From a2ceadf779041fbeeea5cb45d0d94cbe52ff3d68 Mon Sep 17 00:00:00 2001 From: Manik Magar Date: Sun, 11 Oct 2020 21:08:16 -0400 Subject: [PATCH] fix: generation for xml path without parent (#124) fixes #163 example - `mulefd test-api.xml` will not fail now. [patch] --- .../javastreets/mulefd/app/Application.java | 2 +- .../mulefd/app/ApplicationTest.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/javastreets/mulefd/app/Application.java b/src/main/java/com/javastreets/mulefd/app/Application.java index 687b8e7..29ecd84 100644 --- a/src/main/java/com/javastreets/mulefd/app/Application.java +++ b/src/main/java/com/javastreets/mulefd/app/Application.java @@ -70,7 +70,7 @@ CommandModel getCommandModel() { if (Files.isDirectory(sourcePath)) resolvedTarget = sourcePath; if (Files.isRegularFile(sourcePath)) - resolvedTarget = sourcePath.toFile().getParentFile().toPath(); + resolvedTarget = sourcePath.toAbsolutePath().getParent(); } cm.setTargetPath(resolvedTarget); cm.setDiagramType(diagramType); diff --git a/src/test/java/com/javastreets/mulefd/app/ApplicationTest.java b/src/test/java/com/javastreets/mulefd/app/ApplicationTest.java index a1ee393..396f863 100644 --- a/src/test/java/com/javastreets/mulefd/app/ApplicationTest.java +++ b/src/test/java/com/javastreets/mulefd/app/ApplicationTest.java @@ -89,6 +89,28 @@ void commandLineWithSourceDirectory() { } + @Test + @DisplayName("When parsing source file without parent folder, sets parent as target") + void commandLineWithBareSourceFile() throws Exception { + tempDir.createNewFile(); + Path sourceFile = Paths.get("db-config.xml"); + sourceFile.toFile().delete(); + Files.copy(Paths.get("src/test/resources/renderer/component-configs/db-config.xml"), + sourceFile); + String[] args = new String[] {sourceFile.toString()}; + Application application = new Application(); + new CommandLine(application).parseArgs(args); + CommandModel model = application.getCommandModel(); + + CommandModel expectedModel = new CommandModel(); + expectedModel.setSourcePath(sourceFile); + expectedModel.setTargetPath(sourceFile.toAbsolutePath().getParent()); + expectedModel.setDiagramType(DiagramType.GRAPH); + expectedModel.setOutputFilename("mule-diagram.png"); + expectedModel.setGenerateSingles(false); + assertThat(model).isEqualToComparingFieldByField(expectedModel); + } + @Test @DisplayName("When parsing source file, sets parent as target") void commandLineWithSourceFile() throws Exception {