]> source.dussan.org Git - archiva.git/blob
12fc57ceec959d46acb381575a6e468e3da9de22
[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.AbstractBrowseTest;
23 import org.testng.Assert;
24 import org.testng.annotations.Test;
25
26 import java.io.File;
27
28 @Test( groups = { "browse" }, dependsOnMethods = { "testAddArtifactNullValues" } )
29 public class BrowseTest
30     extends AbstractBrowseTest
31 {
32     public void testBrowseArtifactPageTabs()
33     {
34         goToBrowsePage();
35         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
36         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
37         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
38
39         assertTextPresent( "Info" );
40         assertTextPresent( "Dependencies" );
41         assertTextPresent( "Dependency Tree" );
42         assertTextPresent( "Used By" );
43         assertTextPresent( "Mailing Lists" );
44         assertTextPresent( "Metadata" );
45     }
46
47     public void testBrowseArtifact()
48     {
49         goToBrowsePage();
50         assertBrowsePage();
51     }
52
53     @Test( dependsOnMethods = { "testAddArtifactValidValues" }, groups = { "requiresUpload" } )
54     public void testClickArtifactFromBrowse()
55     {
56         goToBrowsePage();
57         assertBrowsePage();
58         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
59         assertPage( "Apache Archiva \\ Browse Repository" );
60         assertTextPresent( "Artifacts" );
61     }
62
63     // MRM-1278
64     @Test( groups = { "requiresUpload" } )
65     public void testCorrectRepositoryInBrowse()
66     {
67         String releasesRepo = getProperty( "RELEASES_REPOSITORY" );
68
69         // create releases repository first
70         goToRepositoriesPage();
71         clickLinkWithText( "Add" );
72         addManagedRepository( getProperty( "RELEASES_REPOSITORY" ), "Releases Repository",
73                               new File( getBasedir(), "target/repository/releases" ).getPath(), "",
74                               "Maven 2.x Repository", "0 0 * * * ?", "", "", true );
75         assertTextPresent( "Releases Repository" );
76
77         String snapshotsRepo = getProperty( "SNAPSHOTS_REPOSITORY" );
78
79         String path =
80             "src/test/resources/snapshots/org/apache/maven/archiva/web/test/foo-bar/1.0-SNAPSHOT/foo-bar-1.0-SNAPSHOT.jar";
81         // TODO: do this differently as uploading doesn't work on browsers other than *chrome (below as well)
82         // upload a snapshot artifact to repository 'releases'
83         addArtifact( "archiva", "archiva-webapp", "1.0-SNAPSHOT", "jar", path, releasesRepo, true );
84         assertTextPresent(
85             "Artifact 'archiva:archiva-webapp:1.0-SNAPSHOT' was successfully deployed to repository '" + releasesRepo
86                 + "'" );
87
88         goToBrowsePage();
89         assertBrowsePage();
90         assertGroupsPage( "archiva/" );
91         assertArtifactsPage( "archiva-webapp/" );
92         assertArtifactInfoPage( "1.0-SNAPSHOT/", releasesRepo, "archiva", "archiva-webapp", "1.0-SNAPSHOT", "jar" );
93
94         // upload a snapshot artifact to repository 'snapshots'
95         addArtifact( "continuum", "continuum-core", "1.0-SNAPSHOT", "jar", path, snapshotsRepo, true );
96         assertTextPresent(
97             "Artifact 'continuum:continuum-core:1.0-SNAPSHOT' was successfully deployed to repository '" + snapshotsRepo
98                 + "'" );
99
100         goToBrowsePage();
101         assertBrowsePage();
102         assertGroupsPage( "continuum/" );
103         assertArtifactsPage( "continuum-core/" );
104         assertArtifactInfoPage( "1.0-SNAPSHOT/", snapshotsRepo, "continuum", "continuum-core", "1.0-SNAPSHOT", "jar" );
105     }
106
107     // MRM-1353
108     @Test( groups = { "requiresUpload" } )
109     public void testBuildNumberOfSnapshotArtifact()
110     {
111         String snapshotsRepo = getProperty( "SNAPSHOTS_REPOSITORY" );
112
113         String path =
114             "src/test/resources/snapshots/org/apache/maven/archiva/web/test/foo-bar/1.0-SNAPSHOT/foo-bar-1.0-SNAPSHOT.jar";
115         // TODO: do this differently as uploading doesn't work on browsers other than *chrome (below as well)
116         // upload a snapshot artifact to repository 'releases'
117         addArtifact( "archiva", "archiva-multiple-artifacts", "1.0-SNAPSHOT", "jar", path, snapshotsRepo, true );
118         assertTextPresent(
119             "Artifact 'archiva:archiva-multiple-artifacts:1.0-SNAPSHOT' was successfully deployed to repository '"
120                 + snapshotsRepo + "'" );
121
122         goToBrowsePage();
123         assertBrowsePage();
124         assertGroupsPage( "archiva/" );
125         assertArtifactsPage( "archiva-multiple-artifacts/" );
126         assertArtifactInfoPage( "1.0-SNAPSHOT/", snapshotsRepo, "archiva", "archiva-multiple-artifacts", "1.0-SNAPSHOT",
127                                 "jar" );
128
129         addArtifact( "archiva", "archiva-multiple-artifacts", "1.0-SNAPSHOT", "jar", path, snapshotsRepo, true );
130         assertTextPresent(
131             "Artifact 'archiva:archiva-multiple-artifacts:1.0-SNAPSHOT' was successfully deployed to repository '"
132                 + snapshotsRepo + "'" );
133
134         goToBrowsePage();
135         assertBrowsePage();
136         assertGroupsPage( "archiva/" );
137         assertArtifactsPage( "archiva-multiple-artifacts/" );
138         assertArtifactInfoPage( "1.0-SNAPSHOT/", snapshotsRepo, "archiva", "archiva-multiple-artifacts", "1.0-SNAPSHOT",
139                                 "jar" );
140
141         String firstSnapshotVersion = getText( "//div[@id='download']/div[@id='accordion']/p[2]/a/" );
142         Assert.assertTrue( firstSnapshotVersion.endsWith( "-1" ) );
143
144         String secondSnapshotVersion = getText( "//div[@id='download']/div[@id='accordion']/p[1]/a/" );
145         Assert.assertTrue( secondSnapshotVersion.endsWith( "-2" ) );
146     }
147
148     public void testAddMetadataPropertyEmpty()
149     {
150         goToBrowsePage();
151         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
152         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
153         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
154         clickLinkWithText( "Metadata" );
155
156         assertTextPresent( "No metadata content." );
157         assertButtonWithValuePresent( "Add" );
158
159         clickButtonWithValue( "Add" );
160
161         waitPage();
162
163         assertTextPresent( "Property Name and Property Value are required." );
164     }
165
166     @Test( dependsOnMethods = { "testAddMetadataPropertyEmpty" } )
167     public void testAddMetadataProperty()
168     {
169         addMetadataProperty();
170     }
171
172     @Test( dependsOnMethods = { "testAddMetadataProperty", "testWithCorrectUsernamePassword" } )
173     public void testDeleteMetadataProperty()
174     {
175         deleteMetadataProperty();
176     }
177
178     @Test( dependsOnMethods = { "testDeleteMetadataProperty" } )
179     public void testMetadataAccessWithRepositoryObserverRole()
180     {
181         addMetadataProperty();
182
183         logout();
184
185         goToBrowsePage();
186         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
187         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
188         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
189         clickLinkWithText( "Metadata" );
190
191         waitPage();
192
193         assertTextNotPresent( "No metadata content." );
194         assertButtonWithValueNotPresent( "Add" );
195         assertTextNotPresent( "Add Property" );
196         assertImgWithAltNotPresent( "Delete" );
197
198         login( getAdminUsername(), getAdminPassword() );
199
200         deleteMetadataProperty();
201     }
202
203     private void addMetadataProperty()
204     {
205         goToBrowsePage();
206         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
207         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
208         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
209         clickLinkWithText( "Metadata" );
210
211         assertTextPresent( "No metadata content." );
212         assertButtonWithValuePresent( "Add" );
213         assertTextPresent( "Add Property" );
214
215         setFieldValue( "propertyName", "foo" );
216         setFieldValue( "propertyValue", "bar" );
217
218         clickButtonWithValue( "Add" );
219
220         waitPage();
221
222         assertTextNotPresent( "No metadata content." );
223         assertTextPresent( "foo=bar" );
224     }
225
226     private void deleteMetadataProperty()
227     {
228         goToBrowsePage();
229         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
230         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
231         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
232         clickLinkWithText( "Metadata" );
233
234         assertTextPresent( "foo=bar" );
235         assertButtonWithValuePresent( "Add" );
236         assertTextPresent( "Add Property" );
237
238         clickImgWithAlt( "Delete" );
239
240         waitPage();
241
242         assertTextNotPresent( "foo=bar" );
243         assertTextPresent( "Property successfully deleted." );
244         assertImgWithAltNotPresent( "Delete" );
245         assertTextPresent( "No metadata content." );
246     }
247
248     private void assertArtifactInfoPage( String version, String artifactInfoRepositoryId, String artifactInfoGroupId,
249                                          String artifactInfoArtifactId, String artifactInfoVersion,
250                                          String artifactInfoPackaging )
251     {
252         clickLinkWithText( version );
253         assertPage( "Apache Archiva \\ Browse Repository" );
254         assertTextPresent( artifactInfoRepositoryId );
255         assertTextPresent( artifactInfoGroupId );
256         assertTextPresent( artifactInfoArtifactId );
257         assertTextPresent( artifactInfoVersion );
258         assertTextPresent( artifactInfoPackaging );
259     }
260
261     private void assertArtifactsPage( String artifactId )
262     {
263         clickLinkWithText( artifactId );
264         assertPage( "Apache Archiva \\ Browse Repository" );
265         assertTextPresent( "Versions" );
266     }
267
268     private void assertGroupsPage( String groupId )
269     {
270         clickLinkWithText( groupId );
271         assertPage( "Apache Archiva \\ Browse Repository" );
272         assertTextPresent( "Artifacts" );
273     }
274 }