1 package org.apache.archiva.webdav;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import com.gargoylesoftware.htmlunit.WebRequest;
24 import com.gargoylesoftware.htmlunit.WebResponse;
25 import org.apache.commons.lang.ArrayUtils;
26 import org.apache.commons.lang.StringUtils;
27 import org.custommonkey.xmlunit.DetailedDiff;
28 import org.custommonkey.xmlunit.Diff;
29 import org.junit.Before;
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
58
59 WebRequest request = new GetMethodWebRequest( "http://machine.com/repository/internal/" + path );
60 WebResponse response = getServletUnitClient().getResponse( request );
61 assertResponseOK( response );
62 return response.getContentAsString();
63 }
64
65 protected String createProjectMetadata( String groupId, String artifactId, String latest, String release,
66 String[] versions )
67 {
68 StringBuilder buf = new StringBuilder();
69
70 buf.append( "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" );
71 buf.append( "<metadata>\n" );
72 buf.append( " <groupId>" ).append( groupId ).append( "</groupId>\n" );
73 buf.append( " <artifactId>" ).append( artifactId ).append( "</artifactId>\n" );
74
75 boolean hasLatest = StringUtils.isNotBlank( latest );
76 boolean hasRelease = StringUtils.isNotBlank( release );
77 boolean hasVersions = !ArrayUtils.isEmpty( versions );
78
79 if ( hasLatest || hasRelease || hasVersions )
80 {
81 buf.append( " <versioning>\n" );
82 if ( hasLatest )
83 {
84 buf.append( " <latest>" ).append( latest ).append( "</latest>\n" );
85 }
86 if ( hasRelease )
87 {
88 buf.append( " <release>" ).append( release ).append( "</release>\n" );
89 }
90 if ( hasVersions )
91 {
92 buf.append( " <versions>\n" );
93 for ( String availVersion : versions )
94 {
95 buf.append( " <version>" ).append( availVersion ).append( "</version>\n" );
96 }
97 buf.append( " </versions>\n" );
98 }
99 buf.append( " </versioning>\n" );
100 }
101 buf.append( "</metadata>" );
102
103 return buf.toString();
104 }
105
106 protected String createGroupMetadata( String groupId, String[] plugins )
107 {
108 StringBuilder buf = new StringBuilder();
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
114 boolean hasPlugins = !ArrayUtils.isEmpty( plugins );
115
116 if ( hasPlugins )
117 {
118 buf.append( " <plugins>\n" );
119 for ( String plugin : plugins )
120 {
121 buf.append( " <plugin>\n" );
122 buf.append( " <prefix>" ).append( plugin ).append( "</prefix>\n" );
123 buf.append( " <artifactId>" ).append( plugin + "-maven-plugin" ).append( "</artifactId>\n" );
124 buf.append( " <name>" ).append( "The " + plugin + " Plugin" ).append( "</name>\n" );
125 buf.append( " </plugin>\n" );
126 }
127 buf.append( " </plugins>\n" );
128 }
129 buf.append( "</metadata>" );
130
131 return buf.toString();
132 }
133
134 protected void setupPrivateSnapshotsRemoteRepo()
135 throws Exception
136 {
137 remotePrivateSnapshots = createServer( "private-snapshots" );
138
139 assertServerSetupCorrectly( remotePrivateSnapshots );
140 archivaConfiguration.getConfiguration().addRemoteRepository( remotePrivateSnapshots.config );
141 setupCleanRepo( remotePrivateSnapshots.root );
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205 @Before
206 @Override
207 public void tearDown()
208 throws Exception
209 {
210 shutdownServer( remotePrivateSnapshots );
211
212 super.tearDown();
213 }
214 }