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