1   package org.apache.maven.plugin.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 org.apache.maven.plugin.ear.AbstractEarTest;
23  
24  /**
25   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
26   * @version $Id: ArtifactRepositoryTest.java 768494 2009-04-25 07:55:50Z snicoll $
27   */
28  public class ArtifactRepositoryTest
29      extends AbstractEarTest
30  {
31  
32  
33      protected void setUp()
34          throws Exception
35      {
36          super.setUp();
37          ArtifactTypeMappingService.getInstance().configure( null );
38      }
39  
40  
41      public static final String MAIN_ARTIFACT_ID = "none";
42  
43      public void testEmptyRepository()
44      {
45          ArtifactRepository repo = new ArtifactRepository( createArtifacts( null ), MAIN_ARTIFACT_ID );
46          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar" ) );
47          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", null ) );
48          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", "class" ) );
49      }
50  
51      public void testRepositoryWithOneUnclassifiedArtifact()
52      {
53          ArtifactRepository repo =
54              new ArtifactRepository( createArtifacts( new String[]{"myartifact"} ), MAIN_ARTIFACT_ID );
55          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
56          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", null ) );
57      }
58  
59      public void testRepositoryWithOneClassifiedArtifact()
60      {
61          ArtifactRepository repo = new ArtifactRepository(
62              createArtifacts( new String[]{"myartifact"}, null, null, new String[]{"classified"} ), MAIN_ARTIFACT_ID );
63          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
64          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "classified" ) );
65          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
66      }
67  
68      public void testRepositoryWithMultipleClassifiedArtifacts()
69      {
70          ArtifactRepository repo = new ArtifactRepository(
71              createArtifacts( new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
72                               new String[]{"class1", "class2", "class3"} ), MAIN_ARTIFACT_ID );
73  
74          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
75          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );
76          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class2" ) );
77          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class3" ) );
78          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
79      }
80  
81      public void testRepositoryWithMultipleClassifiedArtifactsAndMainArtifact()
82      {
83          ArtifactRepository repo = new ArtifactRepository(
84              createArtifacts( new String[]{"myartifact", "myartifact", "myartifact"}, null, null,
85                               new String[]{"class1", "class2", null} ), MAIN_ARTIFACT_ID );
86  
87          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
88          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class1" ) );
89          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "class2" ) );
90          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", MAIN_ARTIFACT_ID ) );
91          assertNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", "wrong" ) );
92      }
93  }