Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactTestStub.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactTestStub.java?rev=1755643&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactTestStub.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/stub/ArtifactTestStub.java Tue Aug 9 19:17:58 2016 @@ -0,0 +1,358 @@ +package org.apache.maven.plugins.ear.stub; + +/* + * 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. + */ + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.handler.ArtifactHandler; +import org.apache.maven.artifact.metadata.ArtifactMetadata; +import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.artifact.resolver.filter.ArtifactFilter; +import org.apache.maven.artifact.versioning.ArtifactVersion; +import org.apache.maven.artifact.versioning.OverConstrainedVersionException; +import org.apache.maven.artifact.versioning.VersionRange; + +import java.io.File; +import java.util.Collection; +import java.util.List; + +/** + * A fake {@link Artifact} test stub. + * + * @author <a href="[email protected]">Stephane Nicoll</a> + * @version $Id: ArtifactTestStub.java 1755538 2016-08-08 20:32:12Z rfscholte $ + */ +public class ArtifactTestStub + implements Artifact + +{ + public static final String DEFAULT_VERSION = "1.0"; + + private final String groupId; + + private final String artifactId; + + private final String type; + + private final String classifier; + + private String version; + + public ArtifactTestStub( String groupId, String artifactId, String type, String classifier, String version ) + { + this.groupId = groupId; + this.artifactId = artifactId; + this.type = type; + this.classifier = classifier; + this.version = version; + } + + public ArtifactTestStub( String groupId, String artifactId, String type, String classifier ) + { + this( groupId, artifactId, type, classifier, DEFAULT_VERSION ); + } + + public String getGroupId() + { + return groupId; + } + + public String getArtifactId() + { + return artifactId; + } + + public String getVersion() + { + return version; + } + + public void setVersion( String version ) + { + this.version = version; + } + + public String getScope() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getType() + { + return type; + } + + public String getClassifier() + { + return classifier; + } + + public boolean hasClassifier() + { + return classifier != null; + } + + public File getFile() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setFile( File file ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getBaseVersion() + { + return version; + } + + public void setBaseVersion( String string ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getId() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getDependencyConflictId() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void addMetadata( ArtifactMetadata artifactMetadata ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public Collection<ArtifactMetadata> getMetadataList() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setRepository( ArtifactRepository artifactRepository ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public ArtifactRepository getRepository() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void updateVersion( String string, ArtifactRepository artifactRepository ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public String getDownloadUrl() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setDownloadUrl( String string ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public ArtifactFilter getDependencyFilter() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setDependencyFilter( ArtifactFilter artifactFilter ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public ArtifactHandler getArtifactHandler() + { + return new ArtifactHandlerTestStub( "jar" ); + } + + public List<String> getDependencyTrail() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setDependencyTrail( List<String> list ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setScope( String string ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public VersionRange getVersionRange() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setVersionRange( VersionRange versionRange ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void selectVersion( String string ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setGroupId( String string ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setArtifactId( String string ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean isSnapshot() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setResolved( boolean b ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean isResolved() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setResolvedVersion( String string ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setArtifactHandler( ArtifactHandler artifactHandler ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean isRelease() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setRelease( boolean b ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public List<ArtifactVersion> getAvailableVersions() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setAvailableVersions( List<ArtifactVersion> list ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean isOptional() + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public void setOptional( boolean b ) + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public ArtifactVersion getSelectedVersion() + throws OverConstrainedVersionException + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean isSelectedVersionKnown() + throws OverConstrainedVersionException + { + throw new UnsupportedOperationException( "not implemented ; fake artifact stub" ); + } + + public boolean equals( Object o ) + { + if ( this == o ) + { + return true; + } + if ( o == null || getClass() != o.getClass() ) + { + return false; + } + + ArtifactTestStub that = (ArtifactTestStub) o; + + if ( artifactId != null ? !artifactId.equals( that.artifactId ) : that.artifactId != null ) + { + return false; + } + if ( classifier != null ? !classifier.equals( that.classifier ) : that.classifier != null ) + { + return false; + } + if ( groupId != null ? !groupId.equals( that.groupId ) : that.groupId != null ) + { + return false; + } + if ( type != null ? !type.equals( that.type ) : that.type != null ) + { + return false; + } + + return true; + } + + public int hashCode() + { + int result; + result = ( groupId != null ? groupId.hashCode() : 0 ); + result = 31 * result + ( artifactId != null ? artifactId.hashCode() : 0 ); + result = 31 * result + ( type != null ? type.hashCode() : 0 ); + result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 ); + return result; + } + + public int compareTo( Artifact o ) + { + if ( this.equals( o ) ) + { + return 0; + } + else + { + return 1; + } + } + + public ArtifactMetadata getMetadata( Class<?> metadataClass ) + { + // TODO Auto-generated method stub + return null; + } +}
Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java?rev=1755643&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactRepositoryTest.java Tue Aug 9 19:17:58 2016 @@ -0,0 +1,109 @@ +package org.apache.maven.plugins.ear.util; + +/* + * 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. + */ + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +import org.apache.maven.plugins.ear.AbstractEarTestBase; +import org.apache.maven.plugins.ear.EarPluginException; +import org.apache.maven.plugins.ear.util.ArtifactRepository; +import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService; +import org.codehaus.plexus.configuration.PlexusConfigurationException; +import org.junit.Test; + +/** + * @author <a href="[email protected]">Stephane Nicoll</a> + * @version $Id: ArtifactRepositoryTest.java 1648192 2014-12-28 12:39:04Z khmarbaise $ + */ +public class ArtifactRepositoryTest + extends AbstractEarTestBase +{ + + public static final String MAIN_ARTIFACT_ID = "none"; + + @Test + public void testEmptyRepository() + { + ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService(); + ArtifactRepository repo = + new ArtifactRepository( createArtifacts( null ), MAIN_ARTIFACT_ID, artifactTypeMappingService ); + assertNull( repo.getUniqueArtifact( "ear", "ar", "jar" ) ); + assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", null ) ); + assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", "class" ) ); + } + + @Test + public void testRepositoryWithOneUnclassifiedArtifact() + { + ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService(); + ArtifactRepository repo = + new ArtifactRepository( createArtifacts( new String[] { "myartifact" } ), MAIN_ARTIFACT_ID, + artifactTypeMappingService ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", null ) ); + } + + @Test + public void testRepositoryWithOneClassifiedArtifact() + { + ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService(); + ArtifactRepository repo = + new ArtifactRepository( createArtifacts( new String[] { "myartifact" }, null, null, + new String[] { "classified" } ), MAIN_ARTIFACT_ID, + artifactTypeMappingService ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "classified" ) ); + assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) ); + } + + @Test + public void testRepositoryWithMultipleClassifiedArtifacts() + { + ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService(); + ArtifactRepository repo = + new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" }, null, + null, new String[] { "class1", "class2", "class3" } ), + MAIN_ARTIFACT_ID, artifactTypeMappingService ); + + assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class2" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class3" ) ); + assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) ); + } + + @Test + public void testRepositoryWithMultipleClassifiedArtifactsAndMainArtifact() + throws PlexusConfigurationException, EarPluginException + { + ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService(); + ArtifactRepository repo = + new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" }, null, + null, new String[] { "class1", "class2", null } ), + MAIN_ARTIFACT_ID, artifactTypeMappingService ); + + assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class2" ) ); + assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", MAIN_ARTIFACT_ID ) ); + assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) ); + } +} Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactTypeMappingServiceTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactTypeMappingServiceTest.java?rev=1755643&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactTypeMappingServiceTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ArtifactTypeMappingServiceTest.java Tue Aug 9 19:17:58 2016 @@ -0,0 +1,250 @@ +package org.apache.maven.plugins.ear.util; + +/* + * 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. + */ + +import junit.framework.TestCase; + +import org.apache.maven.plugins.ear.EarModuleFactory; +import org.apache.maven.plugins.ear.EarPluginException; +import org.apache.maven.plugins.ear.UnknownArtifactTypeException; +import org.apache.maven.plugins.ear.util.ArtifactTypeMappingService; +import org.codehaus.plexus.configuration.PlexusConfigurationException; +import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; + +/** + * Tests for the {@link ArtifactTypeMappingService} + * + * @author <a href="[email protected]">Stephane Nicoll</a> + * @version $Id: ArtifactTypeMappingServiceTest.java 1542508 2013-11-16 13:21:35Z rfscholte $ + */ +public class ArtifactTypeMappingServiceTest + extends TestCase +{ + + public void testDefaultConfiguration() + { + ArtifactTypeMappingService service = getDefaultService(); + for ( String type : EarModuleFactory.getStandardArtifactTypes() ) + { + assertTrue( "Standard type could not be found", service.isMappedToType( type, type ) ); + } + } + + public void testIsMappedToTypeForUnknownType() + { + ArtifactTypeMappingService service = getDefaultService(); + assertFalse( service.isMappedToType( "rar", "MyKoolCustomType" ) ); + } + + public void testIsMappedToTypeForKnownType() + { + ArtifactTypeMappingService service = getServiceWithRarMappingToMyRar(); + assertTrue( service.isMappedToType( "rar", "MyRar" ) ); + } + + public void testGetStandardTypeForUknonwnType() + { + try + { + ArtifactTypeMappingService service = getDefaultService(); + service.getStandardType( "MyKoolCustomType" ); + fail( "Should have failed to retrieve a unknwon custom type" ); + } + catch ( UnknownArtifactTypeException e ) + { + // That's good + } + } + + public void testGetStandardTypeForKnownType() + { + try + { + ArtifactTypeMappingService service = getServiceWithRarMappingToMyRar(); + assertEquals( "rar", service.getStandardType( "MyRar" ) ); + } + catch ( UnknownArtifactTypeException e ) + { + fail( "Should not have failed to retrieve a knwon custom type " + e.getMessage() ); + } + } + + public void testConfigWithSameCustomType() + { + try + { + XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration( "dummy" ); + XmlPlexusConfiguration childConfig = + new XmlPlexusConfiguration( ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT ); + childConfig.setAttribute( "type", "generic" ); + childConfig.setAttribute( "mapping", "rar" ); + XmlPlexusConfiguration childConfig2 = + new XmlPlexusConfiguration( ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT ); + childConfig.setAttribute( "type", "generic" ); + childConfig.setAttribute( "mapping", "ejb" ); + + rootConfig.addChild( childConfig ); + rootConfig.addChild( childConfig2 ); + ArtifactTypeMappingService service = new ArtifactTypeMappingService(); + service.configure( rootConfig ); + fail( "Should have failed" ); + } + catch ( EarPluginException e ) + { + // OK + } + catch ( PlexusConfigurationException e ) + { + e.printStackTrace(); + fail( "Unexpected " + e.getMessage() ); + } + } + + public void testConfigWithUnknownStandardType() + { + try + { + XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration( "dummy" ); + XmlPlexusConfiguration childConfig = + new XmlPlexusConfiguration( ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT ); + childConfig.setAttribute( "type", "generic" ); + childConfig.setAttribute( "mapping", "notAStandardType" ); + + rootConfig.addChild( childConfig ); + ArtifactTypeMappingService service = new ArtifactTypeMappingService(); + service.configure( rootConfig ); + fail( "Should have failed" ); + } + catch ( EarPluginException e ) + { + // OK + } + catch ( PlexusConfigurationException e ) + { + e.printStackTrace(); + fail( "Unexpected " + e.getMessage() ); + } + } + + public void testConfigWithNoType() + { + try + { + XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration( "dummy" ); + XmlPlexusConfiguration childConfig = + new XmlPlexusConfiguration( ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT ); + childConfig.setAttribute( "mapping", "ejb" ); + + rootConfig.addChild( childConfig ); + ArtifactTypeMappingService service = new ArtifactTypeMappingService(); + service.configure( rootConfig ); + fail( "Should have failed" ); + } + catch ( EarPluginException e ) + { + // OK + } + catch ( PlexusConfigurationException e ) + { + e.printStackTrace(); + fail( "Unexpected " + e.getMessage() ); + } + } + + public void testConfigWithNoMapping() + { + try + { + XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration( "dummy" ); + XmlPlexusConfiguration childConfig = + new XmlPlexusConfiguration( ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT ); + childConfig.setAttribute( "type", "generic" ); + + rootConfig.addChild( childConfig ); + ArtifactTypeMappingService service = new ArtifactTypeMappingService(); + service.configure( rootConfig ); + fail( "Should have failed" ); + } + catch ( EarPluginException e ) + { + // OK + } + catch ( PlexusConfigurationException e ) + { + e.printStackTrace(); + fail( "Unexpected " + e.getMessage() ); + } + } + + // Utilities + + protected ArtifactTypeMappingService getServiceWithRarMappingToMyRar() + { + try + { + XmlPlexusConfiguration rootConfig = new XmlPlexusConfiguration( "artifact-type-mappings" ); + XmlPlexusConfiguration childConfig = + new XmlPlexusConfiguration( ArtifactTypeMappingService.ARTIFACT_TYPE_MAPPING_ELEMENT ); + childConfig.setAttribute( "type", "MyRar" ); + childConfig.setAttribute( "mapping", "rar" ); + rootConfig.addChild( childConfig ); + ArtifactTypeMappingService service = new ArtifactTypeMappingService(); + service.configure( rootConfig ); + + return service; + } + catch ( EarPluginException e ) + { + e.printStackTrace(); + fail( e.getMessage() ); + } + catch ( PlexusConfigurationException e ) + { + e.printStackTrace(); + fail( e.getMessage() ); + } + // Won't occur + return null; + + } + + protected ArtifactTypeMappingService getDefaultService() + { + try + { + ArtifactTypeMappingService service = new ArtifactTypeMappingService(); + service.configure( new XmlPlexusConfiguration( "dummy" ) ); + + return service; + } + catch ( EarPluginException e ) + { + e.printStackTrace(); + fail( e.getMessage() ); + } + catch ( PlexusConfigurationException e ) + { + e.printStackTrace(); + fail( e.getMessage() ); + } + // Won't occur + return null; + } +} Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java?rev=1755643&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/EarMavenArchiverTest.java Tue Aug 9 19:17:58 2016 @@ -0,0 +1,83 @@ +package org.apache.maven.plugins.ear.util; + +import static org.junit.Assert.assertEquals; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.maven.plugins.ear.AbstractEarTestBase; +import org.apache.maven.plugins.ear.EarModule; +import org.apache.maven.plugins.ear.EjbModule; +import org.apache.maven.plugins.ear.util.EarMavenArchiver; +import org.junit.Test; + +/* + * 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. + */ + +/** + * @author <a href="[email protected]">Stephane Nicoll</a> + */ +public class EarMavenArchiverTest + extends AbstractEarTestBase +{ + + @Test + public void testSimpleEjbModule() + { + final List<EarModule> modules = new ArrayList<EarModule>(); + final EarModule module = new EjbModule( createArtifact( "foo", "ejb" ) ); + setUri( module, "foo-1.0.jar" ); + modules.add( module ); + + final EarMavenArchiver archiver = new EarMavenArchiver( modules ); + assertEquals( "foo-1.0.jar", archiver.generateClassPathEntry( "" ) ); + + } + + @Test + public void testSimpleJarModuleWithCustomBundleDir() + { + final List<EarModule> modules = new ArrayList<EarModule>(); + final EarModule module = new EjbModule( createArtifact( "foo", "jar" ) ); + setUri( module, "libs/foo-1.0.jar" ); + modules.add( module ); + + final EarMavenArchiver archiver = new EarMavenArchiver( modules ); + assertEquals( "libs/foo-1.0.jar", archiver.generateClassPathEntry( "" ) ); + + } + + @Test + public void testTwoModules() + { + final List<EarModule> modules = new ArrayList<EarModule>(); + final EarModule module = new EjbModule( createArtifact( "foo", "ejb" ) ); + setUri( module, "foo-1.0.jar" ); + modules.add( module ); + + final EarModule module2 = new EjbModule( createArtifact( "bar", "war" ) ); + setUri( module2, "bar-2.0.1.war" ); + modules.add( module2 ); + + final EarMavenArchiver archiver = new EarMavenArchiver( modules ); + assertEquals( "foo-1.0.jar bar-2.0.1.war", archiver.generateClassPathEntry( "" ) ); + + } + +} \ No newline at end of file Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/JavaEEVersionTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/JavaEEVersionTest.java?rev=1755643&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/JavaEEVersionTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/JavaEEVersionTest.java Tue Aug 9 19:17:58 2016 @@ -0,0 +1,152 @@ +package org.apache.maven.plugins.ear.util; + +import org.apache.maven.plugins.ear.util.InvalidJavaEEVersion; +import org.apache.maven.plugins.ear.util.JavaEEVersion; + +/* + * 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. + */ + +import junit.framework.TestCase; + +/** + * @author Stephane Nicoll + */ +public class JavaEEVersionTest + extends TestCase +{ + + public void testGtSameVersion() + { + assertFalse( JavaEEVersion.FIVE.gt( JavaEEVersion.FIVE ) ); + } + + public void testGtNextVersion() + { + assertFalse( JavaEEVersion.FIVE.gt( JavaEEVersion.SIX ) ); + } + + public void testGtPreviousVersion() + { + assertTrue( JavaEEVersion.FIVE.gt( JavaEEVersion.ONE_DOT_FOUR ) ); + } + + public void testGeSameVersion() + { + assertTrue( JavaEEVersion.FIVE.ge( JavaEEVersion.FIVE ) ); + } + + public void testGePreviousVersion() + { + assertTrue( JavaEEVersion.FIVE.ge( JavaEEVersion.ONE_DOT_FOUR ) ); + } + + public void testGeNextVersion() + { + assertFalse( JavaEEVersion.FIVE.ge( JavaEEVersion.SIX ) ); + } + + public void testLtSameVersion() + { + assertFalse( JavaEEVersion.FIVE.lt( JavaEEVersion.FIVE ) ); + } + + public void testLtPreviousVersion() + { + assertFalse( JavaEEVersion.FIVE.lt( JavaEEVersion.ONE_DOT_FOUR ) ); + } + + public void testLtNextVersion() + { + assertTrue( JavaEEVersion.FIVE.lt( JavaEEVersion.SIX ) ); + } + + public void testLeSameVersion() + { + assertTrue( JavaEEVersion.FIVE.le( JavaEEVersion.FIVE ) ); + } + + public void testLePreviousVersion() + { + assertFalse( JavaEEVersion.FIVE.le( JavaEEVersion.ONE_DOT_FOUR ) ); + } + + public void testLeNextVersion() + { + assertTrue( JavaEEVersion.FIVE.le( JavaEEVersion.SIX ) ); + } + + public void testEqSameVersion() + { + assertTrue( JavaEEVersion.FIVE.eq( JavaEEVersion.FIVE ) ); + } + + public void testEqAnotherVersion() + { + assertFalse( JavaEEVersion.FIVE.eq( JavaEEVersion.ONE_DOT_THREE ) ); + } + + public void testGetVersion() + { + assertEquals( "5", JavaEEVersion.FIVE.getVersion() ); + } + + public void testGetJavaEEVersionValid() + { + try + { + assertEquals( JavaEEVersion.SIX, JavaEEVersion.getJavaEEVersion( "6" ) ); + } + catch ( InvalidJavaEEVersion invalidJavaEEVersion ) + { + fail( "No exception should have been thrown but got [" + invalidJavaEEVersion.getMessage() + "]" ); + } + } + + public void testGetJavaEEVersionInvalid() + { + try + { + JavaEEVersion.getJavaEEVersion( "2.4" ); + fail( "Should have failed to get an invalid version." ); + } + catch ( InvalidJavaEEVersion e ) + { + // OK + } + } + + public void testGetJavaEEVersionNull() + { + try + { + JavaEEVersion.getJavaEEVersion( null ); + fail( "Should have failed to get a 'null' version." ); + } + catch ( InvalidJavaEEVersion e ) + { + fail( "Should have failed with an illegal argument exception instead." ); + } + catch ( IllegalArgumentException e ) + { + // OK + } + + } + +} Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ModuleIdentifierValidatorTest.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ModuleIdentifierValidatorTest.java?rev=1755643&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ModuleIdentifierValidatorTest.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ModuleIdentifierValidatorTest.java Tue Aug 9 19:17:58 2016 @@ -0,0 +1,211 @@ +package org.apache.maven.plugins.ear.util; + +/* + * 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. + */ + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.apache.maven.artifact.Artifact; +import org.apache.maven.plugins.ear.EarModule; +import org.apache.maven.plugins.ear.util.ModuleIdentifierValidator; +import org.junit.Before; +import org.junit.Test; + +public class ModuleIdentifierValidatorTest +{ + private List<EarModule> earModules; + + private ModuleIdentifierValidator miv; + + @Before + public void before() + { + this.earModules = new ArrayList<EarModule>(); + this.miv = new ModuleIdentifierValidator( this.earModules ); + } + + private EarModule createMockEarModule( String groupId, String artifactId, String version ) + { + EarModule earModule = mock( EarModule.class ); + Artifact artifact = mock( Artifact.class ); + when( earModule.getArtifact() ).thenReturn( artifact ); + when( earModule.getArtifact().getGroupId() ).thenReturn( groupId ); + when( earModule.getArtifact().getArtifactId() ).thenReturn( artifactId ); + when( earModule.getArtifact().getVersion() ).thenReturn( version ); + when( earModule.getArtifact().getId() ).thenReturn( groupId + ":" + artifactId + ":" + version ); + return earModule; + } + + private EarModule createMockEarModule( String groupId, String artifactId, String classifier, String version ) + { + EarModule earModule = mock( EarModule.class ); + Artifact artifact = mock( Artifact.class ); + when( earModule.getArtifact() ).thenReturn( artifact ); + when( earModule.getArtifact().getGroupId() ).thenReturn( groupId ); + when( earModule.getArtifact().getArtifactId() ).thenReturn( artifactId ); + when( earModule.getArtifact().getClassifier() ).thenReturn( classifier ); + when( earModule.getArtifact().getVersion() ).thenReturn( version ); + when( earModule.getArtifact().getId() ).thenReturn( groupId + ":" + artifactId + ":" + classifier + ":" + version ); + return earModule; + } + + @Test + public void existDuplicateShouldResultFalseWithEmptyList() + { + miv.checkForDuplicateArtifacts(); + + assertFalse( miv.existDuplicateArtifacts() ); + } + + @Test + public void shouldNotFailCauseTheArtifactIdsAreDifferentWithSameGroupId() + { + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-a", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-b", "1.0.0" ) ); + + assertFalse( miv.checkForDuplicateArtifacts().existDuplicateArtifacts() ); + + Map<String, List<EarModule>> result = miv.getDuplicateArtifacts(); + + assertTrue( result.isEmpty() ); + } + + @Test + public void shouldNotFailCauseTheArtifactIdsAreDifferent() + { + earModules.add( createMockEarModule( "org.apache", "artifact-1", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache", "artifact-2", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven", "aid-1", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven", "aid-2", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-a", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-b", "1.0.0" ) ); + + assertFalse( miv.checkForDuplicateArtifacts().existDuplicateArtifacts() ); + + Map<String, List<EarModule>> result = miv.getDuplicateArtifacts(); + + assertTrue( result.isEmpty() ); + } + + @Test + public void shouldNotFailCauseTheClassifiersAreDifferent() + { + earModules.add( createMockEarModule( "org.apache", "artifact-1", "first", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache", "artifact-2", "second", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven", "aid-1", "first", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven", "aid-2", "second", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-a", "first", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-b", "second", "1.0.0" ) ); + + assertFalse( miv.checkForDuplicateArtifacts().existDuplicateArtifacts() ); + + Map<String, List<EarModule>> result = miv.getDuplicateArtifacts(); + + assertTrue( result.isEmpty() ); + } + + @Test + public void shouldFailCauseTheArtifactIdsAreIdenticalWithDifferentGroupIds() + { + EarModule earModule1 = createMockEarModule( "org.apache.maven.test", "result-artifact", "1.0.0" ); + EarModule earModule2 = createMockEarModule( "org.apache.maven", "result-artifact", "1.0.0" ); + earModules.add( earModule1 ); + earModules.add( earModule2 ); + + miv.checkForDuplicateArtifacts(); + Map<String, List<EarModule>> result = miv.getDuplicateArtifacts(); + + assertFalse( result.isEmpty() ); + assertEquals( 1, result.size() ); + assertTrue( result.containsKey( "result-artifact:1.0.0" ) ); + assertEquals( 2, result.get( "result-artifact:1.0.0" ).size() ); + } + + @Test + public void shouldFailCauseTheArtifactIdsAreIdenticalWithClassifiers() + { + EarModule earModule1 = createMockEarModule( "org.apache.maven.test", "result-artifact", "first", "1.0.0" ); + EarModule earModule2 = createMockEarModule( "org.apache.maven", "result-artifact", "second", "1.0.0" ); + earModules.add( earModule1 ); + earModules.add( earModule2 ); + + miv.checkForDuplicateArtifacts(); + Map<String, List<EarModule>> result = miv.getDuplicateArtifacts(); + + assertFalse( result.isEmpty() ); + assertEquals( 1, result.size() ); + assertTrue( result.containsKey( "result-artifact:1.0.0" ) ); + assertEquals( 2, result.get( "result-artifact:1.0.0" ).size() ); + } + + @Test + public void shouldFailCauseTheArtifactIdsAreIdentical() + { + earModules.add( createMockEarModule( "org.apache", "artifact-1", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache", "artifact-2", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven", "aid-1", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven", "artifact-2", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-a", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-b", "1.0.0" ) ); + + miv.checkForDuplicateArtifacts(); + Map<String, List<EarModule>> result = miv.getDuplicateArtifacts(); + + assertFalse( result.isEmpty() ); + } + + @Test + public void shouldFailWithAppropriateInformationAboutTheIdenticalArtifactIds() + { + EarModule earModule_1 = createMockEarModule( "org.apache", "artifact-2", "1.0.0" ); + EarModule earModule_2 = createMockEarModule( "org.apache.maven", "artifact-2", "1.0.0" ); + + earModules.add( createMockEarModule( "org.apache", "artifact-1", "1.0.0" ) ); + earModules.add( earModule_1 ); + earModules.add( createMockEarModule( "org.apache.maven", "aid-1", "1.0.0" ) ); + earModules.add( earModule_2 ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-a", "1.0.0" ) ); + earModules.add( createMockEarModule( "org.apache.maven.test", "result-artifact-b", "1.0.0" ) ); + + miv.checkForDuplicateArtifacts(); + Map<String, List<EarModule>> result = miv.getDuplicateArtifacts(); + + assertFalse( result.isEmpty() ); + assertEquals( 1, result.size() ); + + assertTrue( result.containsKey( "artifact-2:1.0.0" ) ); + + List<EarModule> list = result.get( "artifact-2:1.0.0" ); + + assertEquals( 2, list.size() ); + assertTrue( list.contains( earModule_1 ) ); + assertTrue( list.contains( earModule_2 ) ); + + } + +} Added: maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ResourceEntityResolver.java URL: http://svn.apache.org/viewvc/maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ResourceEntityResolver.java?rev=1755643&view=auto ============================================================================== --- maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ResourceEntityResolver.java (added) +++ maven/plugins/trunk/maven-ear-plugin/src/test/java/org/apache/maven/plugins/ear/util/ResourceEntityResolver.java Tue Aug 9 19:17:58 2016 @@ -0,0 +1,37 @@ +package org.apache.maven.plugins.ear.util; + +/* + * Licensed 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. + */ + +import java.io.InputStream; +import org.xml.sax.EntityResolver; +import org.xml.sax.InputSource; + +public class ResourceEntityResolver + implements EntityResolver +{ + public InputSource resolveEntity( String publicId, String systemId ) + { + String dtd = "/dtd" + systemId.substring( systemId.lastIndexOf( '/' ) ); + InputStream in = ResourceEntityResolver.class.getResourceAsStream( dtd ); + if ( in == null ) + { + throw new RuntimeException( "unable to load DTD " + dtd + " for " + systemId ); + } + else + { + return new InputSource( in ); + } + } +}
