CopyDirectory extends AbstractToOperation<CopyDirectory> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File filesFrom = getAbsoluteFile(transformedAppFolder, transformationContext); File fileTo = getFileTo(transformedAppFolder, transformationContext); TOExecutionResult result = null; try { FileUtils.copyDirectory(filesFrom, fileTo); String details = String.format("Files from '%s' have been copied to '%s'", getRelativePath(transformedAppFolder, filesFrom), getRelativePath(transformedAppFolder, fileTo)); result = TOExecutionResult.success(this, details); } catch (IOException e) { result = TOExecutionResult.error(this, new TransformationOperationException("Directory could not be copied", e)); } return result; } CopyDirectory();   }
@Test public void nonExistentFromFolderTest() { CopyDirectory copyDirectory = new CopyDirectory().relative("nonExistentFolder").setToRelative("src/main/resources"); TOExecutionResult executionResult = copyDirectory.execution(transformedAppFolder, transformationContext); assertEquals(copyDirectory.getToRelative(), "src/main/resources"); assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR); assertEquals(executionResult.getException().getClass(), TransformationOperationException.class); assertEquals(executionResult.getException().getMessage(), "Directory could not be copied"); assertEquals(executionResult.getException().getCause().getMessage(), "Source '" + new File(transformedAppFolder, "nonExistentFolder").getAbsolutePath() + "' does not exist"); assertEquals(copyDirectory.getDescription(), "Copy directory content from nonExistentFolder to src/main/resources"); assertNull(executionResult.getDetails()); }
@Test public void nonDirectoryTest() { CopyDirectory copyDirectory = new CopyDirectory().relative("pom.xml").setToRelative("src/main/resources"); TOExecutionResult executionResult = copyDirectory.execution(transformedAppFolder, transformationContext); assertEquals(copyDirectory.getToRelative(), "src/main/resources"); assertEquals(executionResult.getType(), TOExecutionResult.Type.ERROR); assertEquals(executionResult.getException().getClass(), TransformationOperationException.class); assertEquals(executionResult.getException().getMessage(), "Directory could not be copied"); assertEquals(executionResult.getException().getCause().getMessage(), "Source '" + new File(transformedAppFolder, "pom.xml").getAbsolutePath() + "' exists but is not a directory"); assertEquals(copyDirectory.getDescription(), "Copy directory content from pom.xml to src/main/resources"); assertNull(executionResult.getDetails()); }
@Test public void test() { File fromDir = new File(transformedAppFolder, "blah"); File toDir = new File(transformedAppFolder, "/src/main/resources/blah"); assertTrue(fromDir.exists()); assertTrue(fromDir.isDirectory()); assertFalse(toDir.exists()); CopyDirectory copyDirectory = new CopyDirectory().relative("blah").setToRelative("src/main/resources/blah"); TOExecutionResult executionResult = copyDirectory.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); assertEquals(copyDirectory.getDescription(), "Copy directory content from blah to src/main/resources/blah"); assertEquals(executionResult.getDetails(), "Files from '/blah' have been copied to '/src/main/resources/blah'"); assertTrue(fromDir.exists()); assertTrue(fromDir.isDirectory()); assertTrue(toDir.exists()); assertTrue(toDir.isDirectory()); assertEquals(fromDir.listFiles().length, toDir.listFiles().length); }