@Test public void test() throws IOException { File originalFile = new File(transformedAppFolder, "foo.xml"); File toDir = new File(transformedAppFolder, "/src/main/resources"); assertTrue(originalFile.exists()); assertTrue(originalFile.isFile()); assertTrue(toDir.exists()); File tempOriginalFile = File.createTempFile("butterfly-test-file", null); FileUtils.copyFile(originalFile, tempOriginalFile); Mockito.when(transformationContext.get("ATT")).thenReturn(new File(transformedAppFolder, "/src/main/resources")); MoveFile moveFile = new MoveFile().relative("foo.xml").setToAbsolute("ATT"); TOExecutionResult executionResult = moveFile.execution(transformedAppFolder, transformationContext); assertEquals(executionResult.getType(), TOExecutionResult.Type.SUCCESS); assertEquals(moveFile.getToAbsoluteAttribute(), "ATT"); assertEquals(moveFile.getDescription(), "Move file foo.xml to the location defined by transformation context attribute ATT"); assertEquals(executionResult.getDetails(), "File 'foo.xml' has been moved to '/src/main/resources'"); File copiedFile = new File(transformedAppFolder, "/src/main/resources/foo.xml"); assertFalse(originalFile.exists()); assertTrue(copiedFile.exists()); assertTrue(FileUtils.contentEquals(tempOriginalFile, copiedFile)); tempOriginalFile.delete(); }
@Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext); File fileTo = getFileTo(transformedAppFolder, transformationContext); TOExecutionResult result; try { if (fileFrom.isDirectory()) { IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)"); result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", ex)); } else { String details = String.format("File '%s' has been moved to '%s'", getRelativePath(), getRelativePath(transformedAppFolder, fileTo)); FileUtils.copyFileToDirectory(fileFrom, fileTo); FileUtils.fileDelete(fileFrom.getAbsolutePath()); result = TOExecutionResult.success(this, details); } } catch (IOException e) { result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", e)); } return result; }
MoveFile extends AbstractToOperation<MoveFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext); File fileTo = getFileTo(transformedAppFolder, transformationContext); TOExecutionResult result; try { if (fileFrom.isDirectory()) { IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)"); result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", ex)); } else { String details = String.format("File '%s' has been moved to '%s'", getRelativePath(), getRelativePath(transformedAppFolder, fileTo)); FileUtils.copyFileToDirectory(fileFrom, fileTo); FileUtils.fileDelete(fileFrom.getAbsolutePath()); result = TOExecutionResult.success(this, details); } } catch (IOException e) { result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", e)); } return result; } }
MoveFile extends AbstractToOperation<MoveFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext); File fileTo = getFileTo(transformedAppFolder, transformationContext); TOExecutionResult result; try { if (fileFrom.isDirectory()) { IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)"); result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", ex)); } else { String details = String.format("File '%s' has been moved to '%s'", getRelativePath(), getRelativePath(transformedAppFolder, fileTo)); FileUtils.copyFileToDirectory(fileFrom, fileTo); FileUtils.fileDelete(fileFrom.getAbsolutePath()); result = TOExecutionResult.success(this, details); } } catch (IOException e) { result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", e)); } return result; } MoveFile(); }
MoveFile extends AbstractToOperation<MoveFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext); File fileTo = getFileTo(transformedAppFolder, transformationContext); TOExecutionResult result; try { if (fileFrom.isDirectory()) { IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)"); result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", ex)); } else { String details = String.format("File '%s' has been moved to '%s'", getRelativePath(), getRelativePath(transformedAppFolder, fileTo)); FileUtils.copyFileToDirectory(fileFrom, fileTo); FileUtils.fileDelete(fileFrom.getAbsolutePath()); result = TOExecutionResult.success(this, details); } } catch (IOException e) { result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", e)); } return result; } MoveFile();  }
MoveFile extends AbstractToOperation<MoveFile> { @Override protected TOExecutionResult execution(File transformedAppFolder, TransformationContext transformationContext) { File fileFrom = getAbsoluteFile(transformedAppFolder, transformationContext); File fileTo = getFileTo(transformedAppFolder, transformationContext); TOExecutionResult result; try { if (fileFrom.isDirectory()) { IOException ex = new IOException(getRelativePath(transformedAppFolder, fileFrom) + " (Is a directory)"); result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", ex)); } else { String details = String.format("File '%s' has been moved to '%s'", getRelativePath(), getRelativePath(transformedAppFolder, fileTo)); FileUtils.copyFileToDirectory(fileFrom, fileTo); FileUtils.fileDelete(fileFrom.getAbsolutePath()); result = TOExecutionResult.success(this, details); } } catch (IOException e) { result = TOExecutionResult.error(this, new TransformationOperationException("File could not be moved", e)); } return result; } MoveFile();   }