diff --git a/pom.xml b/pom.xml index ad628a4..0311a0a 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,11 @@ 2.9.1 test + + com.approvaltests + approvaltests + 22.3.2 + com.sun.xml.bind diff --git a/src/test/java/io/fabric8/maven/MavenTest.java b/src/test/java/io/fabric8/maven/MavenTest.java index ad13146..8679e9f 100644 --- a/src/test/java/io/fabric8/maven/MavenTest.java +++ b/src/test/java/io/fabric8/maven/MavenTest.java @@ -15,6 +15,7 @@ import org.apache.maven.model.Model; import org.apache.maven.model.Scm; +import org.approvaltests.Approvals; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -120,6 +121,47 @@ void should_preserve_parent_relative_path(@TempDir Path tempDir) throws Exceptio .isEqualTo("../../pom.xml"); } + @Test + void should_save_full_pom_on_new_file(@TempDir Path tempDir) throws Exception { + URL resource = getClass().getResource("full-pom.xml"); + Path basePom = Paths.get(resource.toURI()); + Model model = Maven.readModel(new FileReader(basePom.toFile())); + + Path newPom = tempDir.resolve("new-pom.xml"); + Maven.writeModel(model, newPom); + + Approvals.verify(Files.readString(newPom)); + } + + @Test + void should_save_full_pom_on_updated_full_file(@TempDir Path tempDir) throws Exception { + URL resource = getClass().getResource("full-pom.xml"); + Path basePom = Paths.get(resource.toURI()); + Model model = Maven.readModel(new FileReader(basePom.toFile())); + + Path updatedPom = tempDir.resolve("updated-full-pom.xml"); + Files.copy(basePom, updatedPom); + Maven.writeModel(model, updatedPom); + + Approvals.verify(Files.readString(updatedPom)); + } + + @Test + void should_save_full_pom_on_updated_minimal_file(@TempDir Path tempDir) throws Exception { + URL resource = getClass().getResource("full-pom.xml"); + Path basePom = Paths.get(resource.toURI()); + Model model = Maven.readModel(new FileReader(basePom.toFile())); + + Path updatedPom = tempDir.resolve("updated-minimal-pom.xml"); + Files.writeString(updatedPom, "\n" + + ""); + Maven.writeModel(model, updatedPom); + + Approvals.verify(Files.readString(updatedPom)); + } + @Test void should_write_scm_tag(@TempDir Path tempDir) throws Exception { Path pomXml = tempDir.resolve("pom.xml"); diff --git a/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_new_file.approved.txt b/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_new_file.approved.txt new file mode 100644 index 0000000..9072ad0 --- /dev/null +++ b/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_new_file.approved.txt @@ -0,0 +1,711 @@ + + + 4.0.0 + + org.jboss + jboss-parent + 43 + + org.acme + full-pom + 0.0.1 + pom + Full Test POM.xml + Full pom.xml for testing purpose + https://acme.org/full-pom + 2024 + + ACME + https://acme.org + + + + string + string + string + string + + + + + string + string + string + string + string + string + + string + + string + + FRANCE + + + + + + string + string + string + string + string + + string + + string + + BLUE + + + + + + string + string + string + string + string + + string + + + + + string + + + string + + + scm:git:git://github.com/fabric8-launcher/maven-model-helper.git + scm:git:git@github.com:fabric8-launcher/maven-model-helper.git + https://github.com/fabric8-launcher/maven-model-helper + + + string + string + + + string + string + + + string + false +
string
+ + 1324567890 + +
+
+
+ + + + true + string + string + + + false + string + string + + string + string + string + string + + + + false + string + string + + + true + string + string + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + false + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + string + string + string + + + string + string + + + false + + + + + + true + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + true + string + string + + string + string + string + string + + + + string + string + string + string + string + + + string + string + string + + + string + + + string + true + string + + string + + + string + + + + + + string + false + string + + string + + + string + + + + string + string + + string + + + + + maven-compiler-plugin + ${compiler-plugin.version} + false + + + string + string + + string + + string + + false + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + integration-test + + true + + ${java.version} + ${java.version} + true + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + true + + + check + verify + + check + + true + + target/jacoco/allTest.exec + + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + check + + false + + + + CLASS + + + + + + + + index + + + true + string + + + string + string + string + + + report1 + + foo + + false + + bar + + + + string + + foo + + + + + + + string + + true + string + + string + string + string + string + + + string + string + + + string + string + + + + string + + + string + false + string + + string + + + string + + + + + + string + true + string + + string + + + string + + + + string + string + + string + + + + + string + string + string + true + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + bar + + string + + bar + + + + + + + string + string + string + false + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + false + + + + bar + + string + + bar + + + + + + string + + + + + true + string + string + + + false + string + string + + string + string + string + string + + + + false + string + string + + + true + string + string + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + true + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + true + string + string + + string + string + string + string + + + + bar + + + false + string + + + string + string + string + + + string + + string + + string + + bar + + + + string + + bar + + + + + + +
diff --git a/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_updated_full_file.approved.txt b/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_updated_full_file.approved.txt new file mode 100644 index 0000000..5f06aeb --- /dev/null +++ b/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_updated_full_file.approved.txt @@ -0,0 +1,706 @@ + + + 4.0.0 + + org.jboss + jboss-parent + 43 + + org.acme + full-pom + 0.0.1 + pom + Full Test POM.xml + Full pom.xml for testing purpose + https://acme.org/full-pom + 2024 + + ACME + https://acme.org + + + + string + string + string + string + + + + + string + string + string + string + string + string + + string + + string + + + FRANCE + + + + + + string + string + string + string + string + + string + + string + + BLUE + + + + + + string + string + string + string + string + + string + + + + + string + + + string + + + scm:git:git://github.com/fabric8-launcher/maven-model-helper.git + scm:git:git@github.com:fabric8-launcher/maven-model-helper.git + https://github.com/fabric8-launcher/maven-model-helper + HEAD + + + string + string + + + string + string + + + string + false +
string
+ + + 1324567890 + + +
+
+
+ + + + true + string + string + + + false + string + string + + string + string + string + string + + + + false + string + string + + + true + string + string + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + false + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + + + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + string + string + + string + string + string + string + + + + string + string + string + string + string + + + string + string + string + + + string + + + string + true + string + + string + + + string + + + + + + string + string + + string + + + string + + + + string + string + + string + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler-plugin.version} + + + string + string + + string + + string + + false + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + integration-test + + true + + ${java.version} + ${java.version} + true + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + true + + + check + verify + + check + + true + + + target/jacoco/allTest.exec + + + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + check + + false + + + + CLASS + + + + + + + + index + + + true + string + + + string + string + string + + + report1 + + foo + + false + + bar + + + + string + + foo + + + + + + + string + + true + string + + string + string + string + string + + + string + string + + + string + string + + + + string + + + string + string + + string + + + string + + + + + + string + true + string + + string + + + string + + + + string + string + + string + + + + + string + string + string + true + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + bar + + string + + bar + + + + + + + string + string + string + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + bar + + string + + bar + + + + + + string + + + + + true + string + string + + + false + string + string + + string + string + string + string + + + + false + string + string + + + true + string + string + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + string + string + + string + string + string + string + + + + bar + + + string + + + string + string + string + + + string + + string + + string + + bar + + + + string + + bar + + + + + + +
diff --git a/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_updated_minimal_file.approved.txt b/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_updated_minimal_file.approved.txt new file mode 100644 index 0000000..3517dee --- /dev/null +++ b/src/test/java/io/fabric8/maven/MavenTest.should_save_full_pom_on_updated_minimal_file.approved.txt @@ -0,0 +1,659 @@ + + + + jboss-parent + org.jboss + 43 + + 4.0.0 + org.acme + full-pom + pom + Full Test POM.xml + 0.0.1 + Full pom.xml for testing purpose + https://acme.org/full-pom + + string + + + string + string + + + string + string + + + string + false +
string
+ + 1324567890 + +
+
+
+ 2024 + + + string + string + string + string + string + + string + + + + + + string + string + string + string + string + string + + string + + string + + FRANCE + + + + + + string + string + string + string + string + + string + + string + + BLUE + + + + + + string + string + string + string + + + + scm:git:git://github.com/fabric8-launcher/maven-model-helper.git + scm:git:git@github.com:fabric8-launcher/maven-model-helper.git + https://github.com/fabric8-launcher/maven-model-helper + + + ACME + https://acme.org + + + string + string + string + string + string + + + string + string + string + + + string + + + string + true + string + + string + + + string + + + + + + string + string + + string + + + string + + + + string + string + + string + + + + + maven-compiler-plugin + ${compiler-plugin.version} + + + string + string + + string + + string + + false + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + integration-test + + true + + ${java.version} + ${java.version} + true + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + true + + + check + verify + + check + + true + + target/jacoco/allTest.exec + + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + check + + false + + + + CLASS + + + + + + + + + string + + true + string + + string + string + string + string + + + string + string + + + string + string + + + + string + + + string + string + + string + + + string + + + + + + string + true + string + + string + + + string + + + + string + string + + string + + + + + string + string + string + true + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + bar + + string + + bar + + + + + + + string + string + string + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + bar + + string + + bar + + + + + + string + + + + + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + string + string + + string + string + string + string + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + bar + + + string + + + string + string + string + string + + bar + + + + string + + bar + + string + + string + + + + + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + + + + + string + + + + + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + string + string + + string + string + string + string + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + index + + + true + string + + + string + string + string + string + + foo + + + + report1 + + bar + + false + + foo + + + + + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + false + +
diff --git a/src/test/resources/io/fabric8/maven/full-pom.xml b/src/test/resources/io/fabric8/maven/full-pom.xml new file mode 100644 index 0000000..63479fb --- /dev/null +++ b/src/test/resources/io/fabric8/maven/full-pom.xml @@ -0,0 +1,723 @@ + + + 4.0.0 + + org.jboss + jboss-parent + 43 + + org.acme + full-pom + 0.0.1 + pom + Full Test POM.xml + Full pom.xml for testing purpose + https://acme.org/full-pom + 2024 + + ACME + https://acme.org + + + + string + string + string + string + + + + + string + string + string + string + string + string + + string + + string + + + FRANCE + + + + + + string + string + string + string + string + + string + + string + + BLUE + + + + + + string + string + string + string + string + + string + + + + + string + + + string + + + scm:git:git://github.com/fabric8-launcher/maven-model-helper.git + scm:git:git@github.com:fabric8-launcher/maven-model-helper.git + https://github.com/fabric8-launcher/maven-model-helper + HEAD + + + string + string + + + string + string + + + string + true + true + false + true +
string
+ + + 1324567890 + +
+
+
+ + + true + + true + string + string + + + false + string + string + + string + string + string + string + + + true + + false + string + string + + + true + string + string + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + false + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + string + string + string + + + string + string + + + false + + + + + + true + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + true + string + string + + string + string + string + string + + + + string + string + string + string + string + + + string + string + string + + + string + + + string + true + string + + string + + + string + + + + + + string + false + string + + string + + + string + + + + string + string + + string + + + + + org.apache.maven.plugins + maven-compiler-plugin + ${compiler-plugin.version} + false + + + string + string + + string + + string + + false + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + integration-test + + true + + ${java.version} + ${java.version} + true + + + + + + + org.jacoco + jacoco-maven-plugin + ${jacoco.version} + true + + + check + verify + + check + + true + + + target/jacoco/allTest.exec + + + + + + string + string + string + string + string + string + string + + + string + string + + + + + + check + + false + + + + CLASS + + + + + + + + index + + + true + string + + + string + string + string + + + report1 + + foo + + false + + bar + + + + string + + foo + + + + + + + string + + true + string + + string + string + string + string + + + string + string + + + string + string + + + + string + + + string + false + string + + string + + + string + + + + + + string + true + string + + string + + + string + + + + string + string + + string + + + + + string + string + string + true + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + bar + + string + + bar + + + + + + + string + string + string + false + + + string + string + + string + + string + + bar + + + + + + string + string + string + string + string + string + string + + + string + string + + + false + + + + bar + + string + + bar + + + + + + string + + + + true + + true + string + string + + + false + string + string + + string + string + string + string + + + true + + false + string + string + + + true + string + string + + string + string + string + string + + + string + string + string + + string + + string + string + string + string + + string + + + true + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + string + string + string + string + string + string + string + + + string + string + + + true + + + + + + true + string + string + + + false + string + string + + string + string + string + string + + + + + + false + string + string + + + true + string + string + + string + string + string + string + + + + bar + + + false + string + + + string + string + string + + + string + + string + + string + + bar + + + + string + + bar + + + + + + +