View Javadoc

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  import org.apache.maven.plugin.ear.EarPluginException;
24  import org.codehaus.plexus.configuration.PlexusConfigurationException;
25  
26  /**
27   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
28   * @version $Id: ArtifactRepositoryTest.java 992370 2010-09-03 16:48:59Z snicoll $
29   */
30  public class ArtifactRepositoryTest
31      extends AbstractEarTest
32  {
33  
34  
35      protected void setUp()
36          throws Exception
37      {
38          super.setUp();
39      }
40  
41  
42      public static final String MAIN_ARTIFACT_ID = "none";
43  
44      public void testEmptyRepository()
45      {
46          ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
47          ArtifactRepository repo =
48              new ArtifactRepository( createArtifacts( null ), MAIN_ARTIFACT_ID, artifactTypeMappingService );
49          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar" ) );
50          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", null ) );
51          assertNull( repo.getUniqueArtifact( "ear", "ar", "jar", "class" ) );
52      }
53  
54      public void testRepositoryWithOneUnclassifiedArtifact()
55      {
56          ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
57          ArtifactRepository repo =
58              new ArtifactRepository( createArtifacts( new String[]{ "myartifact" } ), MAIN_ARTIFACT_ID,
59                                      artifactTypeMappingService );
60          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar" ) );
61          assertNotNull( repo.getUniqueArtifact( DEFAULT_GROUPID, "myartifact", "jar", null ) );
62      }
63  
64      public void testRepositoryWithOneClassifiedArtifact()
65      {
66          ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
67          ArtifactRepository repo = new ArtifactRepository(
68              createArtifacts( new String[]{ "myartifact" }, null, null, 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      public void testRepositoryWithMultipleClassifiedArtifacts()
76      {
77          ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
78          ArtifactRepository repo = new ArtifactRepository(
79              createArtifacts( new String[]{ "myartifact", "myartifact", "myartifact" }, null, null,
80                               new String[]{ "class1", "class2", "class3" } ), MAIN_ARTIFACT_ID,
81              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      public void testRepositoryWithMultipleClassifiedArtifactsAndMainArtifact()
91          throws PlexusConfigurationException, EarPluginException
92      {
93          ArtifactTypeMappingService artifactTypeMappingService = new ArtifactTypeMappingService();
94          ArtifactRepository repo = new ArtifactRepository(
95              createArtifacts( new String[]{ "myartifact", "myartifact", "myartifact" }, null, null,
96                               new String[]{ "class1", "class2", null } ), 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 }