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
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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 }