Skip to content

Commit

Permalink
Add UT
Browse files Browse the repository at this point in the history
  • Loading branch information
cstamas committed Aug 14, 2024
1 parent 8ae86c8 commit 313eb77
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,41 @@ public void testDeployIfArtifactIsNotJar() throws Exception {
assertTrue(file.exists());
}

public void testDeployFileIfPackagingIsSet() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/deploy-file-packaging/plugin-config.xml");
mojo = (DeployFileMojo) lookupMojo("deploy-file", testPom);

openMocks = MockitoAnnotations.openMocks(this);

assertNotNull(mojo);

DefaultRepositorySystemSession repositorySession = new DefaultRepositorySystemSession();
repositorySession.setLocalRepositoryManager(
new SimpleLocalRepositoryManagerFactory(new DefaultLocalPathComposer())
.newInstance(repositorySession, new LocalRepository(LOCAL_REPO)));
when(session.getRepositorySession()).thenReturn(repositorySession);

String packaging = (String) getVariableValueFromObject(mojo, "packaging");

String groupId = (String) getVariableValueFromObject(mojo, "groupId");

String artifactId = (String) getVariableValueFromObject(mojo, "artifactId");

String version = (String) getVariableValueFromObject(mojo, "version");

assertEquals("differentpackaging", packaging);

mojo.execute();

File deployedArtifact = new File(
remoteRepo,
"deploy-file-packaging/" + groupId.replace('.', '/') + "/"
+ artifactId + "/" + version + "/" + artifactId + "-"
+ version + "." + packaging);

assertTrue(deployedArtifact.exists());
}

private void addFileToList(File file, List<String> fileList) {
if (!file.isDirectory()) {
fileList.add(file.getName());
Expand Down
36 changes: 36 additions & 0 deletions src/test/resources/unit/deploy-file-packaging/plugin-config.xml
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>
<build>
<plugins>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<groupId>org.apache.maven.test</groupId>
<artifactId>maven-deploy-file-test</artifactId>
<version>1.0</version>
<packaging>differentpackaging</packaging>
<file>${basedir}/src/test/resources/unit/deploy-file-packaging/target/deploy-test-file-1.0-SNAPSHOT.jar</file>
<repositoryId>deploy-test</repositoryId>
<url>file://${basedir}/target/remote-repo/deploy-file-packaging</url>
<generatePom>true</generatePom>
</configuration>
</plugin>
</plugins>
</build>
</project>

0 comments on commit 313eb77

Please sign in to comment.