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