]> source.dussan.org Git - archiva.git/blob
9018a4edaa09467af8c0495532adfeea659fd0b8
[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 testMetadataPageDisplay()
143     {
144         goToBrowsePage();
145         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
146         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
147         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
148         clickLinkWithText( "Metadata" );
149         
150         assertMinimalMetadataDisplay();
151     }
152     
153     public void testDeleteMetadataDependency()
154     {
155         String depArtifactId = "testArtifactId";
156         
157         goToBrowsePage();
158         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
159         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
160         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
161         clickLinkWithText( "Metadata" );
162         
163         assertMinimalMetadataDisplay();
164         assertTextPresent( "dependencies" );
165         assertTextPresent( depArtifactId );
166         
167         String xPath = "//li[contains(text(),'" + depArtifactId + "')]/a/img[contains(@src,'delete.gif')]";
168         clickLinkWithXPath( xPath );
169         
170         assertTextNotPresent( depArtifactId );
171     }
172     
173     public void testDeleteMetadataMailingList()
174     {
175         String listName = "test user list";
176         
177         goToBrowsePage();
178         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
179         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
180         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
181         clickLinkWithText( "Metadata" );
182         
183         assertMinimalMetadataDisplay();
184         assertTextPresent( "mailingLists" );
185         assertTextPresent( listName );
186         
187         String xPath = "//li[contains(text(),'" + listName + "')]/a/img[contains(@src,'delete.gif')]";
188         clickLinkWithXPath( xPath );
189         
190         assertTextNotPresent( listName );
191     }
192     
193     public void testDeleteMetadataLicense()
194     {
195         String licenseName = "Test License";
196         
197         goToBrowsePage();
198         clickLinkWithText( getProperty( "ARTIFACT_GROUPID" ) + "/" );
199         clickLinkWithText( getProperty( "ARTIFACT_ARTIFACTID" ) + "/" );
200         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
201         clickLinkWithText( "Metadata" );
202         
203         assertMinimalMetadataDisplay();
204         assertTextPresent( "licenses" );
205         assertTextPresent( licenseName );
206         
207         String xPath = "//li[contains(text(),'" + licenseName + "')]/a/img[contains(@src,'delete.gif')]";
208         clickLinkWithXPath( xPath );
209         
210         assertTextNotPresent( licenseName );
211         assertTextNotPresent( "licenses" );
212     }
213     
214     private void assertMinimalMetadataDisplay()
215     {
216         assertTextPresent( "project.metadata.id=" );
217         assertTextPresent( "project.url=" );
218         assertTextPresent( "project.name=" );
219         assertTextPresent( "project.description=" );
220     }
221
222     private void assertArtifactInfoPage( String version, String artifactInfoRepositoryId, String artifactInfoGroupId,
223                                          String artifactInfoArtifactId, String artifactInfoVersion,
224                                          String artifactInfoPackaging )
225     {
226         clickLinkWithText( version );
227         assertPage( "Apache Archiva \\ Browse Repository" );
228         assertTextPresent( artifactInfoRepositoryId );
229         assertTextPresent( artifactInfoGroupId );
230         assertTextPresent( artifactInfoArtifactId );
231         assertTextPresent( artifactInfoVersion );
232         assertTextPresent( artifactInfoPackaging );
233     }
234
235     private void assertArtifactsPage( String artifactId )
236     {
237         clickLinkWithText( artifactId );
238         assertPage( "Apache Archiva \\ Browse Repository" );
239         assertTextPresent( "Versions" );
240     }
241
242     private void assertGroupsPage( String groupId )
243     {
244         clickLinkWithText( groupId );
245         assertPage( "Apache Archiva \\ Browse Repository" );
246         assertTextPresent( "Artifacts" );
247     }
248 }