View Javadoc

1   package org.apache.maven.plugin.ear;
2   
3   import junit.framework.TestCase;
4   import org.apache.maven.artifact.Artifact;
5   
6   import java.util.Set;
7   import java.util.TreeSet;
8   
9   /*
10  * Licensed to the Apache Software Foundation (ASF) under one
11  * or more contributor license agreements.  See the NOTICE file
12  * distributed with this work for additional information
13  * regarding copyright ownership.  The ASF licenses this file
14  * to you under the Apache License, Version 2.0 (the
15  * "License"); you may not use this file except in compliance
16  * with the License.  You may obtain a copy of the License at
17  *
18  *  http://www.apache.org/licenses/LICENSE-2.0
19  *
20  * Unless required by applicable law or agreed to in writing,
21  * software distributed under the License is distributed on an
22  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23  * KIND, either express or implied.  See the License for the
24  * specific language governing permissions and limitations
25  * under the License.
26  */
27  
28  /**
29   * @author <a href="snicoll@apache.org">Stephane Nicoll</a>
30   */
31  public abstract class AbstractEarTest
32      extends TestCase
33  {
34  
35      public static final String DEFAULT_GROUPID = "eartest";
36  
37      public static final String DEFAULT_TYPE = "jar";
38  
39  
40      protected void setUri( EarModule module, String uri )
41      {
42          ( (AbstractEarModule) module ).setUri( uri );
43      }
44  
45  
46      protected Set<Artifact> createArtifacts( String[] artifactsId )
47      {
48          return createArtifacts( artifactsId, null );
49      }
50  
51      protected Set<Artifact> createArtifacts( String[] artifactsId, String[] types )
52      {
53          return createArtifacts( artifactsId, types, null );
54      }
55  
56      protected Set<Artifact> createArtifacts( String[] artifactsId, String[] types, String[] groupsId )
57      {
58          return createArtifacts( artifactsId, types, groupsId, null );
59      }
60  
61      protected Set<Artifact> createArtifacts( String[] artifactsId, String[] types, String[] groupsId, String[] classifiers )
62      {
63          Set<Artifact> result = new TreeSet<Artifact>();
64          if ( artifactsId == null || artifactsId.length == 0 )
65          {
66              return result;
67          }
68          for ( int i = 0; i < artifactsId.length; i++ )
69          {
70              String artifactId = artifactsId[i];
71              String type = getData( types, i, DEFAULT_TYPE );
72              String groupId = getData( groupsId, i, DEFAULT_GROUPID );
73              String classifier = getData( classifiers, i, null );
74              result.add( new ArtifactTestStub( groupId, artifactId, type, classifier ) );
75  
76          }
77          return result;
78      }
79  
80      protected String getData( String[] data, int i, String defaultValue )
81      {
82          if ( data == null || data[i] == null )
83          {
84              return defaultValue;
85          }
86          else
87          {
88              return data[i];
89  
90          }
91      }
92  
93      protected String getDefaultValue( String t, String defaultValue )
94      {
95          if ( t == null )
96          {
97              return defaultValue;
98          }
99          else
100         {
101             return t;
102         }
103     }
104 
105     protected Artifact createArtifact( String artifactId, String type, String groupId, String classifier )
106     {
107         return new ArtifactTestStub( getDefaultValue( groupId, DEFAULT_GROUPID ), artifactId,
108                                      getDefaultValue( type, DEFAULT_TYPE ), classifier );
109     }
110 
111 
112     protected Artifact createArtifact( String artifactId, String type, String groupId )
113     {
114         return createArtifact( artifactId, type, groupId, null );
115 
116     }
117 
118     protected Artifact createArtifact( String artifactId, String type )
119     {
120         return createArtifact( artifactId, type, null );
121 
122     }
123 }