Skip to content

Commit

Permalink
[MRELEASE-1054] Add some unit test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
wuwen5 committed Dec 13, 2024
1 parent e236be7 commit 02e42c5
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2454,21 +2454,43 @@ public void testSimulateRelease_CheckModificationExcludes() throws Exception {
MapReleaseVersionsPhase phase =
new MapReleaseVersionsPhase(scmRepositoryConfigurator, mockPrompter, versionPolicies);

List<MavenProject> reactorProjects = Collections.singletonList(createProjectWithPomFile("artifactId", "1.2"));
List<MavenProject> reactorProjects = new ArrayList<>();
Collections.addAll(
reactorProjects,
createProject("bar", "1.11-SNAPSHOT"),
createProjectWithPomFile("artifactId", "1.2-SNAPSHOT", "src/test/resources/projects/scm-commit/multiple-poms/pom.xml"),
createProjectWithPomFile("subproject1", "2.0", "src/test/resources/projects/scm-commit/multiple-poms/subproject1/pom.xml"));

ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
builder.setCheckModificationExcludes(Collections.singletonList("**/pom1.xml"));
builder.setCheckModificationExcludes(Collections.singletonList("**/subproject1/pom.xml"));
builder.setInteractive(false);

// test
phase.simulate(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);

// verify
assertNull(
assertEquals(
"Check release versions",
"1.2",
ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:artifactId"));
assertNull(
"Check development versions",
ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:artifactId"));

assertEquals(
"Check release versions",
"1.11",
ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:bar"));
assertNull(
"Check development versions",
ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:bar"));

assertNull(
"Check release versions",
ReleaseUtils.buildReleaseDescriptor(builder).getProjectReleaseVersion("groupId:subproject1"));
assertNull(
"Check development versions",
ReleaseUtils.buildReleaseDescriptor(builder).getProjectDevelopmentVersion("groupId:subproject1"));
}

private static MavenProject createProject(String artifactId, String version) {
Expand All @@ -2479,13 +2501,13 @@ private static MavenProject createProject(String artifactId, String version) {
return new MavenProject(model);
}

private static MavenProject createProjectWithPomFile(String artifactId, String version) {
private static MavenProject createProjectWithPomFile(String artifactId, String version, String pathName) {
Model model = new Model();
model.setGroupId("groupId");
model.setArtifactId(artifactId);
model.setVersion(version);
MavenProject mavenProject = new MavenProject(model);
mavenProject.setFile(new File("src/test/resources/pomfinder/pom1.xml"));
mavenProject.setFile(new File(pathName));
return mavenProject;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.File;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
Expand Down Expand Up @@ -454,4 +455,19 @@ public void testRewritePomWithDifferentVersionsAcrossModules() throws Exception

assertTrue(comparePomFiles(reactorProjects));
}

@Test
public void testRewritePomWithCheckModificationExcludes() throws Exception {
List<MavenProject> reactorProjects = createReactorProjects("multimodule-with-check-modification-excludes");

ReleaseDescriptorBuilder builder =
createDescriptorFromProjects(reactorProjects, "multimodule-with-check-modification-excludes");
builder.addReleaseVersion("groupId:artifactId", NEXT_VERSION);
builder.addReleaseVersion("groupId:subproject1", ALTERNATIVE_NEXT_VERSION);
builder.setCheckModificationExcludes(Collections.singletonList("**/subproject2/*"));

phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);

assertTrue(comparePomFiles(reactorProjects));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,52 @@ public void testSuppressCommitAfterBranch() throws Exception {
verifyNoMoreInteractions(scmProviderMock);
}

@Test
public void testCommitMultiModuleWithCheckModificationExcludes() throws Exception {
// prepare
ReleaseDescriptorBuilder builder = new ReleaseDescriptorBuilder();
String dir = "scm-commit/multiple-poms";
List<MavenProject> reactorProjects = createReactorProjects(dir, dir, null);
builder.setScmSourceUrl("scm-url");
MavenProject rootProject = ReleaseUtil.getRootProject(reactorProjects);
builder.setWorkingDirectory(rootProject.getFile().getParentFile().getAbsolutePath());
builder.setScmReleaseLabel("release-label");
builder.setCheckModificationExcludes(Collections.singletonList("**/subproject2/*"));

List<File> poms = new ArrayList<>();
for (Iterator<MavenProject> i = reactorProjects.iterator(); i.hasNext(); ) {
MavenProject project = i.next();
//This is a mock match that verifies that the project has not been submitted
if (!"subproject2".equals(project.getName())) {
poms.add(project.getFile());
}
}
ScmFileSet fileSet = new ScmFileSet(rootProject.getFile().getParentFile(), poms);

ScmProvider scmProviderMock = mock(ScmProvider.class);
when(scmProviderMock.checkIn(
isA(ScmRepository.class),
argThat(new IsScmFileSetEquals(fileSet)),
isNull(ScmVersion.class),
eq(PREFIX + "release-label")))
.thenReturn(new CheckInScmResult(
"...",
Collections.singletonList(
new ScmFile(rootProject.getFile().getPath(), ScmFileStatus.CHECKED_IN))));
ScmManagerStub stub = (ScmManagerStub) lookup(ScmManager.class);
stub.setScmProvider(scmProviderMock);

// execute
phase.execute(ReleaseUtils.buildReleaseDescriptor(builder), new DefaultReleaseEnvironment(), reactorProjects);

// verify
verify(scmProviderMock)
.checkIn(
isA(ScmRepository.class), argThat(new IsScmFileSetEquals(fileSet)),
isNull(ScmVersion.class), eq(PREFIX + "release-label"));
verifyNoMoreInteractions(scmProviderMock);
}

private List<MavenProject> createReactorProjects() throws Exception {
String dir = "scm-commit/single-pom";
return createReactorProjects(dir, dir, null);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0</version>
<packaging>pom</packaging>

<scm>
<connection>scm:svn:file://localhost/tmp/scm-repo/tags/release-label</connection>
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/tags/release-label</developerConnection>
<url>file://localhost/tmp/scm-repo/tags/release-label</url>
</scm>

<modules>
<module>subproject1</module>
<module>subproject2</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>

<scm>
<connection>scm:svn:file://localhost/tmp/scm-repo/trunk</connection>
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk</developerConnection>
<url>file://localhost/tmp/scm-repo/trunk</url>
</scm>

<modules>
<module>subproject1</module>
<module>subproject2</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0</version>
</parent>

<artifactId>subproject1</artifactId>
<version>2.0</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>subproject1</artifactId>
<version>2.0-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<scm>
<connection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</connection>
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</developerConnection>
<url>file://localhost/tmp/scm-repo/trunk/subproject2</url>
</scm>

<artifactId>subproject2</artifactId>
<version>2.0-SNAPSHOT</version>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->

<project>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>groupId</groupId>
<artifactId>artifactId</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<scm>
<connection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</connection>
<developerConnection>scm:svn:file://localhost/tmp/scm-repo/trunk/subproject2</developerConnection>
<url>file://localhost/tmp/scm-repo/trunk/subproject2</url>
</scm>

<artifactId>subproject2</artifactId>
<version>2.0-SNAPSHOT</version>
</project>

0 comments on commit 02e42c5

Please sign in to comment.