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
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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 createArtifacts( String[] artifactsId )
47 {
48 return createArtifacts( artifactsId, null );
49 }
50
51 protected Set createArtifacts( String[] artifactsId, String[] types )
52 {
53 return createArtifacts( artifactsId, types, null );
54 }
55
56 protected Set createArtifacts( String[] artifactsId, String[] types, String[] groupsId )
57 {
58 return createArtifacts( artifactsId, types, groupsId, null );
59 }
60
61 protected Set createArtifacts( String[] artifactsId, String[] types, String[] groupsId, String[] classifiers )
62 {
63 Set result = new TreeSet();
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 }