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