]> source.dussan.org Git - archiva.git/blob
6c8e66209cf03db608daa87b211f1a0df358ec49
[archiva.git] /
1 package org.apache.archiva.web.test.parent;
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 java.io.File;
23 import org.testng.Assert;
24
25 public abstract class AbstractRepositoryTest 
26         extends AbstractArchivaTest
27 {
28         // Repository Groups
29         public void goToRepositoryGroupsPage()
30         {
31             if( !getTitle().equals( "Apache Archiva \\ Administration - Repository Groups" ) )
32             {
33                 clickLinkWithText( "Repository Groups" );
34             }
35                 assertRepositoryGroupsPage();
36         }
37         
38         public void assertRepositoryGroupsPage()
39         {
40                 assertPage( "Apache Archiva \\ Administration - Repository Groups" );
41                 assertTextPresent( "Administration - Repository Groups" );
42                 assertTextPresent( "Identifier*:" );
43                 assertElementPresent( "repositoryGroup.id" );
44                 assertButtonWithValuePresent( "Add Group" );
45                 assertTextPresent( "Repository Groups" );
46         }
47         
48         public void assertAddedRepositoryLink( String repositoryGroupName)
49         {
50                 assertPage( "Apache Archiva \\ Administration - Repository Groups" );
51                 String repositoryGroupUrlValue = "repository/" + repositoryGroupName + "/";
52                 String baseUrlValue = "archiva";
53                 String repositoryGroupLink = baseUrl.replaceFirst( baseUrlValue, repositoryGroupUrlValue);
54                 assertTextPresent( repositoryGroupLink );
55         }
56         
57         public void assertAddedRepositoryToRepositoryGroups( String repositoryName)
58         {
59                 assertPage( "Apache Archiva \\ Administration - Repository Groups" );
60                 assertTextPresent( repositoryName );
61                 assertTextPresent( "Archiva Managed Internal Repository" );
62                 assertAddedRepositoryLink( repositoryName );
63         }
64         
65         public void assertDeleteRepositoryGroupPage( String repositoryName)
66         {
67                 assertPage( "Apache Archiva \\ Admin: Delete Repository Group" );
68                 assertTextPresent( "WARNING: This operation can not be undone." );
69                 assertTextPresent( "Are you sure you want to delete the following repository group?" );
70                 assertTextPresent( "ID: " + repositoryName );
71                 assertButtonWithValuePresent( "Confirm" );
72                 assertButtonWithValuePresent( "Cancel" );
73         }
74         
75         public void addRepositoryGroup( String repoGroupName )
76         {
77                 goToRepositoryGroupsPage();
78                 setFieldValue( "repositoryGroup.id", repoGroupName );
79                 clickButtonWithValue( "Add Group" );
80         }
81         
82         public void addRepositoryToRepositoryGroup( String repositoryGroupName, String repositoryName )
83         {
84                 goToRepositoryGroupsPage();
85                 String s = getSelenium().getBodyText();
86                 if ( s.contains( "No Repository Groups Defined." ) )
87                 {
88                         setFieldValue( "repositoryGroup.id" , repositoryGroupName );
89                         clickButtonWithValue( "Add Group" );
90                         //assertAddedRepositoryLink( repositoryGroupName );
91                         
92                         selectValue( "addRepositoryToGroup_repoId" , repositoryName );
93                         clickButtonWithValue( "Add Repository" );
94                         assertAddedRepositoryToRepositoryGroups( repositoryName );
95                 }
96                 else
97                 {
98                         //assertAddedRepositoryLink( repositoryGroupName );
99                         selectValue( "addRepositoryToGroup_repoId" , repositoryName );
100                         clickButtonWithValue( "Add Repository" );
101                 }
102         }
103         
104         public void deleteRepositoryInRepositoryGroups()
105         {
106                 goToRepositoryGroupsPage();
107                 getSelenium().click( "xpath=//div[@id='contentArea']/div[2]/div/div[3]/div[1]/a/img" );
108                 waitPage();
109         }
110         
111         public void deleteRepositoryGroup( String repositoryName )
112         {
113                 getSelenium().click( "xpath=//div[@id='contentArea']/div[2]/div/div[1]/div/a/img" );
114                 waitPage();
115                 assertDeleteRepositoryGroupPage( repositoryName );
116                 clickButtonWithValue( "Confirm" );
117         }
118         
119         ///////////////////////////////
120         // proxy connectors
121         ///////////////////////////////
122         public void goToProxyConnectorsPage()
123         {
124                 clickLinkWithText( "Proxy Connectors" );
125                 assertProxyConnectorsPage();
126         }
127         
128         public void assertProxyConnectorsPage()
129         {
130                 assertPage( "Apache Archiva \\ Administration - Proxy Connectors" );
131                 assertTextPresent( "Administration - Proxy Connectors" );
132                 assertTextPresent( "Repository Proxy Connectors" );
133                 assertTextPresent( "internal" );
134                 assertTextPresent( "Archiva Managed Internal Repository" );
135                 assertTextPresent( "Proxy Connector" );
136                 assertTextPresent( "Central Repository" );
137                 assertTextPresent( "Java.net Repository for Maven 2" );
138         }
139         
140         public void assertAddProxyConnectorPage()
141         {
142                 assertPage( "Apache Archiva \\ Admin: Add Proxy Connector" );
143                 assertTextPresent( "Admin: Add Proxy Connector" );
144                 String proxy = "Network Proxy*:,Managed Repository*:,Remote Repository*:,Policies:,Return error when:,On remote error:,Releases:,Snapshots:,Checksum:,Cache failures:,Properties:,No properties have been set.,Black List:,No black list patterns have been set.,White List:,No white list patterns have been set.";
145                 String[] arrayProxy = proxy.split( "," );
146                 for ( String arrayproxy : arrayProxy )
147                         assertTextPresent( arrayproxy );
148                 /*String proxyElements = "addProxyConnector_connector_proxyId,addProxyConnector_connector_sourceRepoId,addProxyConnector_connector_targetRepoId,policy_propagate-errors-on-update,policy_propagate-errors,policy_releases,policy_snapshots,policy_checksum,policy_cache-failures,propertiesEntry,propertiesValue,blackListEntry,whiteListEntry";
149                 String[] arrayProxyElements = proxyElements.split( "," );
150                 for ( String arrayproxyelements : arrayProxyElements )
151                         assertTextPresent( arrayproxyelements );*/
152                 assertButtonWithValuePresent( "Add Property" );
153                 assertButtonWithValuePresent( "Add Pattern" );
154                 assertButtonWithValuePresent( "Add Proxy Connector" );
155         }
156         
157         // this only fills in the values of required fields in adding Proxy Connectors
158         public void addProxyConnector( String networkProxy, String managedRepo, String remoteRepo )
159         {
160                 goToProxyConnectorsPage();
161                 clickLinkWithText( "Add" );
162                 assertAddProxyConnectorPage();
163                 selectValue( "connector.proxyId" , networkProxy );
164                 selectValue( "connector.sourceRepoId" , managedRepo );
165                 selectValue( "connector.targetRepoId" , remoteRepo );
166         }
167         
168         public void deleteProxyConnector()
169         {
170                 goToProxyConnectorsPage();
171                 clickLinkWithXPath( "//div[@id='contentArea']/div[2]/div[1]/div[2]/div[1]/a[3]/img" );
172                 assertPage( "Apache Archiva \\ Admin: Delete Proxy Connectors" );
173                 clickButtonWithValue( "Delete" );
174                 assertPage( "Apache Archiva \\ Administration - Proxy Connectors" );
175         }
176         
177         ///////////////////////////////
178         // network proxies
179         ///////////////////////////////
180         public void goToNetworkProxiesPage()
181         {
182                 clickLinkWithText( "Network Proxies" );
183                 assertNetworkProxiesPage();
184         }
185         
186         public void assertNetworkProxiesPage()
187         {
188                 assertPage( "Apache Archiva \\ Administration - Network Proxies" );
189                 assertTextPresent( "Administration - Network Proxies" );
190                 assertTextPresent( "Network Proxies" );
191                 assertLinkPresent( "Add Network Proxy" );
192         }
193         
194         public void assertAddNetworkProxy()
195         {
196                 assertPage( "Apache Archiva \\ Admin: Add Network Proxy" );
197                 assertTextPresent( "Admin: Add Network Proxy" );
198                 assertTextPresent( "Add network proxy:" );
199                 assertTextPresent( "Identifier*:" );
200                 assertTextPresent( "Protocol*:" );
201                 assertTextPresent( "Hostname*:" );
202                 assertTextPresent( "Port*:" );
203                 assertTextPresent( "Username:" );
204                 assertTextPresent( "Password:" );
205                 assertButtonWithValuePresent( "Save Network Proxy" );
206         }
207         
208         public void addNetworkProxy( String identifier, String protocol, String hostname, String port, String username, String password )
209         {
210                 //goToNetworkProxiesPage();
211                 clickLinkWithText( "Add Network Proxy" );
212                 assertAddNetworkProxy();
213                 setFieldValue( "proxy.id" , identifier );
214                 setFieldValue( "proxy.protocol" , protocol );
215                 setFieldValue( "proxy.host" , hostname );
216                 setFieldValue( "proxy.port" , port );
217                 setFieldValue( "proxy.username" , username );
218                 setFieldValue( "proxy.password" , password );
219                 clickButtonWithValue( "Save Network Proxy" );
220         }
221         
222         public void editNetworkProxies( String fieldName, String value)
223         {
224                 //goToNetworkProxiesPage();
225                 clickLinkWithText( "Edit Network Proxy" );
226                 setFieldValue( fieldName, value);
227                 clickButtonWithValue( "Save Network Proxy" );
228         }
229         
230         public void deleteNetworkProxy()
231         {
232                 //goToNetworkProxiesPage();
233                 clickLinkWithText( "Delete Network Proxy" );
234                 assertPage( "Apache Archiva \\ Admin: Delete Network Proxy" );
235                 assertTextPresent( "WARNING: This operation can not be undone." );
236                 clickButtonWithValue( "Delete" );
237         }
238         
239         // remote repositories
240         public void assertAddRemoteRepository()
241         {
242                 assertPage( "Apache Archiva \\ Admin: Add Remote Repository" );
243                 String remote = "Identifier*:,Name*:,URL*:,Username:,Password:,Timeout in seconds:,Type:";
244                 String[] arrayRemote = remote.split( "," );
245                 for ( String arrayremote : arrayRemote )
246                         assertTextPresent( arrayremote );
247                 String remoteElements = "addRemoteRepository_repository_id,addRemoteRepository_repository_name,addRemoteRepository_repository_url,addRemoteRepository_repository_username,addRemoteRepository_repository_password,addRemoteRepository_repository_timeout,addRemoteRepository_repository_layout";
248                 String[] arrayRemoteElements = remoteElements.split( "," );
249                 for ( String arrayremotelement : arrayRemoteElements )
250                         assertElementPresent( arrayremotelement );
251         }
252         
253         public void assertDeleteRemoteRepositoryPage()
254         {
255                 assertPage( "Apache Archiva \\ Admin: Delete Remote Repository" );
256                 assertTextPresent( "Admin: Delete Remote Repository" );
257                 assertTextPresent( "WARNING: This operation can not be undone." );
258                 assertTextPresent( "Are you sure you want to delete the following remote repository?" );
259                 assertButtonWithValuePresent( "Confirm" );
260                 assertButtonWithValuePresent( "Cancel" );
261         }
262         
263         public void addRemoteRepository( String identifier, String name, String url, String username, String password, String timeout, String type )
264         {
265                         //goToRepositoriesPage();
266                         assertAddRemoteRepository();
267                         setFieldValue( "addRemoteRepository_repository_id" ,  identifier );
268                         setFieldValue( "addRemoteRepository_repository_name" , name );
269                         setFieldValue( "addRemoteRepository_repository_url" , url );
270                         setFieldValue( "addRemoteRepository_repository_username" , username );
271                         setFieldValue( "addRemoteRepository_repository_password" , password );
272                         setFieldValue( "addRemoteRepository_repository_timeout" , timeout );
273                         selectValue( "addRemoteRepository_repository_layout" , type );
274                         clickButtonWithValue( "Add Repository" );
275         }
276         
277         public void deleteRemoteRepository()
278         {
279                 goToRepositoriesPage();
280                 clickLinkWithXPath( "//div[@id='contentArea']/div/div[8]/div[1]/a[2]" );
281                 assertDeleteRemoteRepositoryPage();
282                 clickButtonWithValue( "Confirm" );
283         }
284         
285         public void editRemoteRepository( String fieldName, String value)
286         {
287                 goToRepositoriesPage();
288                 clickLinkWithXPath( "//div[@id='contentArea']/div/div[8]/div[1]/a[1]" );
289                 setFieldValue( fieldName, value );
290                 clickButtonWithValue( "Update Repository" );
291         }
292         
293         public void editManagedRepository( String fieldName, String value )
294         {           
295                 goToRepositoriesPage();
296                 clickLinkWithXPath( "//div[@id='contentArea']/div/div[5]/div[1]/a[1]/img" );
297                 assertPage( "Apache Archiva \\ Admin: Edit Managed Repository" );
298                 setFieldValue(fieldName, value);
299                 //TODO
300                 clickButtonWithValue( "Update Repository" );
301         }
302         
303         public void deleteManagedRepository()
304         {
305                 clickLinkWithXPath( "//div[@id='contentArea']/div/div[5]/div[1]/a[2]" );
306                 assertPage( "Apache Archiva \\ Admin: Delete Managed Repository" );
307                 clickButtonWithValue( "Delete Configuration Only" );
308         }
309         
310         public String getRepositoryDir()
311         {
312                 File f = new File( "" );
313                 String artifactFilePath = f.getAbsolutePath();
314                 return artifactFilePath + "/target/";
315         }
316         
317         /////////////////////////////////////////////
318         // Repository Scanning
319         /////////////////////////////////////////////
320         public void goToRepositoryScanningPage()
321         {
322                 clickLinkWithText( "Repository Scanning" );
323                 assertRepositoryScanningPage();
324         }
325         
326         public void assertRepositoryScanningPage()
327         {
328                 assertPage( "Apache Archiva \\ Administration - Repository Scanning" );
329                 assertTextPresent( "Administration - Repository Scanning" );
330                 assertTextPresent( "Repository Scanning - File Types" );
331                 String artifactsTypes = "**/*.pom,**/*.jar,**/*.ear,**/*.war,**/*.car,**/*.sar,**/*.mar,**/*.rar,**/*.dtd,**/*.tld,**/*.tar.gz,**/*.tar.bz2,**/*.zip";
332                 String [] arrayArtifactTypes = artifactsTypes.split( "," );
333                 for (int i = 0; i < arrayArtifactTypes.length; i++)
334                         Assert.assertEquals(getSelenium().getTable("//div[@id='contentArea']/div/div[1]/table."+i+".0"), arrayArtifactTypes[i]);
335                 
336                 String autoremove = "**/*.bak,**/*~,**/*-";
337                 String [] arrayAutoremove = autoremove.split( "," );
338                 for (int i = 0; i < arrayAutoremove.length; i++)
339                         Assert.assertEquals(getSelenium().getTable("//div[@id='contentArea']/div/div[2]/table."+i+".0"), arrayAutoremove[i]);
340                 
341                 String ignored = "**/.htaccess,**/KEYS,**/*.rb,**/*.sh,**/.svn/**,**/.DAV/**";
342                 String [] arrayIgnored = ignored.split( "," );
343                 for (int i = 0; i < arrayIgnored.length; i++)
344                         Assert.assertEquals(getSelenium().getTable("//div[@id='contentArea']/div/div[3]/table."+i+".0"), arrayIgnored[i]);
345                 
346                 String indexableContent = "**/*.txt,**/*.TXT,**/*.block,**/*.config,**/*.pom,**/*.xml,**/*.xsd,**/*.dtd,**/*.tld";
347                 String [] arrayIndexableContent = indexableContent.split( "," );
348                 for (int i = 0; i < arrayIndexableContent.length; i++)
349                         Assert.assertEquals(getSelenium().getTable("//div[@id='contentArea']/div/div[4]/table."+i+".0"), arrayIndexableContent[i]);
350         }
351         
352         /////////////////////////////////////////////
353         // Database
354         /////////////////////////////////////////////
355         public void goToDatabasePage()
356         {
357                 clickLinkWithText( "Database" );
358                 assertDatabasePage();
359         }
360         
361         public void assertDatabasePage()
362         {
363                 assertPage( "Apache Archiva \\ Administration - Database" );
364                 assertTextPresent( "Administration - Database" );
365                 assertTextPresent( "Database - Unprocessed Artifacts Scanning" );
366                 assertTextPresent( "Cron:" );
367                 assertElementPresent( "database_cron" );
368                 assertButtonWithValuePresent( "Update Cron" );
369                 assertButtonWithValuePresent( "Update Database Now" );
370                 assertTextPresent( "Database - Unprocessed Artifacts Scanning" );
371                 assertTextPresent( "Database - Artifact Cleanup Scanning" );
372         }
373 }