]> source.dussan.org Git - archiva.git/blob
94db3f39c6d07666cf25264cdba3ec4e3f96d425
[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" }, enabled = false )
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         // FIXME: broken
59         assertTextPresent( "Invalid cron expression." );
60     }
61
62     @Test
63     public void testAddManagedRepoInvalidIdentifier()
64     {
65         getSelenium().open( "/archiva/admin/addRepository.action" );
66
67         addManagedRepository( "<> \\/~+[ ]'\"", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1",
68                               "1", false );
69         assertTextPresent(
70             "Identifier must only contain alphanumeric characters, underscores(_), dots(.), and dashes(-)." );
71     }
72
73     @Test
74     public void testAddManagedRepoInvalidRepoName()
75     {
76         getSelenium().open( "/archiva/admin/addRepository.action" );
77
78         addManagedRepository( "identifier", "<>\\~+[]'\"", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?",
79                               "1", "1", false );
80         assertTextPresent(
81             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
82     }
83
84     @Test
85     public void testAddManagedRepoInvalidDirectory()
86     {
87         getSelenium().open( "/archiva/admin/addRepository.action" );
88
89         addManagedRepository( "identifier", "name", "<> ~+[ ]'\"", "/.index", "Maven 2.x Repository", "0 0 * * * ?",
90                               "1", "1", false );
91         assertTextPresent(
92             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
93     }
94
95     @Test
96     public void testAddManagedRepoInvalidIndexDir()
97     {
98         getSelenium().open( "/archiva/admin/addRepository.action" );
99
100         addManagedRepository( "identifier", "name", "/home", "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1",
101                               "1", false );
102         assertTextPresent(
103             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
104     }
105
106     @Test
107     public void testAddManagedRepoInvalidRetentionCount()
108     {
109         getSelenium().open( "/archiva/admin/addRepository.action" );
110
111         addManagedRepository( "identifier", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1",
112                               "101", false );
113         assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
114     }
115
116     @Test
117     public void testAddManagedRepoInvalidDaysOlder()
118     {
119         getSelenium().open( "/archiva/admin/addRepository.action" );
120
121         addManagedRepository( "identifier", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1",
122                               "1", false );
123         assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
124     }
125
126     @Test( enabled = false )
127     public void testAddManagedRepoBlankValues()
128     {
129         getSelenium().open( "/archiva/admin/addRepository.action" );
130
131         addManagedRepository( "", "", "", "", "Maven 2.x Repository", "", "", "", false );
132         assertTextPresent( "You must enter a repository identifier." );
133         assertTextPresent( "You must enter a repository name." );
134         assertTextPresent( "You must enter a directory." );
135         // FIXME: broken
136         assertTextPresent( "Invalid cron expression." );
137     }
138
139     @Test
140     public void testAddManagedRepoNoIdentifier()
141     {
142         getSelenium().open( "/archiva/admin/addRepository.action" );
143
144         addManagedRepository( "", "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "", false );
145         assertTextPresent( "You must enter a repository identifier." );
146     }
147
148     @Test
149     public void testAddManagedRepoNoRepoName()
150     {
151         getSelenium().open( "/archiva/admin/addRepository.action" );
152
153         addManagedRepository( "identifier", "", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "",
154                               false );
155         assertTextPresent( "You must enter a repository name." );
156     }
157
158     @Test
159     public void testAddManagedRepoNoDirectory()
160     {
161         getSelenium().open( "/archiva/admin/addRepository.action" );
162
163         addManagedRepository( "identifier", "name", "", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "", "",
164                               false );
165         assertTextPresent( "You must enter a directory." );
166     }
167
168     @Test( enabled = false )
169     public void testAddManagedRepoNoCron()
170     {
171         getSelenium().open( "/archiva/admin/addRepository.action" );
172
173         addManagedRepository( "identifier", "name", "/home", "/.index", "Maven 2.x Repository", "", "", "", false );
174
175         // FIXME: broken
176         assertTextPresent( "Invalid cron expression." );
177     }
178
179     @Test
180     public void testAddManagedRepoForEdit()
181     {
182         getSelenium().open( "/archiva/admin/addRepository.action" );
183         addManagedRepository( "managedrepo", "Managed Repository Sample", getRepositoryDir() + "local-repo/", "",
184                               "Maven 2.x Repository", "0 0 * * * ?", "", "", true );
185         clickButtonWithValue( "Save" );
186         assertTextPresent( "Managed Repository Sample" );
187     }
188
189     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" }, enabled = false )
190     public void testEditManagedRepoInvalidValues()
191     {
192         editManagedRepository( "<>\\~+[]'\"", "<> ~+[ ]'\"", "<> ~+[ ]'\"", "Maven 2.x Repository", "", "-1", "101" );
193         assertTextPresent(
194             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
195         assertTextPresent(
196             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
197         assertTextPresent(
198             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
199         assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
200         assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
201         // FIXME: broken
202         assertTextPresent( "Invalid cron expression." );
203     }
204
205     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
206     public void testEditManagedRepoInvalidRepoName()
207     {
208         editManagedRepository( "<>\\~+[]'\"", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
209         assertTextPresent(
210             "Repository Name must only contain alphanumeric characters, white-spaces(' '), forward-slashes(/), open-parenthesis('('), close-parenthesis(')'), underscores(_), dots(.), and dashes(-)." );
211     }
212
213     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
214     public void testEditManagedRepoInvalidDirectory()
215     {
216         editManagedRepository( "name", "<> ~+[ ]'\"", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
217         assertTextPresent(
218             "Directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
219     }
220
221     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
222     public void testEditManagedRepoInvalidIndexDir()
223     {
224         editManagedRepository( "name", "/home", "<> ~+[ ]'\"", "Maven 2.x Repository", "0 0 * * * ?", "1", "1" );
225         assertTextPresent(
226             "Index directory must only contain alphanumeric characters, equals(=), question-marks(?), exclamation-points(!), ampersands(&), forward-slashes(/), back-slashes(\\), underscores(_), dots(.), colons(:), tildes(~), and dashes(-)." );
227     }
228
229     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" }, enabled = false )
230     public void testEditManagedRepoInvalidCron()
231     {
232         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "", "1", "1" );
233         // FIXME: broken
234         assertTextPresent( "Invalid cron expression." );
235     }
236
237     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
238     public void testEditManagedRepoInvalidRetentionCount()
239     {
240         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "1", "101" );
241         assertTextPresent( "Repository Purge By Retention Count needs to be between 1 and 100." );
242     }
243
244     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
245     public void testEditManagedRepoInvalidDaysOlder()
246     {
247         editManagedRepository( "name", "/home", "/.index", "Maven 2.x Repository", "0 0 * * * ?", "-1", "1" );
248         assertTextPresent( "Repository Purge By Days Older Than needs to be larger than 0." );
249     }
250
251     // TODO
252     @Test( dependsOnMethods = { "testAddManagedRepoForEdit" } )
253     public void testEditManagedRepo()
254     {
255         editManagedRepository( "repository.name", "Managed Repo" );
256         assertTextPresent( "Managed Repository Sample" );
257     }
258
259     // TODO
260     @Test( dependsOnMethods = { "testEditManagedRepo" }, enabled = false )
261     public void testDeleteManageRepo()
262     {
263         deleteManagedRepository();
264         // assertTextNotPresent( "managedrepo" );
265     }
266
267     @Test( dependsOnMethods = { "testAddRemoteRepoValidValues" } )
268     public void testAddRemoteRepoNullValues()
269     {
270         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
271         addRemoteRepository( "", "", "", "", "", "", "Maven 2.x Repository", false );
272         assertTextPresent( "You must enter a repository identifier." );
273         assertTextPresent( "You must enter a repository name." );
274         assertTextPresent( "You must enter a url." );
275     }
276
277     @Test
278     public void testAddRemoteRepositoryNullIdentifier()
279     {
280         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
281         addRemoteRepository( "", "Remote Repository Sample", "http://repository.codehaus.org/org/codehaus/mojo/", "",
282                              "", "", "Maven 2.x Repository", false );
283         assertTextPresent( "You must enter a repository identifier." );
284     }
285
286     @Test( dependsOnMethods = { "testAddRemoteRepositoryNullIdentifier" } )
287     public void testAddRemoteRepoNullName()
288     {
289         addRemoteRepository( "remoterepo", "", "http://repository.codehaus.org/org/codehaus/mojo/", "", "", "",
290                              "Maven 2.x Repository", false );
291         assertTextPresent( "You must enter a repository name." );
292     }
293
294     @Test
295     public void testAddRemoteRepoNullURL()
296     {
297         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
298         addRemoteRepository( "remoterepo", "Remote Repository Sample", "", "", "", "", "Maven 2.x Repository", false );
299         assertTextPresent( "You must enter a url." );
300     }
301
302     @Test( dependsOnMethods = { "testAddRemoteRepoNullURL" } )
303     public void testAddProxyConnectorValidValues()
304         throws Exception
305     {
306         getSelenium().open( "/archiva/admin/addProxyConnector.action" );
307         addProxyConnector( "(direct connection)", "internal", "remoterepo" );
308         assertTextPresent( "remoterepo" );
309         assertTextPresent( "Remote Repository Sample" );
310     }
311
312     @Test
313     public void testAddRemoteRepoValidValues()
314     {
315         getSelenium().open( "/archiva/admin/addRemoteRepository.action" );
316         addRemoteRepository( "remoterepo", "Remote Repository Sample",
317                              "http://repository.codehaus.org/org/codehaus/mojo/", "", "", "", "Maven 2.x Repository",
318                              true );
319         assertTextPresent( "Remote Repository Sample" );
320     }
321
322     // *** BUNDLED REPOSITORY TEST ***
323
324     @Test( dependsOnMethods = { "testWithCorrectUsernamePassword" }, alwaysRun = true )
325     public void testBundledRepository()
326     {
327         String repo1 = baseUrl + "repository/internal/";
328         String repo2 = baseUrl + "repository/snapshots/";
329
330         assertRepositoryAccess( repo1 );
331         assertRepositoryAccess( repo2 );
332
333         getSelenium().open( "/archiva" );
334     }
335
336     private void assertRepositoryAccess( String repo )
337     {
338         getSelenium().open( "/archiva" );
339         goToRepositoriesPage();
340         assertLinkPresent( repo );
341         clickLinkWithText( repo );
342         assertPage( "Collection: /" );
343         assertTextPresent( "Collection: /" );
344     }
345 }