Example usage for org.apache.commons.io FileUtils touch

List of usage examples for org.apache.commons.io FileUtils touch

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils touch.

Prototype

public static void touch(File file) throws IOException 

Source Link

Document

Implements the same behaviour as the "touch" utility on Unix.

Usage

From source file:org.wso2.carbon.automation.extensions.servers.axis2server.Axis2ServerManager.java

/**
 * copy resources/* ww w  .  j a va 2  s . c  o m*/
 * @param resourceName
 * @param fileName
 * @return
 * @throws IOException
 */

private File copyResourceToFileSystem(String resourceName, String fileName) throws IOException {
    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);
    }
    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);
    InputStream is = null;

    try {
        if (resourceName.contains(".aar")) {
            is = new FileInputStream(ExtensionUtils.getSystemResourceLocation() + File.separator + "artifacts"
                    + File.separator + "AXIS2" + File.separator + "aar" + File.separator + resourceName);
        } else {
            is = new FileInputStream(ExtensionUtils.getSystemResourceLocation() + File.separator + "artifacts"
                    + File.separator + "AXIS2" + File.separator + "config" + File.separator + resourceName);
        }
        if (is != null) {
            byte[] data = new byte[1024];
            int len;
            while ((len = is.read(data)) != -1) {
                os.write(data, 0, len);
            }
        }
    } finally {
        os.flush();
        os.close();

        if (is != null)
            is.close();
    }

    return file;
}

From source file:org.wso2.carbon.automation.extensions.servers.axis2server.Axis2ServerManager.java

private File copyServiceToFileSystem(String resourceName, String fileName) throws IOException {

    File file = new File(System.getProperty("basedir") + File.separator + "target" + File.separator + fileName);

    if (file.exists()) {
        FileUtils.deleteQuietly(file);/*from   w  w w.  ja v  a2 s  . c o  m*/
    }

    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);
    InputStream is = null;

    try {

        is = new FileInputStream(ExtensionUtils.getSystemResourceLocation() + File.separator + "artifacts"
                + File.separator + "AXIS2" + File.separator + "config" + File.separator + resourceName);

        if (is != null) {
            byte[] data = new byte[1024];
            int len;
            while ((len = is.read(data)) != -1) {
                os.write(data, 0, len);
            }
            os.flush();

        }
    } finally {
        os.close();
        is.close();
    }

    return file;
}

From source file:org.wso2.carbon.automation.test.utils.common.FileManager.java

public static File copyResourceToFileSystem(String sourcePath, String targetPath, String fileName)
        throws IOException {
    File file = new File(targetPath + File.separator + fileName);
    if (file.exists()) {
        FileUtils.deleteQuietly(file);/*from w  w  w.ja v  a  2s .  c o m*/
    }
    FileUtils.touch(file);
    OutputStream os = FileUtils.openOutputStream(file);
    InputStream is = new FileInputStream(sourcePath);
    if (is != null) {
        byte[] data = new byte[1024];
        int len;
        while ((len = is.read(data)) != -1) {
            os.write(data, 0, len);
        }
        os.flush();
        os.close();
        is.close();
    }
    return file;
}

From source file:org.wso2.carbon.esb.hotdeployment.test.SynapseArtifactsHotDeploymentTestCase.java

@Test(groups = "wso2.esb", description = "Proxy Service Hot Deployment")
public void testProxyServiceHotDeployment() throws Exception {
    String proxyName = "HotDeploymentTestProxy";
    String proxyServiceFile = SERVER_DEPLOYMENT_DIR + "proxy-services" + File.separator + proxyFileName;

    Assert.assertTrue(esbUtils.isProxyDeployed(contextUrls.getBackEndUrl(), sessionCookie, proxyName),
            "Proxy Deployment failed");

    logViewerClient.clearLogs();//  w ww.  java2  s.  com
    FileUtils.touch(new File(proxyServiceFile));
    log.info(proxyFileName + " has been updated and waiting for redeployment");
    Assert.assertTrue(searchInLogs(logViewerClient, "'HotDeploymentTestProxy' has been update from file"),
            "Proxy deployment failed on updating file. Log message not found");
    Assert.assertTrue(esbUtils.isProxyDeployed(contextUrls.getBackEndUrl(), sessionCookie, proxyName),
            "Proxy Deployment failed on updating file");
    Awaitility.await().atMost(10, SECONDS).until(fileDelete(proxyServiceFile));
    Assert.assertTrue(esbUtils.isProxyUnDeployed(contextUrls.getBackEndUrl(), sessionCookie, proxyName),
            "Proxy Undeployment failed");
}

From source file:org.wso2.carbon.esb.hotdeployment.test.SynapseArtifactsHotDeploymentTestCase.java

@Test(groups = "wso2.esb", description = "Sequence Hot Deployment")
public void testSequenceHotDeployment() throws Exception {
    String sequenceName = "HotDeploymentTestSequence";
    String sequenceFile = SERVER_DEPLOYMENT_DIR + "sequences" + File.separator + sequenceFileName;

    Assert.assertTrue(esbUtils.isSequenceDeployed(contextUrls.getBackEndUrl(), sessionCookie, sequenceName),
            "Sequence Deployment failed");

    logViewerClient.clearLogs();/*  ww w.  ja v a 2s . c o  m*/
    FileUtils.touch(new File(sequenceFile));
    log.info(sequenceFile + " has been updated and waiting for redeployment");
    Assert.assertTrue(searchInLogs(logViewerClient, "HotDeploymentTestSequence has been updated from the file"),
            "Sequence deployment failed on updating file. Log message not found");
    Assert.assertTrue(esbUtils.isSequenceDeployed(contextUrls.getBackEndUrl(), sessionCookie, sequenceName),
            "Sequence Deployment failed on updating file");

    Awaitility.await().atMost(10, SECONDS).until(fileDelete(sequenceFile));
    Assert.assertTrue(esbUtils.isSequenceUnDeployed(contextUrls.getBackEndUrl(), sessionCookie, sequenceName),
            "Sequence Undeployment failed");
}

From source file:org.wso2.carbon.esb.hotdeployment.test.SynapseArtifactsHotDeploymentTestCase.java

@Test(groups = "wso2.esb", description = "Endpoint Hot Deployment")
public void testEndpointHotDeployment() throws Exception {
    String endpointName = "HotDeploymentTestEndpoint";
    String endpointFile = SERVER_DEPLOYMENT_DIR + "endpoints" + File.separator + endpointFileName;

    Assert.assertTrue(esbUtils.isEndpointDeployed(contextUrls.getBackEndUrl(), sessionCookie, endpointName),
            "Endpoint Deployment failed");

    logViewerClient.clearLogs();/* ww  w.ja va  2  s.  c o m*/
    FileUtils.touch(new File(endpointFile));
    log.info(endpointFileName + " has been updated and waiting for redeployment");
    Assert.assertTrue(searchInLogs(logViewerClient, "HotDeploymentTestEndpoint has been updated from the file"),
            "Endpoint deployment failed on updating file. Log message not found");
    Assert.assertTrue(esbUtils.isEndpointDeployed(contextUrls.getBackEndUrl(), sessionCookie, endpointName),
            "Endpoint Deployment failed on updating file");

    Awaitility.await().atMost(10, SECONDS).until(fileDelete(endpointFile));
    Assert.assertTrue(esbUtils.isEndpointUnDeployed(contextUrls.getBackEndUrl(), sessionCookie, endpointName),
            "Endpoint Undeployment failed");
}

From source file:org.wso2.carbon.esb.hotdeployment.test.SynapseArtifactsHotDeploymentTestCase.java

@Test(groups = "wso2.esb", description = "API Hot Deployment")
public void testAPIHotDeployment() throws Exception {
    String apiName = "HotDeploymentTestAPI";
    String apiFile = SERVER_DEPLOYMENT_DIR + "api" + File.separator + apiFileName;

    Assert.assertTrue(esbUtils.isApiDeployed(contextUrls.getBackEndUrl(), sessionCookie, apiName),
            "API Deployment failed");

    logViewerClient.clearLogs();/*from www  .  ja  v a  2s. c  om*/
    FileUtils.touch(new File(apiFile));
    log.info(apiFileName + " has been updated and waiting for redeployment");
    Assert.assertTrue(searchInLogs(logViewerClient, "HotDeploymentTestAPI has been updated from the file"),
            "API deployment failed on updating file. Log message not found");
    Assert.assertTrue(esbUtils.isApiDeployed(contextUrls.getBackEndUrl(), sessionCookie, apiName),
            "API Deployment failed on updating file");

    Awaitility.await().atMost(5, SECONDS).until(fileDelete(apiFile));
    Assert.assertTrue(esbUtils.isApiUnDeployed(contextUrls.getBackEndUrl(), sessionCookie, apiName),
            "API Undeployment failed");
}

From source file:org.wso2.carbon.esb.hotdeployment.test.SynapseArtifactsHotDeploymentTestCase.java

@Test(groups = "wso2.esb", description = "Local Entry Hot Deployment")
public void testLocalEntryHotDeployment() throws Exception {
    String localEntryName = "HotDeploymentTestLocalEntry";
    String localEntryFile = SERVER_DEPLOYMENT_DIR + "local-entries" + File.separator + localEntryFileName;

    Assert.assertTrue(esbUtils.isLocalEntryDeployed(contextUrls.getBackEndUrl(), sessionCookie, localEntryName),
            "Local Entry Deployment failed");

    logViewerClient.clearLogs();//from  w w w .j  a  va2s  . c  o m
    FileUtils.touch(new File(localEntryFile));
    log.info(localEntryFileName + " has been updated and waiting for redeployment");
    Assert.assertTrue(
            searchInLogs(logViewerClient, "HotDeploymentTestLocalEntry has been updated from the file"),
            "Local Entry deployment failed on updating file. Log message not found");
    Assert.assertTrue(esbUtils.isLocalEntryDeployed(contextUrls.getBackEndUrl(), sessionCookie, localEntryName),
            "Local Entry Deployment failed on updating file");
    Awaitility.await().atMost(10, SECONDS).until(fileDelete(localEntryFile));
    Assert.assertTrue(
            esbUtils.isLocalEntryUnDeployed(contextUrls.getBackEndUrl(), sessionCookie, localEntryName),
            "Local Entry Undeployment failed");
}

From source file:org.wso2.carbon.esb.hotdeployment.test.SynapseArtifactsHotDeploymentTestCase.java

@Test(groups = "wso2.esb", description = "Message Store Hot Deployment")
public void testMessageStoreHotDeployment() throws Exception {
    String messageStoreName = "HotDeploymentTestMessageStore";
    String messageStoreFile = SERVER_DEPLOYMENT_DIR + "message-stores" + File.separator + messageStoreFileName;

    Assert.assertTrue(/*from ww  w  .j av a  2  s.  co m*/
            esbUtils.isMessageStoreDeployed(contextUrls.getBackEndUrl(), sessionCookie, messageStoreName),
            "Message Store Deployment failed");

    logViewerClient.clearLogs();
    FileUtils.touch(new File(messageStoreFile));
    log.info(messageStoreFileName + " has been updated and waiting for redeployment");
    Assert.assertTrue(
            searchInLogs(logViewerClient, "HotDeploymentTestMessageStore has been updated from the file"),
            "Message Store deployment failed on updating file. Log message not found");
    Assert.assertTrue(
            esbUtils.isMessageStoreDeployed(contextUrls.getBackEndUrl(), sessionCookie, messageStoreName),
            "Message Store Deployment failed on updating file");
    Awaitility.await().atMost(10, SECONDS).until(fileDelete(messageStoreFile));
    Assert.assertTrue(
            esbUtils.isSequenceUnDeployed(contextUrls.getBackEndUrl(), sessionCookie, messageStoreName),
            "Message Store Undeployment failed");
}

From source file:org.wso2.carbon.esb.proxyservice.test.proxyservices.HttpsServiceViaHttpProxyTestCase.java

/**
 * Method to change the axis2 config file dynamically
 *
 * @param file : Config file/* w w w  .  ja v a 2s.com*/
 * @throws java.io.IOException
 */
private void changeConfiguration(String file) throws IOException {
    StringBuilder sb = new StringBuilder();
    File config = new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts"
            + File.separator + "AXIS2" + File.separator + "config" + File.separator + file);
    if (config != null) {
        String currentLine;
        BufferedReader br = new BufferedReader(new FileReader(config));
        while ((currentLine = br.readLine()) != null) {
            if (currentLine.contains("REPLACE_CK")) {
                currentLine = currentLine.replace("REPLACE_CK",
                        System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "repository"
                                + File.separator + "resources" + File.separator + "security" + File.separator
                                + "wso2carbon.jks");
            } else if (currentLine.contains("REPLACE_TS")) {
                currentLine = currentLine.replace("REPLACE_TS",
                        System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "repository"
                                + File.separator + "resources" + File.separator + "security" + File.separator
                                + "client-truststore.jks");
            }
            sb.append(currentLine);
        }
        br.close();
    }
    File newConfig = new File(FrameworkPathUtil.getSystemResourceLocation() + File.separator + "artifacts"
            + File.separator + "AXIS2" + File.separator + "config" + File.separator + MODIFIED_RESOURCE_NAME);
    if (newConfig.exists()) {
        FileUtils.deleteQuietly(newConfig);
    }

    FileUtils.touch(newConfig);
    OutputStream os = FileUtils.openOutputStream(newConfig);
    os.write(sb.toString().getBytes("UTF-8"));
    os.close();
}