List of usage examples for org.apache.commons.io FileUtils touch
public static void touch(File file) throws IOException
From source file:org.duracloud.mill.audit.generator.SpaceLogTest.java
@Test public void testWriteExistingUndersizeLog() throws Exception { setupAuditItem();// w w w .j a va 2s.c o m replayAll(); createTestSubject(); File file = createNewLogFile(); FileUtils.touch(file); this.spaceLog.write(item); this.spaceLog.close(); verifyFileContents(); }
From source file:org.duracloud.mill.audit.generator.SpaceLogTest.java
@Test public void testLogRollingBreaksAfterFileIsClosed() throws Exception { setupAuditItem();/*from w w w. ja v a 2s . com*/ replayAll(); createTestSubject(); File file = createNewLogFile(); FileUtils.touch(file); while (file.length() <= SpaceLog.MAX_FILE_SIZE) { this.spaceLog.write(item); } this.spaceLog.close(); this.spaceLog.write(item); }
From source file:org.duracloud.mill.audit.generator.SpaceLogTest.java
@Test public void testWriteTwoExistingLogs() throws Exception { setupAuditItem();//ww w .ja v a2s. c om replayAll(); createTestSubject(); File leastRecent = createNewLogFile(); FileUtils.touch(leastRecent); Thread.sleep(1000); File mostRecent = createNewLogFile(); FileUtils.touch(mostRecent); this.spaceLog.write(item); this.spaceLog.close(); verifyFileContents(mostRecent); assertTrue(leastRecent.length() == 0); assertTrue(mostRecent.length() > 0); }
From source file:org.duracloud.sync.walker.RestartDirWalkerTest.java
@Test public void testRestartDirWalker() throws Exception { List<File> dirs = new ArrayList<File>(); dirs.add(tempDir);//from w ww . jav a2 s . c om // Create three sub directories with files File subDir1 = new File(tempDir, "subdir1"); subDir1.mkdir(); File sub1file1 = File.createTempFile("subdir1", "file1", subDir1); File sub1file2 = File.createTempFile("subdir1", "file2", subDir1); File subDir2 = new File(tempDir, "subdir2"); subDir2.mkdir(); File sub2file1 = File.createTempFile("subdir2", "file1", subDir2); File subDir3 = new File(tempDir, "subdir3"); subDir3.mkdir(); File sub3file1 = File.createTempFile("subdir3", "file1", subDir3); long restartTime = System.currentTimeMillis(); Thread.sleep(1000); // Add a file to subdir 2 File sub2file2 = File.createTempFile("subdir2", "file2", subDir2); // Update file in subdir 1 FileUtils.touch(sub1file1); // Run the restart walker RestartDirWalker rDirWalker = new RestartDirWalker(dirs, restartTime, new FileExclusionManager()); assertFalse(rDirWalker.walkComplete()); rDirWalker.walkDirs(); assertTrue(rDirWalker.walkComplete()); // Changed list should include sub1file1, and all files from sub2 List<File> changedFiles = new ArrayList<File>(); ChangedFile changedFile = changedList.reserve(); while (changedFile != null) { changedFiles.add(changedFile.getFile()); changedFile = changedList.reserve(); } assertEquals(3, changedFiles.size()); for (File file : changedFiles) { assertTrue(file.equals(sub1file1) || file.equals(sub2file1) || file.equals(sub2file2)); } assertNull(changedList.reserve()); }
From source file:org.eclipse.smarthome.config.dispatch.test.ConfigDispatcherOSGiTest.java
@Test public void propertiesForTheSameLocalPIDInDifferentFilesMustBeOverriddenInTheOrderTheyWereLastModified() throws Exception { String configDirectory = configBaseDirectory + SEP + "local_pid_different_files_conflict_conf"; String servicesDirectory = "local_pid_different_files_conflict_services"; String defaultConfigFilePath = configDirectory + SEP + "local.pid.default.file.cfg"; String lastModifiedFileName = "last.modified.service.file.cfg"; /*//from ww w.ja v a 2 s.c o m * Every file from servicesDirectory contains this property, but with different value. * The value for this property in the last processed file must override the previous * values for the same property in the configuration. */ String conflictProperty = "property"; initialize(defaultConfigFilePath); cd.processConfigFile(new File(getAbsoluteConfigDirectory(configDirectory, servicesDirectory))); // Modify this file, so that we are sure it is the last modified file in servicesDirectory. File fileToModify = new File(configDirectory + SEP + servicesDirectory + SEP + lastModifiedFileName); FileUtils.touch(fileToModify); cd.processConfigFile(fileToModify); String value = getLastModifiedValueForPoperty( getAbsoluteConfigDirectory(configDirectory, servicesDirectory), conflictProperty); /* * Assert that the property for the same local pid in the last modified file * has overridden the other properties for that pid from previously modified files. */ verifyValueOfConfigurationProperty("local.conflict.pid", conflictProperty, value); }
From source file:org.eclipse.smarthome.config.dispatch.test.ConfigDispatcherOSGiTest.java
@Test public void whenPropertyValuePairsForAGlobalPIDAreInDifferentFilesPropertiesWillNotBeMerged() throws IOException { String configDirectory = configBaseDirectory + SEP + "global_pid_different_files_no_merge_conf"; String servicesDirectory = "global_pid_different_files_no_merge_services"; initialize(null);//from www .ja v a 2 s . c o m cd.processConfigFile(new File(getAbsoluteConfigDirectory(configDirectory, servicesDirectory))); // Modify this file, so that we are sure it is the last modified file File lastModified = new File( configDirectory + SEP + servicesDirectory + SEP + "global.pid.service.c.file.cfg"); FileUtils.touch(lastModified); cd.processConfigFile(lastModified); /* * Assert that the configuration is updated only with the property=value * pairs which are parsed last: */ verifyNotExistingConfigurationProperty("different.files.global.pid", "first.property"); verifyNotExistingConfigurationProperty("different.files.global.pid", "second.property"); verifyValueOfConfigurationProperty("different.files.global.pid", "third.property", "third.value"); }
From source file:org.eclipse.smarthome.config.dispatch.test.ConfigDispatcherOSGiTest.java
@Test public void propertiesForTheSameGlobalPIDInDifferentFilesMustBeOverriddenInTheOrderTheyWereLastModified() throws Exception { String configDirectory = configBaseDirectory + SEP + "global_pid_different_files_conflict_conf"; String servicesDirectory = "global_pid_different_files_conflict_services"; String defaultConfigFilePath = configDirectory + SEP + "global.pid.default.file.cfg"; String lastModifiedFileName = "global.pid.last.modified.service.file.cfg"; /*//from w w w . ja va 2s. co m * Every file from servicesDirectory contains this property, but with different value. * The value for this property in the last processed file will override the previous * values for the same property in the configuration. */ String conflictProperty = "property"; initialize(defaultConfigFilePath); cd.processConfigFile(new File(getAbsoluteConfigDirectory(configDirectory, servicesDirectory))); // Modify this file, so that we are sure it is the last modified file in servicesDirectory. File fileToModify = new File(configDirectory + SEP + servicesDirectory + SEP + lastModifiedFileName); FileUtils.touch(fileToModify); cd.processConfigFile(fileToModify); String value = getLastModifiedValueForPoperty( getAbsoluteConfigDirectory(configDirectory, servicesDirectory), conflictProperty); /* * Assert that the property for the same global pid in the last modified file * has overridden the other properties for that pid from previously modified files. */ verifyValueOfConfigurationProperty("different.files.global.pid", conflictProperty, value); }
From source file:org.eclipse.smarthome.config.dispatch.test.ConfigDispatcherOSGiTest.java
@Test public void localPIDIsOverriddenByGlobalPIDInDifferentFileIfTheFileWithTheGlobalOneIsModifiedLast() throws Exception { String configDirectory = configBaseDirectory + SEP + "global_and_local_pid_different_files_conf"; String servicesDirectory = "global_and_local_pid_overridden_local_services"; String defaultConfigFilePath = configDirectory + SEP + "global.and.local.pid.default.file.cfg"; String lastModifiedFileName = "a.overriding.global.pid.service.file.cfg"; /*/*from w w w . j a v a 2s .co m*/ * Both files(with local and global pid) contain this property, but with different value. * The value for this property in the last processed file must override the previous * values for the same property in the configuration. */ String conflictProperty = "global.and.local.property"; initialize(defaultConfigFilePath); cd.processConfigFile(new File(getAbsoluteConfigDirectory(configDirectory, servicesDirectory))); // Modify this file, so that we are sure it is the last modified file in servicesDirectory. File fileToModify = new File(configDirectory + SEP + servicesDirectory + SEP + lastModifiedFileName); FileUtils.touch(fileToModify); cd.processConfigFile(fileToModify); String value = getLastModifiedValueForPoperty( getAbsoluteConfigDirectory(configDirectory, servicesDirectory), conflictProperty); /* * Assert that the global pid from the last modified file * has overridden the local pid from previously processed file. */ verifyValueOfConfigurationProperty("overridden.local.pid", conflictProperty, value); }
From source file:org.eclipse.smarthome.config.dispatch.test.ConfigDispatcherOSGiTest.java
@Test public void globalPIDIsOverriddenByLocalPIDInDifferentFileIfTheFileWithTheLocalOneIsModifiedLast() throws Exception { String configDirectory = configBaseDirectory + SEP + "global_and_local_pid_different_files_conf"; String servicesDirectory = "global_and_local_pid_overridden_global_services"; String defaultConfigFilePath = configDirectory + SEP + "global.and.local.pid.default.file.cfg"; String lastModifiedFileName = "a.overriding.local.pid.service.file.cfg"; /*//from w ww. ja v a2 s .co m * Both files(with local and global pid) contain this property, but with different value. * The value for this property in the last processed file must override the previous * values for the same property in the configuration. */ String conflictProperty = "global.and.local.property"; initialize(defaultConfigFilePath); cd.processConfigFile(new File(getAbsoluteConfigDirectory(configDirectory, servicesDirectory))); // Modify this file, so that we are sure it is the last modified file in servicesDirectory. File fileToModify = new File(configDirectory + SEP + servicesDirectory + SEP + lastModifiedFileName); FileUtils.touch(fileToModify); cd.processConfigFile(fileToModify); String value = getLastModifiedValueForPoperty( getAbsoluteConfigDirectory(configDirectory, servicesDirectory), conflictProperty); /* * Assert that the local pid from the last modified file * has overridden the global pid from previously processed file. */ verifyValueOfConfigurationProperty("overridden.global.pid", conflictProperty, value); }
From source file:org.eclipse.tycho.nexus.internal.plugin.cache.UnzipCacheTest.java
@Test public void testReleaseRedeploy() throws Exception { String redeployableRepoDir = "src/test/resources/redeployRelRepo"; String redeployableArchiveRepoPath = "/dir/redeployable-1.0.0.zip"; String redeployableArchiveFullPath = redeployableRepoDir + redeployableArchiveRepoPath; final File redeployableArchiveFile = new File(redeployableArchiveFullPath); try {/*from ww w . j a v a 2s . co m*/ UnzipCache cache = createUnzipRepo(createRedeployRelRepo()).getCache(); final File version1File = new File(redeployableRepoDir + "/dir/version-1.zip"); final File version2File = new File(redeployableRepoDir + "/dir/version-2.zip"); FileUtils.copyFile(version1File, redeployableArchiveFile); final File redeployableRequest1 = cache.getArchive(redeployableArchiveRepoPath); //expect content of version-1.zip Assert.assertArrayEquals(FileUtils.readFileToByteArray(version1File), FileUtils.readFileToByteArray(redeployableRequest1)); //update content of redeployable-1.0.0 FileUtils.copyFile(version2File, redeployableArchiveFile); FileUtils.touch(redeployableArchiveFile); final File redeployableRequest2 = cache.getArchive(redeployableArchiveRepoPath); //expect content of version-2.zip Assert.assertArrayEquals(FileUtils.readFileToByteArray(version2File), FileUtils.readFileToByteArray(redeployableRequest2)); } finally { FileUtils.deleteQuietly(redeployableArchiveFile); } }