Skip to content

Commit

Permalink
Add BOM UT
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Jan 12, 2024
1 parent 889a2bc commit 4ca3dc9
Show file tree
Hide file tree
Showing 5 changed files with 190 additions and 1 deletion.
76 changes: 76 additions & 0 deletions src/test/java/org/apache/maven/plugins/deploy/DeployMojoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,82 @@ public void testBasicDeployWithPackagingAsPom() throws Exception {
assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}

public void testBasicDeployWithPackagingAsBom() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-bom/plugin-config.xml");

mojo = (DeployMojo) lookupMojo("deploy", testPom);

MockitoAnnotations.initMocks(this);

assertNotNull(mojo);

ProjectBuildingRequest buildingRequest = mock(ProjectBuildingRequest.class);
when(session.getProjectBuildingRequest()).thenReturn(buildingRequest);
DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(buildingRequest.getRepositorySession()).thenReturn(repositorySession);
when(session.getRepositorySession()).thenReturn(repositorySession);

File pomFile = new File(
getBasedir(),
"target/test-classes/unit/basic-deploy-bom/target/" + "deploy-test-file-1.0-SNAPSHOT.pom");

assertTrue(pomFile.exists());

MavenProject project = (MavenProject) getVariableValueFromObject(mojo, "project");
project.setGroupId("org.apache.maven.test");
project.setArtifactId("maven-deploy-test");
project.setVersion("1.0-SNAPSHOT");

setVariableValueToObject(mojo, "pluginContext", new ConcurrentHashMap<>());
setVariableValueToObject(mojo, "reactorProjects", Collections.singletonList(project));

artifact = (DeployArtifactStub) project.getArtifact();

artifact.setArtifactHandlerExtension(project.getPackaging());

artifact.setFile(pomFile);

ArtifactRepositoryStub repo = getRepoStub(mojo);

repo.setAppendToUrl("basic-deploy-bom");

mojo.execute();

List<String> expectedFiles = new ArrayList<>();
List<String> fileList = new ArrayList<>();

expectedFiles.add("org");
expectedFiles.add("apache");
expectedFiles.add("maven");
expectedFiles.add("test");
expectedFiles.add("maven-deploy-test");
expectedFiles.add("1.0-SNAPSHOT");
expectedFiles.add("maven-metadata.xml");
expectedFiles.add("maven-metadata.xml.md5");
expectedFiles.add("maven-metadata.xml.sha1");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.md5");
expectedFiles.add("maven-deploy-test-1.0-SNAPSHOT.pom.sha1");
// as we are in SNAPSHOT the file is here twice
expectedFiles.add("maven-metadata.xml");
expectedFiles.add("maven-metadata.xml.md5");
expectedFiles.add("maven-metadata.xml.sha1");
remoteRepo = new File(remoteRepo, "basic-deploy-bom");

File[] files = remoteRepo.listFiles();

for (File file : Objects.requireNonNull(files)) {
addFileToList(file, fileList);
}

assertEquals(expectedFiles.size(), fileList.size());

assertEquals(0, getSizeOfExpectedFiles(fileList, expectedFiles));
}

public void testDeployIfArtifactFileIsNull() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/basic-deploy-test/plugin-config.xml");

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.
*/
package org.apache.maven.plugins.deploy.stubs;

import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;

public class DeployBomArtifactStub extends DeployArtifactStub {
@Override
public String getType() {
return "bom";
}

public ArtifactHandler getArtifactHandler() {
return new DefaultArtifactHandler() {
public String getExtension() {
return "pom";
}
};
}
}
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.
*/
package org.apache.maven.plugins.deploy.stubs;

import org.apache.maven.artifact.handler.ArtifactHandler;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;

public class DeployPomArtifactStub extends DeployArtifactStub {
@Override
public String getType() {
return "pom";
}

public ArtifactHandler getArtifactHandler() {
return new DefaultArtifactHandler() {
public String getExtension() {
return "pom";
}
};
}
}
39 changes: 39 additions & 0 deletions src/test/resources/unit/basic-deploy-bom/plugin-config.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
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>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<project implementation="org.apache.maven.plugins.deploy.stubs.MavenProjectStub">
<file>${basedir}/src/test/resources/unit/basic-deploy-pom/plugin-config.xml</file>
<packaging>bom</packaging>
<artifact implementation="org.apache.maven.plugins.deploy.stubs.DeployBomArtifactStub" />
<attachedArtifacts />
<deploymentRepository implementation="org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub">
<basedir>${basedir}</basedir>
</deploymentRepository>
</project>
</configuration>
</plugin>
</plugins>
</build>
</project>
2 changes: 1 addition & 1 deletion src/test/resources/unit/basic-deploy-pom/plugin-config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ under the License.
<project implementation="org.apache.maven.plugins.deploy.stubs.MavenProjectStub">
<file>${basedir}/src/test/resources/unit/basic-deploy-pom/plugin-config.xml</file>
<packaging>pom</packaging>
<artifact implementation="org.apache.maven.plugins.deploy.stubs.DeployArtifactStub" />
<artifact implementation="org.apache.maven.plugins.deploy.stubs.DeployPomArtifactStub" />
<attachedArtifacts />
<deploymentRepository implementation="org.apache.maven.plugins.deploy.stubs.ArtifactRepositoryStub">
<basedir>${basedir}</basedir>
Expand Down

0 comments on commit 4ca3dc9

Please sign in to comment.