diff --git a/src/test/java/org/springframework/cloud/release/PomUpdaterTests.java b/src/test/java/org/springframework/cloud/release/PomUpdaterTests.java index 6ff6c84a..236c624f 100644 --- a/src/test/java/org/springframework/cloud/release/PomUpdaterTests.java +++ b/src/test/java/org/springframework/cloud/release/PomUpdaterTests.java @@ -115,6 +115,70 @@ public class PomUpdaterTests { .containsEntry("spring-cloud-vault.version", "0.0.4.BUILD-SNAPSHOT"); } + @Test + public void should_not_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception { + File springCloudReleasePom = pom("/projects/spring-cloud-release"); + + then(this.pomUpdater.shouldProjectBeUpdated(springCloudReleasePom, this.versions)).isFalse(); + } + + @Test + public void should_update_child_pom_when_project_is_not_on_the_versions_list() throws Exception { + File springCloudSleuthPom = pom("/projects/spring-cloud-sleuth"); + + then(this.pomUpdater.shouldProjectBeUpdated(springCloudSleuthPom, this.versions)).isTrue(); + } + + @Test + public void should_not_update_the_child_model_if_no_changes_were_made() throws Exception { + File nonMatchingPom = pom("/projects/project"); + + ModelWrapper model = this.pomUpdater.updatePom(nonMatchingPom, this.versions); + + then(model.dirty).isFalse(); + } + + @Test + public void should_update_the_child_model_if_parent_is_matched_via_sc_build() throws Exception { + File matchingArtifactId = pom("/projects/project/children", "pom_matching_parent_v2.xml"); + + ModelWrapper model = this.pomUpdater.updatePom(matchingArtifactId, this.versions); + + then(model.dirty).isTrue(); + then(model.model.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + // the rest is the same + then(model.model.getProperties()) + .containsEntry("spring-cloud-foo.version", "1.3.1.BUILD-SNAPSHOT") + .containsEntry("foo.version", "1.2.0.BUILD-SNAPSHOT"); + } + + @Test + public void should_update_the_child_model_if_parent_is_matched_via_sc_dependencies_parent() throws Exception { + File matchingArtifactId = pom("/projects/project/children", "pom_matching_parent.xml"); + + ModelWrapper model = this.pomUpdater.updatePom(matchingArtifactId, this.versions); + + then(model.dirty).isTrue(); + then(model.model.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + // the rest is the same + then(model.model.getProperties()) + .containsEntry("spring-cloud-foo.version", "1.3.1.BUILD-SNAPSHOT") + .containsEntry("foo.version", "1.2.0.BUILD-SNAPSHOT"); + } + + @Test + public void should_update_the_child_model_if_properties_are_matched() throws Exception { + File matchingArtifactId = pom("/projects/project/children", "pom_matching_properties.xml"); + + ModelWrapper model = this.pomUpdater.updatePom(matchingArtifactId, this.versions); + + then(model.dirty).isTrue(); + then(model.model.getParent().getVersion()).isEqualTo("0.0.3.BUILD-SNAPSHOT"); + then(model.model.getProperties()) + .containsEntry("spring-cloud-sleuth.version", "0.0.3.BUILD-SNAPSHOT") + .containsEntry("spring-cloud-vault.version", "0.0.4.BUILD-SNAPSHOT"); + } + Set projects() { Set projects = new HashSet<>(); projects.add(new Project("spring-cloud-sleuth", "0.0.3.BUILD-SNAPSHOT")); diff --git a/src/test/resources/projects/project/children/pom.xml b/src/test/resources/projects/project/children/pom.xml new file mode 100644 index 00000000..039b9bf6 --- /dev/null +++ b/src/test/resources/projects/project/children/pom.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + foo + 1.2.0.BUILD-SNAPSHOT + pom + foo + foo + + + parentGroup + parentArtifactId + 1.3.1.BUILD-SNAPSHOT + .. + + + + 1.3.1.BUILD-SNAPSHOT + 1.2.0.BUILD-SNAPSHOT + + diff --git a/src/test/resources/projects/project/children/pom_matching_artifact.xml b/src/test/resources/projects/project/children/pom_matching_artifact.xml new file mode 100644 index 00000000..0d53f5e5 --- /dev/null +++ b/src/test/resources/projects/project/children/pom_matching_artifact.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + spring-cloud-sleuth-child + 1.2.0.BUILD-SNAPSHOT + pom + foo + foo + + + parentGroup + parentArtifactId + 1.3.1.BUILD-SNAPSHOT + .. + + + + 1.3.1.BUILD-SNAPSHOT + 1.2.0.BUILD-SNAPSHOT + + diff --git a/src/test/resources/projects/project/children/pom_matching_parent.xml b/src/test/resources/projects/project/children/pom_matching_parent.xml new file mode 100644 index 00000000..f64bd647 --- /dev/null +++ b/src/test/resources/projects/project/children/pom_matching_parent.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + spring-cloud-sleuth-child + 1.2.0.BUILD-SNAPSHOT + pom + foo + foo + + + org.springframework.cloud + spring-cloud-sleuth + 1.3.1.BUILD-SNAPSHOT + .. + + + + 1.3.1.BUILD-SNAPSHOT + 1.2.0.BUILD-SNAPSHOT + + diff --git a/src/test/resources/projects/project/children/pom_matching_parent_v2.xml b/src/test/resources/projects/project/children/pom_matching_parent_v2.xml new file mode 100644 index 00000000..f64bd647 --- /dev/null +++ b/src/test/resources/projects/project/children/pom_matching_parent_v2.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + spring-cloud-sleuth-child + 1.2.0.BUILD-SNAPSHOT + pom + foo + foo + + + org.springframework.cloud + spring-cloud-sleuth + 1.3.1.BUILD-SNAPSHOT + .. + + + + 1.3.1.BUILD-SNAPSHOT + 1.2.0.BUILD-SNAPSHOT + + diff --git a/src/test/resources/projects/project/children/pom_matching_properties.xml b/src/test/resources/projects/project/children/pom_matching_properties.xml new file mode 100644 index 00000000..c2be71c2 --- /dev/null +++ b/src/test/resources/projects/project/children/pom_matching_properties.xml @@ -0,0 +1,40 @@ + + + + + 4.0.0 + + spring-cloud-sleuth-child + 1.2.0.BUILD-SNAPSHOT + pom + foo + foo + + + org.springframework.cloud + spring-cloud-sleuth + 1.3.1.BUILD-SNAPSHOT + .. + + + + 1.3.1.BUILD-SNAPSHOT + 1.2.0.BUILD-SNAPSHOT + +