]> source.dussan.org Git - archiva.git/blob
b51bc0694461e31d7d8e56188e3dc8a2b8ca359d
[archiva.git] /
1 package org.apache.archiva.web.test;
2
3 /*
4  * Licensed to the Apache Software Foundation (ASF) under one
5  * or more contributor license agreements.  See the NOTICE file
6  * distributed with this work for additional information
7  * regarding copyright ownership.  The ASF licenses this file
8  * to you under the Apache License, Version 2.0 (the
9  * "License"); you may not use this file except in compliance
10  * with the License.  You may obtain a copy of the License at
11  *
12  *   http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing,
15  * software distributed under the License is distributed on an
16  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17  * KIND, either express or implied.  See the License for the
18  * specific language governing permissions and limitations
19  * under the License.
20  */
21
22 import org.apache.archiva.web.test.parent.AbstractRepositoryTest;
23 import org.testng.annotations.Test;
24
25 @Test( groups = { "repository" }, dependsOnMethods = { "testWithCorrectUsernamePassword" }, sequential = true )
26 public class RepositoryTest
27     extends AbstractRepositoryTest
28 {
29     @Test
30     public void testAddManagedRepoValidValues()
31     {
32         goToRepositoriesPage();
33         getSelenium().open( "/archiva/admin/addRepository.action" );
34         addManagedRepository( "managedrepo1", "Managed Repository Sample 1", getRepositoryDir() + "repository/", "",
35                               "Maven 2.x Repository", "0 0 * * * ?", "", "", true );
36         clickButtonWithValue( "Save" );
37         assertTextPresent( "Managed Repository Sample 1" );
38         assertRepositoriesPage();
39     }
40
41     @Test( dependsOnMethods = { "testAddManagedRepoValidValues" } )
42     public void testAddManagedRepoInvalidValues()
43     {
44         getSelenium().open( "/archiva/admin/addRepository.action" );
45
46         addManagedRepository( "<> \\/~+[ ]'\"", "<>\\~+[]'\"", "<> ~+[ ]'\"", "<> ~+[ ]'\"", "Maven 2.x Repository", "",
47                               "-1", "101", false );
48         assertTextPresent(
49             "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
50         assertTextPresent(
51             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
52         assertTextPresent(
53             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
54         assertTextPresent(
55             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
56         assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
57         assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
58         assertTextPresent( "Cron expression is required." );
59     }
60
61     @Test
62     public void testAddManagedRepoInvalidIdentifier()
63     {
64         getSelenium().open( "/archiva/admin/addRepository.action" );
65
66         addManagedRepository( "<> \\/~+[ ]'\"", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1",
67                               "1", false );
68         assertTextPresent(
69             "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
70     }
71
72     @Test
73     public void testAddManagedRepoInvalidRepoName()
74     {
75         getSelenium().open( "/archiva/admin/addRepository.action" );
76
77         addManagedRepository( "identifier", "<>\\~+[]'\"", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?",
78                               "1", "1", false );
79         assertTextPresent(
80             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
81     }
82
83     @Test
84     public void testAddManagedRepoInvalidDirectory()
85     {
86         getSelenium().open( "/archiva/admin/addRepository.action" );
87
88         addManagedRepository( "identifier", "name", "<> ~+[ ]'\"", "/.index", "Maven 2.x Repository", "0 0 * * * ?",
89                               "1", "1", false );
90         assertTextPresent(
91             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
92     }
93
94     @Test
95     public void testAddManagedRepoInvalidIndexDir()
96     {
97         getSelenium().open( "/archiva/admin/addRepository.action" );
98
99         addManagedRepository( "identifier", "name", "/home", "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1",
100                               "1", false );
101         assertTextPresent(
102             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
103     }
104
105     @Test
106     public void testAddManagedRepoInvalidRetentionCount()
107     {
108         getSelenium().open( "/archiva/admin/addRepository.action" );
109
110         addManagedRepository( "identifier", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1",
111                               "101", false );
112         assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
113     }
114
115     @Test
116     public void testAddManagedRepoInvalidDaysOlder()
117     {
118         getSelenium().open( "/archiva/admin/addRepository.action" );
119
120         addManagedRepository( "identifier", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1",
121                               "1", false );
122         assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
123     }
124
125     @Test
126     public void testAddManagedRepoBlankValues()
127     {
128         getSelenium().open( "/archiva/admin/addRepository.action" );
129
130         addManagedRepository( "", "", "", "", "Maven 2.x Repository", "", "", "", false );
131         assertTextPresent( "You must enter a repository identifier." );
132         assertTextPresent( "You must enter a repository name." );
133         assertTextPresent( "You must enter a directory." );
134         assertTextPresent( "Cron expression is required." );
135     }
136
137     @Test
138     public void testAddManagedRepoNoIdentifier()
139     {
140         getSelenium().open( "/archiva/admin/addRepository.action" );
141
142         addManagedRepository( "", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "", false );
143         assertTextPresent( "You must enter a repository identifier." );
144     }
145
146     @Test
147     public void testAddManagedRepoNoRepoName()
148     {
149         getSelenium().open( "/archiva/admin/addRepository.action" );
150
151         addManagedRepository( "identifier", "", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "",
152                               false );
153         assertTextPresent( "You must enter a repository name." );
154     }
155
156     @Test
157     public void testAddManagedRepoNoDirectory()
158     {
159         getSelenium().open( "/archiva/admin/addRepository.action" );
160
161         addManagedRepository( "identifier", "name", "", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "",
162                               false );
163         assertTextPresent( "You must enter a directory." );
164     }
165
166     @Test
167     public void testAddManagedRepoNoCron()
168     {
169         getSelenium().open( "/archiva/admin/addRepository.action" );
170
171         addManagedRepository( "identifier", "name", "/home", "/.index", "Maven 2.x Repository", "", "", "", false );
172
173         assertTextPresent( "Cron expression is required." );
174     }
175
176     @Test
177     public void testAddManagedRepoForEdit()
178     {
179         getSelenium().open( "/archiva/admin/addRepository.action" );
180         addManagedRepository( "managedrepo", "Managed Repository Sample", getRepositoryDir() + "local-repo/", "",
181                               "Maven 2.x Repository", "0 0 * * * ?", "", "", true );
182         clickButtonWithValue( "Save" );
183         assertTextPresent( "Managed Repository Sample" );
184     }
185
186     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
187     public void testEditManagedRepoInvalidValues()
188     {
189         editManagedRepository( "<>\\~+[]'\"", "<> ~+[ ]'\"", "<> ~+[ ]'\"", "Maven 2.x Repository", "", "-1", "101" );
190         assertTextPresent(
191             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
192         assertTextPresent(
193             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
194         assertTextPresent(
195             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
196         assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
197         assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
198         assertTextPresent( "Cron expression is required." );
199     }
200
201     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
202     public void testEditManagedRepoInvalidRepoName()
203     {
204         editManagedRepository( "<>\\~+[]'\"", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
205         assertTextPresent(
206             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
207     }
208
209     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
210     public void testEditManagedRepoInvalidDirectory()
211     {
212         editManagedRepository( "name", "<> ~+[ ]'\"", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
213         assertTextPresent(
214             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
215     }
216
217     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
218     public void testEditManagedRepoInvalidIndexDir()
219     {
220         editManagedRepository( "name", "/home", "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
221         assertTextPresent(
222             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
223     }
224
225     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
226     public void testEditManagedRepoInvalidCronBadText()
227     {
228         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "asdf", "1", "1" );
229         assertTextPresent( "Invalid cron expression." );
230     }
231
232     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
233     public void testEditManagedRepoInvalidCronBadValue()
234     {
235         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "60 0 * * * ?", "1", "1" );
236         assertTextPresent( "Invalid cron expression." );
237     }
238
239     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
240     public void testEditManagedRepoInvalidCronTooManyElements()
241     {
242         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "* * * * * * * *", "1", "1" );
243         assertTextPresent( "Invalid cron expression." );
244     }
245
246     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
247     public void testEditManagedRepoInvalidRetentionCount()
248     {
249         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "101" );
250         assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
251     }
252
253     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
254     public void testEditManagedRepoInvalidDaysOlder()
255     {
256         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1", "1" );
257         assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
258     }
259
260     // TODO
261     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
262     public void testEditManagedRepo()
263     {
264         editManagedRepository( "repository.name", "Managed Repo" );
265         assertTextPresent( "Managed Repository Sample" );
266     }
267
268     // TODO
269     @Test( dependsOnMethods = { "testEditManagedRepo" }, enabled = false )
270     public void testDeleteManageRepo()
271     {
272         deleteManagedRepository();
273         // assertTextNotPresent( "managedrepo" );
274     }
275
276     @Test( dependsOnMethods = { "testAddRemoteRepoValidValues" } )
277     public void testAddRemoteRepoNullValues()
278     {
279         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
280         addRemoteRepository( "", "", "", "", "", "", "Maven 2.x Repository", false );
281         assertTextPresent( "You must enter a repository identifier." );
282         assertTextPresent( "You must enter a repository name." );
283         assertTextPresent( "You must enter a url." );
284     }
285
286     @Test
287     public void testAddRemoteRepositoryNullIdentifier()
288     {
289         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
290         addRemoteRepository( "", "Remote Repository Sample", "http://repository.codehaus.org/org/codehaus/mojo/", "",
291                              "", "", "Maven 2.x Repository", false );
292         assertTextPresent( "You must enter a repository identifier." );
293     }
294
295     @Test( dependsOnMethods = { "testAddRemoteRepositoryNullIdentifier" } )
296     public void testAddRemoteRepoNullName()
297     {
298         addRemoteRepository( "remoterepo", "", "http://repository.codehaus.org/org/codehaus/mojo/", "", "", "",
299                              "Maven 2.x Repository", false );
300         assertTextPresent( "You must enter a repository name." );
301     }
302
303     @Test
304     public void testAddRemoteRepoNullURL()
305     {
306         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
307         addRemoteRepository( "remoterepo", "Remote Repository Sample", "", "", "", "", "Maven 2.x Repository", false );
308         assertTextPresent( "You must enter a url." );
309     }
310
311     @Test( dependsOnMethods = { "testAddRemoteRepoNullURL" } )
312     public void testAddProxyConnectorValidValues()
313         throws Exception
314     {
315         getSelenium().open( "/archiva/admin/addProxyConnector.action" );
316         addProxyConnector( "(direct connection)", "internal", "remoterepo" );
317         assertTextPresent( "remoterepo" );
318         assertTextPresent( "Remote Repository Sample" );
319     }
320
321     @Test
322     public void testAddRemoteRepoValidValues()
323     {
324         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
325         addRemoteRepository( "remoterepo", "Remote Repository Sample",
326                              "http://repository.codehaus.org/org/codehaus/mojo/", "", "", "", "Maven 2.x Repository",
327                              true );
328         assertTextPresent( "Remote Repository Sample" );
329     }
330
331     // *** BUNDLED REPOSITORY TEST ***
332
333     @Test( dependsOnMethods = { "testWithCorrectUsernamePassword" }, alwaysRun = true )
334     public void testBundledRepository()
335     {
336         String repo1 = baseUrl + "repository/internal/";
337         String repo2 = baseUrl + "repository/snapshots/";
338
339         assertRepositoryAccess( repo1 );
340         assertRepositoryAccess( repo2 );
341
342         getSelenium().open( "/archiva" );
343     }
344
345     private void assertRepositoryAccess( String repo )
346     {
347         getSelenium().open( "/archiva" );
348         goToRepositoriesPage();
349         assertLinkPresent( repo );
350         clickLinkWithText( repo );
351         assertPage( "Collection: /" );
352         assertTextPresent( "Collection: /" );
353     }
354 }