View Javadoc
1   package org.apache.maven.plugins.ear.util;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.assertNotNull;
23  import static org.junit.Assert.assertNull;
24  
25  import java.util.HashSet;
26  import java.util.Set;
27  
28  import org.apache.maven.artifact.Artifact;
29  import org.apache.maven.plugins.ear.AbstractEarTestBase;
30  import org.junit.Test;
31  
32  /**
33   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
34   */
35  public class ArtifactRepositoryTest
36      extends AbstractEarTestBase
37  {
38  
39      private static final String MAIN_ARTIFACT_ID = "none";
40  
41      private ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
42  
43      @Test
44      public void testEmptyRepository()
45      {
46          Set<Artifact> artifacts = new HashSet<>();
47          ArtifactRepository repo = new ArtifactRepository( artifacts, MAIN_ARTIFACT_ID, artifactTypeMappingService );
48          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar" ) );
49          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", null ) );
50          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", "class" ) );
51      }
52  
53      @Test
54      public void testRepositoryWithOneUnclassifiedArtifact()
55      {
56          ArtifactRepository repo =
57              new ArtifactRepository( createArtifacts( new String[] { "myartifact" } ), MAIN_ARTIFACT_ID,
58                                      artifactTypeMappingService );
59          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
60          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", null ) );
61      }
62  
63      @Test
64      public void testRepositoryWithOneClassifiedArtifact()
65      {
66          ArtifactRepository repo =
67              new ArtifactRepository( createArtifacts( new String[] { "myartifact" },
68                                                       new String[] { "classified" } ), MAIN_ARTIFACT_ID,
69                                      artifactTypeMappingService );
70          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
71          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "classified" ) );
72          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
73      }
74  
75      @Test
76      public void testRepositoryWithMultipleClassifiedArtifacts()
77      {
78          ArtifactRepository repo =
79              new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" }, 
80                                                       new String[] { "class1", "class2", "class3" } ),
81                                      MAIN_ARTIFACT_ID, artifactTypeMappingService );
82  
83          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
84          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );
85          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class2" ) );
86          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class3" ) );
87          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
88      }
89  
90      @Test
91      public void testRepositoryWithMultipleClassifiedArtifactsAndMainArtifact()
92      {
93          ArtifactRepository repo =
94              new ArtifactRepository( createArtifacts( new String[] { "myartifact", "myartifact", "myartifact" },
95                                                       new String[] { "class1", "class2", null } ),
96                                      MAIN_ARTIFACT_ID, artifactTypeMappingService );
97  
98          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
99          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );
100         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class2" ) );
101         assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", MAIN_ARTIFACT_ID ) );
102         assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
103     }
104 }