org.wso2.carbon.integration.common.utils.FileManager Java Examples

The following examples show how to use org.wso2.carbon.integration.common.utils.FileManager. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerConfigurationManager.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * @param fileName file name
 * @throws IOException
 * @throws URISyntaxException
 */
public void removeFromComponentLib(String fileName) throws IOException, URISyntaxException {
    String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
    String filePath = Paths.get(carbonHome, "lib", fileName).toString();
    FileManager.deleteFile(filePath);
    //      removing osgi bundle from dropins; OSGI bundle versioning starts with _1.0.0
    fileName = fileName.replace("-", "_");
    fileName = fileName.replace(".jar", "_1.0.0.jar");
    removeFromComponentDropins(fileName);
}
 
Example #2
Source File: RestResourceLCWithTwoActionsPointingToSameStateWithExecutor.java    From product-es with Apache License 2.0 5 votes vote down vote up
@AfterClass(alwaysRun = true)
public void cleanUp() throws Exception {
    deleteAsset(assetId, publisherUrl, cookieHeader, "restservice", genericRestClient);
    lifeCycleAdminServiceClient.editLifeCycle(lifeCycleName,
                                              readFile(resourcePath + "lifecycle" +
                                                       File.separator + "ServiceLifeCycle.xml"));
    FileManager.deleteFile(libPath + File.separator + executorJAR);
    FileManager.deleteFile(dropinsPath + File.separator + "test_artifacts_1.0_SNAPSHOT_1.0.0.jar");
    serverConfigurationManager.restartGracefully();
}
 
Example #3
Source File: TestServerManager.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private void copyFileToServer(String sourcePath, String destinationPath) {
    log.info("Updating " + destinationPath + " for product EI");
    String catalinaResourcePath = Paths.get(FrameworkPathUtil.getSystemResourceLocation(), sourcePath).toString();
    try {
        FileManager.copyFile(Paths.get(catalinaResourcePath).toFile(), Paths.get(carbonHome, destinationPath).toString());
    } catch (IOException e) {
        log.warn("IOException while replacing " + destinationPath);
    }
}
 
Example #4
Source File: CCOMMONS8SetTenantDomainTest.java    From product-ei with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public void init() throws Exception {
    super.init();
    regTestContext = new AutomationContext("ESB", "esbsRegTest", TestUserMode.SUPER_TENANT_ADMIN);

    startupParameterMap = new HashMap<String, String>();
    startupParameterMap.put("-DportOffset", "230");

    String backEndRegUrl = "https://" + context.getInstance().getHosts().get("default") + ":" + context.getInstance().getPorts().get("https") + "/registry";

    changeRegistryFile(getClass().getResource(COMMON_FILE_LOCATION + "registry-template.xml").getPath(), backEndRegUrl);

    testServerManager = new TestServerManager(regTestContext, null, startupParameterMap) {

        public void configureServer() throws AutomationFrameworkException {

            try {
                File sourceFile = new File(getClass().getResource(COMMON_FILE_LOCATION + "registry.xml").getPath());

                //copying registry.xml file to conf folder
                FileManager.copyFile(sourceFile, this.getCarbonHome() + File.separator + "repository" + File.separator + "conf" + File.separator + "registry.xml");
            } catch (IOException e) {
                throw new AutomationFrameworkException(e.getMessage(), e);
            }
        }
    };

}
 
Example #5
Source File: SynapseArtifactsHotDeploymentTestCase.java    From product-ei with Apache License 2.0 5 votes vote down vote up
private Callable<Boolean> fileDelete(final String filePath) {
    return new Callable<Boolean>() {
        public Boolean call() throws Exception {
            return FileManager.deleteFile(filePath);
        }
    };
}
 
Example #6
Source File: ServerConfigurationManager.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * @param fileName file name
 * @throws IOException
 * @throws URISyntaxException
 */
public void removeFromComponentDropins(String fileName) throws IOException, URISyntaxException {
    String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
    URI filePath = Paths.get(carbonHome, "dropins", fileName).toUri();
    File file = Paths.get(filePath).toFile();

    if (file.exists()) {
        FileManager.deleteFile(file.getAbsolutePath());
    }
}
 
Example #7
Source File: ServerConfigurationManager.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
     * @param fileName file name
     * @throws IOException
     * @throws URISyntaxException
     */
    public void removeFromComponentLib(String fileName) throws IOException, URISyntaxException {
        String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
        String filePath = Paths.get(carbonHome ,"lib" , fileName).toString();
        FileManager.deleteFile(filePath);
//      removing osgi bundle from dropins; OSGI bundle versioning starts with _1.0.0
        fileName = fileName.replace("-", "_");
        fileName = fileName.replace(".jar", "_1.0.0.jar");
        removeFromComponentDropins(fileName);
    }
 
Example #8
Source File: SynapseArtifactsHotDeploymentTestCase.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
private Callable<Boolean> fileDelete(final String filePath) {
    return new Callable<Boolean>() {
        public Boolean call() throws Exception {
            return FileManager.deleteFile(filePath);
        }
    };
}
 
Example #9
Source File: ServerConfigurationManager.java    From micro-integrator with Apache License 2.0 5 votes vote down vote up
/**
 * @param fileName file name
 * @throws IOException
 * @throws URISyntaxException
 */
public void removeFromComponentDropins(String fileName) throws IOException, URISyntaxException {
    String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
    URI filePath = Paths.get(carbonHome, "dropins", fileName).toUri();
    File file = Paths.get(filePath).toFile();

    if (file.exists()) {
        FileManager.deleteFile(file.getAbsolutePath());
    }
}
 
Example #10
Source File: DS1189LeagyTimeStampModeTestCase.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void serviceDeployment() throws Exception {

    super.init();

    startupParameterMap = new HashMap<String, String>();
    startupParameterMap.put("-DportOffset", "1210");

    testServerManager = new DSSTestServerManager(dssContext, null, startupParameterMap) {

        public void configureServer() throws AutomationFrameworkException {

            try {
                File sourceFile = new File(
                        getResourceLocation() + File.separator + "serverConfigs" + File.separator + getParameter(
                                "shFilename"));

                //copying wso2server.sh file to bin folder
                FileManager.copyFile(sourceFile,
                        this.getCarbonHome() + File.separator + "bin" + File.separator + "wso2server.sh");

            } catch (IOException e) {
                throw new AutomationFrameworkException(e.getMessage(), e);
            } catch (XPathExpressionException e) {
                throw new AutomationFrameworkException(e.getMessage(), e);
            }

        }
    };

    testServerManager.setParameter("shFilename", "wso2serverLegacyMode.sh");

    String testServerCarbonHome = testServerManager.startServer();

    backupUserDir = System.getProperty("user.dir");
    backupCarbonHome = System.getProperty("carbon.home");

    System.out.println("****************  back up user dir   " + backupUserDir);
    System.out.println("****************  back up carbonhome " + backupCarbonHome);

    System.setProperty("carbon.home", testServerCarbonHome);

    loginClient = new AuthenticatorClient(backendUrl);
    sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

    List<File> sqlFileLis = new ArrayList<File>();
    sqlFileLis.add(selectSqlFile("CreateTableTimeStamp.sql"));
    deployService(serviceName, createArtifact(
            getResourceLocation() + File.separator + "dbs" + File.separator + "rdbms" + File.separator + "h2"
                    + File.separator + serviceName + ".dbs", sqlFileLis));

    insertTimeStampToDb("Insert With America/New_York Time Zone", "1970-01-02T12:00:00.000+02:00");

    testServerManager.stopServer();
    testServerManager.removeParameter("shFilename");
    testServerManager.setParameter("shFilename", "wso2serverLegacyMode1.sh");
    testServerManager.configureServer();
    testServerManager.startServer();

    sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

    insertTimeStampToDb("Insert With UTC Time Zone", "1970-01-02T12:00:00.000+02:00");

}
 
Example #11
Source File: DS1069DifferentTimeStampStoreIssueTestCase.java    From micro-integrator with Apache License 2.0 4 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void serviceDeployment() throws Exception {

    super.init();

    startupParameterMap = new HashMap<String, String>();
    startupParameterMap.put("-DportOffset", "1210");

    testServerManager = new DSSTestServerManager(dssContext, null, startupParameterMap) {

        public void configureServer() throws AutomationFrameworkException {

            try {
                File sourceFile = new File(
                        getResourceLocation() + File.separator + "serverConfigs" + File.separator + getParameter(
                                "shFilename"));
                //                    File destinationFile = new File(testServerManager.getCarbonHome() + File.separator + "bin" + File.separator + "wso2server.sh");

                //copying wso2server.sh file to bin folder
                FileManager.copyFile(sourceFile,
                        this.getCarbonHome() + File.separator + "bin" + File.separator + "wso2server.sh");

            } catch (IOException e) {
                throw new AutomationFrameworkException(e.getMessage(), e);
            } catch (XPathExpressionException e) {
                throw new AutomationFrameworkException(e.getMessage(), e);
            }

        }
    };

    testServerManager.setParameter("shFilename", "wso2server.sh");

    String testServerCarbonHome = testServerManager.startServer();

    backupUserDir = System.getProperty("user.dir");
    backupCarbonHome = System.getProperty("carbon.home");

    System.out.println("****************  back up user dir   " + backupUserDir);
    System.out.println("****************  back up carbonhome " + backupCarbonHome);

    System.setProperty("carbon.home", testServerCarbonHome);
    //        System.setProperty("user.dir", testServerCarbonHome);

    loginClient = new AuthenticatorClient(backendUrl);
    sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

    List<File> sqlFileLis = new ArrayList<File>();
    sqlFileLis.add(selectSqlFile("CreateTableWithTimeStamp.sql"));
    deployService(serviceName, createArtifact(
            getResourceLocation() + File.separator + "dbs" + File.separator + "rdbms" + File.separator + "h2"
                    + File.separator + serviceName + ".dbs", sqlFileLis));

    //        backendUrl = dssContext.getContextUrls().getBackEndUrl();

    insertTimeStampToDb("Insert With America/New_York Time Zone", "1970-01-02T12:00:00.000+02:00");

    testServerManager.stopServer();

    testServerManager.removeParameter("shFilename");
    testServerManager.setParameter("shFilename", "wso2server1.sh");
    testServerManager.configureServer();
    testServerManager.startServer();
    sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

    insertTimeStampToDb("Insert With America/New_York Time Zone", "1970-01-02T12:00:00.000+02:00");

}
 
Example #12
Source File: ValidPathAxis2RepoTestCase.java    From micro-integrator with Apache License 2.0 3 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

    super.init();

    String urlAxis2Xml = getESBResourceLocation() + "/mediatorconfig/callout/client_repo/conf";
    String uriSynapse = getESBResourceLocation() + "/mediatorconfig/callout/ValidPath_Axis2Repo.xml";

    OMElement lineItem = AXIOMUtil.stringToOM(FileManager.readFile(uriSynapse));

    Iterator sequenceElements = lineItem.getChildElements();      // get all sequence elements

    while (sequenceElements.hasNext()) {

        OMElement sequenceElement = (OMElement) sequenceElements.next();

        Iterator callOutElements = sequenceElement
                .getChildrenWithLocalName("callout");        // get all callout elements

        while (callOutElements.hasNext()) {

            OMElement callOutElement = (OMElement) callOutElements.next();

            Iterator configElments = callOutElement
                    .getChildrenWithLocalName("configuration");        // get configuration elements

            while (configElments.hasNext()) {

                OMElement configElment = (OMElement) configElments
                        .next();           //this is the configuration element

                configElment.getAttribute(new QName("repository")).setAttributeValue(
                        urlAxis2Xml);    // gets the attribute of repository and changes it to a different path
            }
        }
    }

    updateESBConfiguration(lineItem);
}
 
Example #13
Source File: ValidPathAxis2RepoTestCase.java    From product-ei with Apache License 2.0 3 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {

    super.init();

    String urlAxis2Xml = getESBResourceLocation() +"/mediatorconfig/callout/client_repo/conf";
    String uriSynapse = getESBResourceLocation()+ "/mediatorconfig/callout/ValidPath_Axis2Repo.xml";

    OMElement lineItem = AXIOMUtil.stringToOM(FileManager.readFile(uriSynapse));

    Iterator sequenceElements = lineItem.getChildElements();      // get all sequence elements


    while (sequenceElements.hasNext()) {

        OMElement sequenceElement = (OMElement) sequenceElements.next();

        Iterator callOutElements = sequenceElement.getChildrenWithLocalName("callout");        // get all callout elements


        while (callOutElements.hasNext()) {

            OMElement callOutElement = (OMElement) callOutElements.next();

            Iterator configElments = callOutElement.getChildrenWithLocalName("configuration");        // get configuration elements


            while (configElments.hasNext()) {

                OMElement configElment = (OMElement) configElments.next();           //this is the configuration element

                configElment.getAttribute(new QName("repository")).setAttributeValue(urlAxis2Xml);    // gets the attribute of repository and changes it to a different path
            }
        }
    }

    updateESBConfiguration(lineItem);
}
 
Example #14
Source File: DS1069DifferentTimeStampStoreIssueTestCase.java    From product-ei with Apache License 2.0 2 votes vote down vote up
@BeforeClass(alwaysRun = true)
    public void serviceDeployment() throws Exception {

        super.init();

        startupParameterMap = new HashMap<String, String>();
        startupParameterMap.put("-DportOffset", "1210");

        testServerManager = new DSSTestServerManager(dssContext, null, startupParameterMap) {

            public void configureServer() throws AutomationFrameworkException {

                try {
                    File sourceFile = new File(getResourceLocation() + File.separator + "serverConfigs" + File.separator
                            + getParameter("shFilename"));
//                    File destinationFile = new File(testServerManager.getCarbonHome() + File.separator + "bin" + File.separator + "wso2server.sh");

                    //copying wso2server.sh file to bin folder
                    FileManager.copyFile(sourceFile, this.getCarbonHome() + File.separator + "bin" + File.separator + "wso2server.sh");


                } catch (IOException e) {
                    throw new AutomationFrameworkException(e.getMessage(), e);
                } catch (XPathExpressionException e) {
                    throw new AutomationFrameworkException(e.getMessage(), e);
                }

            }
        };

        testServerManager.setParameter("shFilename", "wso2server.sh");

        String testServerCarbonHome = testServerManager.startServer();

        backupUserDir = System.getProperty("user.dir");
        backupCarbonHome = System.getProperty("carbon.home");

        System.out.println("****************  back up user dir   " + backupUserDir);
        System.out.println("****************  back up carbonhome " + backupCarbonHome);


        System.setProperty("carbon.home", testServerCarbonHome);
//        System.setProperty("user.dir", testServerCarbonHome);

        loginClient = new AuthenticatorClient(backendUrl);
        sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

        List<File> sqlFileLis = new ArrayList<File>();
        sqlFileLis.add(selectSqlFile("CreateTableWithTimeStamp.sql"));
        deployService(serviceName,
                createArtifact(getResourceLocation() + File.separator + "dbs" + File.separator
                        + "rdbms" + File.separator + "h2" + File.separator
                        + serviceName + ".dbs", sqlFileLis));

//        backendUrl = dssContext.getContextUrls().getBackEndUrl();

        insertTimeStampToDb("Insert With America/New_York Time Zone", "1970-01-02T12:00:00.000+02:00");

        testServerManager.stopServer();

        testServerManager.removeParameter("shFilename");
        testServerManager.setParameter("shFilename", "wso2server1.sh");
        testServerManager.configureServer();
        testServerManager.startServer();
        sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

        insertTimeStampToDb("Insert With America/New_York Time Zone", "1970-01-02T12:00:00.000+02:00");

    }
 
Example #15
Source File: DS1189LeagyTimeStampModeTestCase.java    From product-ei with Apache License 2.0 2 votes vote down vote up
@BeforeClass(alwaysRun = true)
public void serviceDeployment() throws Exception {

    super.init();

    startupParameterMap = new HashMap<String, String>();
    startupParameterMap.put("-DportOffset", "1210");

    testServerManager = new DSSTestServerManager(dssContext, null, startupParameterMap) {

        public void configureServer() throws AutomationFrameworkException {

            try {
                File sourceFile = new File(getResourceLocation() + File.separator + "serverConfigs" + File.separator
                        + getParameter("shFilename"));

                //copying wso2server.sh file to bin folder
                FileManager.copyFile(sourceFile, this.getCarbonHome() + File.separator + "bin" + File.separator + "wso2server.sh");


            } catch (IOException e) {
                throw new AutomationFrameworkException(e.getMessage(), e);
            } catch (XPathExpressionException e) {
                throw new AutomationFrameworkException(e.getMessage(), e);
            }

        }
    };

    testServerManager.setParameter("shFilename", "wso2serverLegacyMode.sh");

    String testServerCarbonHome = testServerManager.startServer();

    backupUserDir = System.getProperty("user.dir");
    backupCarbonHome = System.getProperty("carbon.home");

    System.out.println("****************  back up user dir   " + backupUserDir);
    System.out.println("****************  back up carbonhome " + backupCarbonHome);


    System.setProperty("carbon.home", testServerCarbonHome);

    loginClient = new AuthenticatorClient(backendUrl);
    sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

    List<File> sqlFileLis = new ArrayList<File>();
    sqlFileLis.add(selectSqlFile("CreateTableTimeStamp.sql"));
    deployService(serviceName,
            createArtifact(getResourceLocation() + File.separator + "dbs" + File.separator
                    + "rdbms" + File.separator + "h2" + File.separator
                    + serviceName + ".dbs", sqlFileLis));

    insertTimeStampToDb("Insert With America/New_York Time Zone", "1970-01-02T12:00:00.000+02:00");

    testServerManager.stopServer();
    testServerManager.removeParameter("shFilename");
    testServerManager.setParameter("shFilename", "wso2serverLegacyMode1.sh");
    testServerManager.configureServer();
    testServerManager.startServer();

    sessionCookie = loginClient.login(userInfo.getUserName(), userInfo.getPassword(), "localhost");

    insertTimeStampToDb("Insert With UTC Time Zone", "1970-01-02T12:00:00.000+02:00");

}
 
Example #16
Source File: ServerConfigurationManager.java    From product-ei with Apache License 2.0 2 votes vote down vote up
/**
 * Copy Jar file to server component/lib
 *
 * @param jar jar file
 * @throws IOException
 * @throws URISyntaxException
 */
public void copyToComponentLib(File jar) throws IOException, URISyntaxException {
    String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
    String lib = Paths.get(carbonHome, "lib").toString();
    FileManager.copyJarFile(jar, lib);
}
 
Example #17
Source File: ServerConfigurationManager.java    From product-ei with Apache License 2.0 2 votes vote down vote up
/**
 * /**
 * Copy Jar file to server component/dropins
 *
 * @param jar jar file
 * @throws IOException
 * @throws URISyntaxException
 */
public void copyToComponentDropins(File jar) throws IOException, URISyntaxException {
    String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
    String lib = Paths.get(carbonHome, "dropins").toString();
    FileManager.copyJarFile(jar, lib);
}
 
Example #18
Source File: ServerConfigurationManager.java    From micro-integrator with Apache License 2.0 2 votes vote down vote up
/**
 * Copy Jar file to server component/lib
 *
 * @param jar jar file
 * @throws IOException
 * @throws URISyntaxException
 */
public void copyToComponentLib(File jar) throws IOException, URISyntaxException {
    String carbonHome = System.getProperty(ServerConstants.CARBON_HOME);
    String lib = Paths.get(carbonHome, "lib").toString();
    FileManager.copyJarFile(jar, lib);
}