Skip to content

Commit

Permalink
Merge pull request #1 from mabrarov/MEAR-287_it
Browse files Browse the repository at this point in the history
[MEAR-287] - Integration test for MEAR-287 fix
  • Loading branch information
zzzLobster authored Oct 2, 2020
2 parents 92b300c + 4d14823 commit 5bcdf4c
Show file tree
Hide file tree
Showing 8 changed files with 277 additions and 15 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
<javaVersion>7</javaVersion>
<surefire.version>2.22.2</surefire.version>
<project.build.outputTimestamp>2020-09-26T20:10:30Z</project.build.outputTimestamp>
<mavenWarPluginVersion>2.1.1</mavenWarPluginVersion>
</properties>

<dependencies>
Expand Down Expand Up @@ -280,7 +281,7 @@
<goal>package</goal>
</goals>
<extraArtifacts>
<extraArtifact>org.apache.maven.plugins:maven-war-plugin:2.1.1:jar</extraArtifact>
<extraArtifact>org.apache.maven.plugins:maven-war-plugin:${mavenWarPluginVersion}:jar</extraArtifact>
<extraArtifact>org.apache.maven.plugins:maven-compiler-plugin:2.5.1:jar</extraArtifact>
<extraArtifact>org.apache.maven.plugins:maven-ejb-plugin:2.3:jar</extraArtifact>
</extraArtifacts>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,17 @@ public abstract class AbstractEarPluginIT
* @param projectName the name of the project
* @param properties extra properties to be used by the embedder
* @param expectNoError true/false
* @param cleanBeforeExecute call clean plugin before execution
* @return the base directory of the project
*/
protected File executeMojo( final String projectName, final Properties properties, boolean expectNoError ) throws VerificationException, IOException
protected File executeMojo( final String projectName, final Properties properties, boolean expectNoError,
boolean cleanBeforeExecute ) throws VerificationException, IOException
{
System.out.println( " Building: " + projectName );

File testDir = getTestDir( projectName );
Verifier verifier = new Verifier( testDir.getAbsolutePath() );
verifier.setAutoclean( cleanBeforeExecute );
// Let's add alternate settings.xml setting so that the latest dependencies are used
String localRepo = System.getProperty( "localRepositoryPath" );
verifier.setLocalRepo( localRepo );
Expand Down Expand Up @@ -119,31 +122,48 @@ protected File executeMojo( final String projectName, final Properties propertie
protected File executeMojo( final String projectName, final Properties properties )
throws VerificationException, IOException
{
return executeMojo( projectName, properties, true );
return executeMojo( projectName, properties, true, true );
}

/**
* Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid
*
*
* @param projectName the project to test
* @param earModuleName the name of 1st level EAR module in multi-module project or null if project is single-module
* @param expectedArtifacts the list of artifacts to be found in the EAR archive
* @param artifactsDirectory whether the artifact is an exploded artifactsDirectory or not
* @param cleanBeforeExecute call clean plugin before execution
* @return the base directory of the project
*/
protected File doTestProject( final String projectName, final String[] expectedArtifacts,
final boolean[] artifactsDirectory )
protected File doTestProject( final String projectName, final String earModuleName, final String[] expectedArtifacts,
final boolean[] artifactsDirectory, boolean cleanBeforeExecute )
throws VerificationException, IOException
{
final File baseDir = executeMojo( projectName, new Properties() );
assertEarArchive( baseDir, projectName );
assertEarDirectory( baseDir, projectName );

assertArchiveContent( baseDir, projectName, expectedArtifacts, artifactsDirectory );

assertDeploymentDescriptors( baseDir, projectName );

final File baseDir = executeMojo( projectName, new Properties(), true, cleanBeforeExecute );
final File earDir = earModuleName == null ? baseDir : new File( baseDir, earModuleName );
assertEarArchive( earDir, projectName );
assertEarDirectory( earDir, projectName );

assertArchiveContent( earDir, projectName, expectedArtifacts, artifactsDirectory );

assertDeploymentDescriptors( earDir, projectName );

return baseDir;
}

/**
* Executes the specified projects and asserts the given artifacts. Assert the deployment descriptors are valid
*
* @param projectName the project to test
* @param expectedArtifacts the list of artifacts to be found in the EAR archive
* @param artifactsDirectory whether the artifact is an exploded artifactsDirectory or not
* @return the base directory of the project
*/
protected File doTestProject( final String projectName, final String[] expectedArtifacts,
final boolean[] artifactsDirectory )
throws VerificationException, IOException
{
return doTestProject( projectName, null, expectedArtifacts, artifactsDirectory, true );
}

/**
Expand Down
22 changes: 21 additions & 1 deletion src/test/java/org/apache/maven/plugins/ear/it/EarMojoIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ public void testProject025()
public void testProject026()
throws Exception
{
final File baseDir = executeMojo( "project-026", new Properties(), false );
final File baseDir = executeMojo( "project-026", new Properties(), false, true );
// Stupido, checks that the ear archive is not there
assertFalse( "Execution should have failed", getEarArchive( baseDir, "project-026" ).exists() );
}
Expand Down Expand Up @@ -993,4 +993,24 @@ public void testProject087()
{
doTestProject( "project-087", new String[] { "eartest-ejb-sample-one-1.0.jar", "eartest-ejb-sample-two-1.0.jar" } );
}

/**
* Builds WAR and EAR as part of multi-module project twice so that the 2nd build is guaranteed to be performed when
* target directories and files exist.
* @throws Exception in case of an error.
*/
public void testProject088()
throws Exception
{
final String[] expectedArtifacts = {
"eartest-war-sample-two-1.0.war",
"eartest-ejb-sample-one-1.0.jar",
"lib/eartest-jar-sample-two-1.0.jar" };
final boolean[] artifactsDirectory = { false, true, false };
// "Clean" build - target directories and files do not exist
// Pass cleanBeforeExecute parameter to ensure that target location is cleaned before Mojo execution
doTestProject( "project-088", "ear", expectedArtifacts, artifactsDirectory, true );
// "Dirty" build - target directories and files exist
doTestProject( "project-088", "ear", expectedArtifacts, artifactsDirectory, false );
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>maven-ear-plugin-test-project-088</display-name>
<module>
<web>
<web-uri>eartest-war-sample-two-1.0.war</web-uri>
<context-root>/war-sample-two</context-root>
</web>
</module>
<module>
<ejb>eartest-ejb-sample-one-1.0.jar</ejb>
</module>
<library-directory>lib</library-directory>
</application>
62 changes: 62 additions & 0 deletions src/test/resources/projects/project-088/ear/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ear</groupId>
<artifactId>maven-ear-plugin-test-project-088-parent</artifactId>
<version>99.0</version>
</parent>
<artifactId>maven-ear-plugin-test-project-088</artifactId>
<packaging>ear</packaging>
<dependencies>
<dependency>
<groupId>eartest</groupId>
<artifactId>jar-sample-two</artifactId>
</dependency>
<dependency>
<groupId>eartest</groupId>
<artifactId>war-sample-two</artifactId>
<type>war</type>
</dependency>
<dependency>
<groupId>eartest</groupId>
<artifactId>ejb-sample-one</artifactId>
<type>ejb</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<version>6</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<skinnyWars>true</skinnyWars>
<unpackTypes>ejb</unpackTypes>
</configuration>
</plugin>
</plugins>
</build>
</project>
64 changes: 64 additions & 0 deletions src/test/resources/projects/project-088/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ear</groupId>
<artifactId>maven-ear-plugin-test-project-088-parent</artifactId>
<version>99.0</version>
<packaging>pom</packaging>
<modules>
<module>war</module>
<module>ear</module>
</modules>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>eartest</groupId>
<artifactId>jar-sample-two</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>eartest</groupId>
<artifactId>war-sample-two</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>eartest</groupId>
<artifactId>ejb-sample-one</artifactId>
<version>1.0</version>
<type>ejb</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>@mavenWarPluginVersion@</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
39 changes: 39 additions & 0 deletions src/test/resources/projects/project-088/war/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>ear</groupId>
<artifactId>maven-ear-plugin-test-project-088-parent</artifactId>
<version>99.0</version>
</parent>
<groupId>eartest</groupId>
<artifactId>war-sample-two</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>eartest</groupId>
<artifactId>jar-sample-two</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
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.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>

0 comments on commit 5bcdf4c

Please sign in to comment.