1 package org.apache.maven.archiva.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import com.meterware.httpunit.GetMethodWebRequest;
23 import com.meterware.httpunit.HttpUnitOptions;
24 import com.meterware.httpunit.WebRequest;
25 import com.meterware.httpunit.WebResponse;
26 import org.apache.commons.lang.ArrayUtils;
27 import org.apache.commons.lang.StringUtils;
28 import org.custommonkey.xmlunit.DetailedDiff;
29 import org.custommonkey.xmlunit.Diff;
30
31
32
33
34
35
36 public abstract class AbstractRepositoryServletProxiedMetadataTestCase
37 extends AbstractRepositoryServletProxiedTestCase
38 {
39 protected RemoteRepoInfo remotePrivateSnapshots;
40
41 protected void assertExpectedMetadata( String expectedMetadata, String actualMetadata )
42 throws Exception
43 {
44 DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadata, actualMetadata ) );
45 if ( !detailedDiff.similar() )
46 {
47
48 assertEquals( expectedMetadata, actualMetadata );
49 }
50
51 }
52
53 protected String requestMetadataOK( String path )
54 throws Exception
55 {
56
57 HttpUnitOptions.setExceptionsThrownOnErrorStatus( false );
58
59 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + path );
60 WebResponse response = sc.getResponse( request );
61 assertResponseOK( response );
62 return response.getText();
63 }
64
65 protected String createVersionMetadata( String groupId, String artifactId, String version )
66 {
67 return createVersionMetadata( groupId, artifactId, version, null, null, null );
68 }
69
70 protected String createVersionMetadata( String groupId, String artifactId, String version, String timestamp,
71 String buildNumber, String lastUpdated )
72 {
73 StringBuffer buf = new StringBuffer();
74
75 buf.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" );
76 buf.append( "<metadata>\n" );
77 buf.append( " <groupId>" ).append( groupId ).append( "</groupId>\n" );
78 buf.append( " <artifactId>" ).append( artifactId ).append( "</artifactId>\n" );
79 buf.append( " <version>" ).append( version ).append( "</version>\n" );
80
81 boolean hasSnapshot = StringUtils.isNotBlank( timestamp ) || StringUtils.isNotBlank( buildNumber );
82 boolean hasLastUpdated = StringUtils.isNotBlank( lastUpdated );
83
84 if ( hasSnapshot || hasLastUpdated )
85 {
86 buf.append( " <versioning>\n" );
87 if ( hasSnapshot )
88 {
89 buf.append( " <snapshot>\n" );
90 buf.append( " <buildNumber>" ).append( buildNumber ).append( "</buildNumber>\n" );
91 buf.append( " <timestamp>" ).append( timestamp ).append( "</timestamp>\n" );
92 buf.append( " </snapshot>\n" );
93 }
94 if ( hasLastUpdated )
95 {
96 buf.append( " <lastUpdated>" ).append( lastUpdated ).append( "</lastUpdated>\n" );
97 }
98 buf.append( " </versioning>\n" );
99 }
100 buf.append( "</metadata>" );
101
102 return buf.toString();
103 }
104
105 protected String createProjectMetadata( String groupId, String artifactId, String latest, String release,
106 String[] versions )
107 {
108 StringBuffer buf = new StringBuffer();
109
110 buf.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" );
111 buf.append( "<metadata>\n" );
112 buf.append( " <groupId>" ).append( groupId ).append( "</groupId>\n" );
113 buf.append( " <artifactId>" ).append( artifactId ).append( "</artifactId>\n" );
114
115 boolean hasLatest = StringUtils.isNotBlank( latest );
116 boolean hasRelease = StringUtils.isNotBlank( release );
117 boolean hasVersions = !ArrayUtils.isEmpty( versions );
118
119 if ( hasLatest || hasRelease || hasVersions )
120 {
121 buf.append( " <versioning>\n" );
122 if ( hasLatest )
123 {
124 buf.append( " <latest>" ).append( latest ).append( "</latest>\n" );
125 }
126 if ( hasRelease )
127 {
128 buf.append( " <release>" ).append( release ).append( "</release>\n" );
129 }
130 if ( hasVersions )
131 {
132 buf.append( " <versions>\n" );
133 for ( String availVersion : versions )
134 {
135 buf.append( " <version>" ).append( availVersion ).append( "</version>\n" );
136 }
137 buf.append( " </versions>\n" );
138 }
139 buf.append( " </versioning>\n" );
140 }
141 buf.append( "</metadata>" );
142
143 return buf.toString();
144 }
145
146 protected String createGroupMetadata( String groupId, String[] plugins )
147 {
148 StringBuffer buf = new StringBuffer();
149
150 buf.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" );
151 buf.append( "<metadata>\n" );
152 buf.append( " <groupId>" ).append( groupId ).append( "</groupId>\n" );
153
154 boolean hasPlugins = !ArrayUtils.isEmpty( plugins );
155
156 if ( hasPlugins )
157 {
158 buf.append( " <plugins>\n" );
159 for ( String plugin : plugins )
160 {
161 buf.append( " <plugin>\n" );
162 buf.append( " <prefix>" ).append( plugin ).append( "</prefix>\n" );
163 buf.append( " <artifactId>" ).append( plugin + "-maven-plugin" ).append( "</artifactId>\n" );
164 buf.append( " <name>" ).append( "The " + plugin + " Plugin" ).append( "</name>\n" );
165 buf.append( " </plugin>\n" );
166 }
167 buf.append( " </plugins>\n" );
168 }
169 buf.append( "</metadata>" );
170
171 return buf.toString();
172 }
173
174 protected void setupPrivateSnapshotsRemoteRepo()
175 throws Exception
176 {
177 remotePrivateSnapshots = createServer( "private-snapshots" );
178
179 assertServerSetupCorrectly( remotePrivateSnapshots );
180 archivaConfiguration.getConfiguration().addRemoteRepository( remotePrivateSnapshots.config );
181 setupCleanRepo( remotePrivateSnapshots.root );
182 }
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245 protected void tearDown()
246 throws Exception
247 {
248 shutdownServer( remotePrivateSnapshots );
249
250 super.tearDown();
251 }
252 }