List of usage examples for org.apache.commons.io FileUtils contentEquals
public static boolean contentEquals(File file1, File file2) throws IOException
From source file:org.talend.components.azurestorage.blob.runtime.AzureStorageGetReaderTestIT.java
public Boolean fileExistsAndHasTheGoodSize(String file) throws Exception { File dl = new File(FOLDER_PATH_GET + "/" + file); File or = new File(FOLDER_PATH_PUT + "/" + file); return (dl.exists() && FileUtils.contentEquals(dl, or)); }
From source file:org.tmpotter.preferences.PreferencesTest.java
/** * Test that if an error is encountered when loading the preferences file, the * original file is backed up./* ww w .j a va 2s.c o m*/ * <p> * Note that this test can spuriously fail if run in a situation where the * Preferences class has already been initialized, for instance when running * the entire suite of tests in Eclipse. It behaves correctly when run * individually, or with ant. */ public void testPreferencesBackup() throws Exception { File tmpDir = FileUtil.createTempDir(); try { assertTrue(tmpDir.isDirectory()); Utilities.setConfigDir(tmpDir.getAbsolutePath()); File prefs = new File(tmpDir, Preferences.FILE_PREFERENCES); // Write anything that is malformed XML, to force a parsing error. PrintWriter out = new PrintWriter(prefs, "UTF-8"); out.println("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>"); out.println("<tmpotter>"); out.println("<preference version=\"1.0\">"); out.close(); assertFalse(out.checkError()); // Load bad prefs file. Preferences pref = Preferences.getPreferences(); pref.doLoad(); // The actual backup file will have a timestamp in the filename, // so we have to loop through looking for it. File backup = null; for (File f : tmpDir.listFiles()) { String name = f.getName(); if (name.startsWith("tmpotter.prefs") && name.endsWith(".bak")) { backup = f; break; } } assertNotNull(backup); assertTrue(backup.isFile()); assertTrue(FileUtils.contentEquals(prefs, backup)); } finally { assertTrue(FileUtil.deleteTree(tmpDir)); } }
From source file:org.tmpotter.util.UtilitiesTest.java
/** * Test of saveUTF8 method, of class Utilities. *///from w ww . j ava2s .c om @Test public void testSaveUTF8() { System.out.println("saveUTF8"); String dir = this.getClass().getResource("/").getFile(); String filename = "save_utf8_result.txt"; String output = "\u3401\u3402"; try { Utilities.saveUtf8(dir, filename, output); File target = new File(this.getClass().getResource("/save_utf8_result.txt").getFile()); File expected = new File(this.getClass().getResource("/save_utf8_expected.txt").getFile()); assertTrue(FileUtils.contentEquals(target, expected)); target.delete(); } catch (Exception ex) { System.out.println(ex); fail(); } }
From source file:org.wise.vle.utils.FileManager.java
/** * Import the asset from one project asset folder to another project asset folder * @param fromAssetFileName the name of the file in the asset folder * @param fromAssetFileContent (optional) the content that we want to save to the to asset. * if this is not provided we will obtain the content from the fromAssetFileName handle. * this parameter is used when the content in the fromAssetFileName needs to be modified * such as when file name references in the content need to be changed due to file name * conflicts./* w w w . j ava2s . c om*/ * @param fromProjectAssetsFolder the asset folder in the from project * @param toProjectAssetsFolder the asset folder in the to project * @return the name of the asset file that was created in the to project asset folder * or null if we were unable to create the asset in the to project asset folder */ public static String importAssetInContent(String fromAssetFileName, String fromAssetFileContent, File fromProjectAssetsFolder, File toProjectAssetsFolder) { String toAssetFileName = null; String toAssetFileContent = null; //create the file handle for the "from" file File fromAsset = new File(fromProjectAssetsFolder, fromAssetFileName); //make sure the file exists in the "from" project if (fromAsset.exists()) { toAssetFileName = fromAssetFileName; //create the file handle for the "to" file File toAsset = new File(toProjectAssetsFolder, toAssetFileName); boolean assetCompleted = false; int counter = 1; /* * this while loop will check if the file already exists. * * if the file already exists, we will check if the content in the "from" file is the same as in the "to" file. * if the content is the same, we do not need to do anything. * if the content is different, we will look for another file name to use. * if the file does not exist, we will make it. */ while (!assetCompleted) { if (toAsset.exists()) { //file already exists try { //get the to asset file content toAssetFileContent = FileUtils.readFileToString(toAsset); } catch (IOException e1) { e1.printStackTrace(); } try { boolean contentMatches = false; if (fromAssetFileContent != null) { /* * the from asset file content was passed in so we will compare it with * the to asset file content */ if (fromAssetFileContent.equals(toAssetFileContent)) { //the file content matches contentMatches = true; } } else if (FileUtils.contentEquals(fromAsset, toAsset)) { /* * the from asset file content was not passed in so we will compare * the contents from their file handles */ //the file content matches contentMatches = true; } if (contentMatches) { //files are the same so we do not need to do anything assetCompleted = true; } else { //files are not the same so we need to try a different file name //get new file name e.g. myPicture-1.jpg toAssetFileName = createNewFileName(fromAssetFileName, counter); //create the handle for the next file we will try to use toAsset = new File(toProjectAssetsFolder, toAssetFileName); counter++; } } catch (IOException e) { e.printStackTrace(); break; } } else { //file does not exist so we will copy the file to the "to" assets folder try { if (fromAssetFileContent != null) { //the content was passed in so we will use it FileUtils.write(toAsset, fromAssetFileContent); } else { /* * the content was not passed in so we will use the content * obtained from the file handle */ //copy the file into our new asset file FileUtils.copyFile(fromAsset, toAsset); } assetCompleted = true; } catch (IOException e) { e.printStackTrace(); break; } } } } return toAssetFileName; }
From source file:org.wso2.carbon.esb.rest.test.api.ESBJAVA4519TestCase.java
@Test(groups = { "wso2.esb" }, description = "Test whether file get restored after deployment failure") public void testRestoringToPreviousConfigurationOnHotDeploymentFailure() throws Exception { boolean messageInLog = false; String esbApiPath = System.getProperty(ServerConstants.CARBON_HOME) + File.separator + "repository" + File.separator + "deployment" + File.separator + "server" + File.separator + "synapse-configs" + File.separator + "default" + File.separator + "api" + File.separator + "CorruptedApi.xml"; File esbApiFile = new File(esbApiPath); String corruptedApiPath = TestConfigurationProvider.getResourceLocation("ESB") + File.separator + "synapseconfig" + File.separator + "rest" + File.separator + "CorruptedApi.xml"; File corruptedApiFile = new File(corruptedApiPath); String validApiPath = TestConfigurationProvider.getResourceLocation("ESB") + File.separator + "synapseconfig" + File.separator + "rest" + File.separator + "CorrectApi.xml"; File validApiFile = new File(validApiPath); long startTime = System.currentTimeMillis(); while ((startTime + 60000) > System.currentTimeMillis()) { log.info("Waiting for esb to persist the api config file..."); if (esbApiFile.exists() && FileUtils.contentEquals(validApiFile, esbApiFile)) { log.info("Api Config is written to file system by esb. Waiting for hot deployment to pick up the " + "resorted file as it will be taken as a restored file from esb."); Thread.sleep(30000);/*from w w w. j a v a2s. c o m*/ break; } else { Thread.sleep(20000); } } LogEvent[] logs; log.info("Copying the corrupted api config file..."); Files.copy(corruptedApiFile.toPath(), esbApiFile.toPath(), StandardCopyOption.REPLACE_EXISTING); log.info("Copied the corrupted api config file to config folder."); for (int i = 0; i < 5; i++) { log.info("Checking for error logs in the esb.."); logs = logViewerClient.getAllRemoteSystemLogs(); for (LogEvent logEvent : logs) { String message = logEvent.getMessage(); if (message.contains("Deployment of synapse artifact failed")) { log.info("Hot Deployment error log is printed in the ESB logs."); messageInLog = true; break; } } if (!messageInLog) { Thread.sleep(20000); } else { break; } } Assert.assertTrue(messageInLog, "Exception has occurred"); messageInLog = false; logs = logViewerClient.getAllRemoteSystemLogs(); for (LogEvent logEvent : logs) { String message = logEvent.getMessage(); if (message.contains("Restoring the existing artifact into the file")) { messageInLog = true; break; } } Assert.assertTrue(messageInLog, "Original xml is not restored."); }
From source file:org.wso2.ppaas.tools.artifactmigration.test.HttpClientTest.java
@Test(timeout = 60000) public void transformNetworkPartitionListTest() throws Exception { File partitionfile1 = new File(TestConstants.OUTPUT_DIRECTORY + TestConstants.OUTPUT_PARTITION); File partitionfile2 = new File(TestConstants.TEST_OUTPUTS + TestConstants.OUTPUT_PARTITION); assertTrue(FileUtils.contentEquals(partitionfile1, partitionfile2)); }
From source file:org.wso2.ppaas.tools.artifactmigration.test.HttpClientTest.java
@Test(timeout = 60000) public void transformAutoscalePolicyListTest() throws Exception { File autoscalefile1 = new File(TestConstants.OUTPUT_DIRECTORY + TestConstants.OUTPUT_AUTOSCALE); File autoscalefile2 = new File(TestConstants.TEST_OUTPUTS + TestConstants.OUTPUT_AUTOSCALE); assertTrue(FileUtils.contentEquals(autoscalefile1, autoscalefile2)); }
From source file:org.wso2.ppaas.tools.artifactmigration.test.HttpClientTest.java
@Test(timeout = 60000) public void transformDeploymentPolicyList() throws Exception { File deploymentfile1 = new File(TestConstants.OUTPUT_DIRECTORY + TestConstants.OUTPUT_DEPLOYMENT); File deploymentfile2 = new File(TestConstants.TEST_OUTPUTS + TestConstants.OUTPUT_DEPLOYMENT); assertTrue(FileUtils.contentEquals(deploymentfile1, deploymentfile2)); }
From source file:org.wso2.ppaas.tools.artifactmigration.test.HttpClientTest.java
@Test(timeout = 60000) public void transformCartridgeList() throws Exception { File cartridgefile1 = new File(TestConstants.OUTPUT_DIRECTORY + TestConstants.OUTPUT_CARTRIDGE); File cartridgefile2 = new File(TestConstants.TEST_OUTPUTS + TestConstants.OUTPUT_CARTRIDGE); assertTrue(FileUtils.contentEquals(cartridgefile1, cartridgefile2)); }
From source file:org.wso2.ppaas.tools.artifactmigration.test.HttpClientTest.java
@Test(timeout = 60000) public void createdApplicationList() throws Exception { File applicationfile1 = new File(TestConstants.OUTPUT_DIRECTORY + TestConstants.OUTPUT_APPLICATION); File applicationfile2 = new File(TestConstants.TEST_OUTPUTS + TestConstants.OUTPUT_APPLICATION); assertTrue(FileUtils.contentEquals(applicationfile1, applicationfile2)); }