]> source.dussan.org Git - archiva.git/blob
6732ee97c298a12f56c894cda166d38fce861631
[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.AbstractArchivaTest;
23 import org.testng.annotations.Test;
24
25 @Test( groups = { "auditlogsreport" }, dependsOnMethods = { "testWithCorrectUsernamePassword" } )
26 public class AuditLogsReportTest
27     extends AbstractArchivaTest
28 {
29     private void goToAuditLogReports()
30     {
31         getSelenium().open( "/archiva/report/queryAuditLogReport.action" );
32     }
33
34     private void assertAuditLogsReportPage()
35     {
36         assertPage( "Apache Archiva \\ Audit Log Report" );
37         assertTextPresent( "Audit Log Report" );
38
39         assertElementPresent( "repository" );
40         assertElementPresent( "groupId" );
41         assertElementPresent( "artifactId" );
42         assertElementPresent( "startDate" );
43         assertElementPresent( "endDate" );
44         assertElementPresent( "rowCount" );
45         assertButtonWithValuePresent( "View Audit Log" );
46     }
47
48     @Test( dependsOnMethods = { "testWithCorrectUsernamePassword" } )
49     public void testAuditLogsReport()
50     {
51         goToAuditLogReports();
52         assertAuditLogsReportPage();
53         assertTextPresent( "Latest Events" );
54     }
55
56     @Test( dependsOnMethods = { "testWithCorrectUsernamePassword" } )
57     public void testViewAuditLogsNoDataFound()
58     {
59         goToAuditLogReports();
60         assertAuditLogsReportPage();
61
62         setFieldValue( "groupId", "non.existing" );
63         submit();
64
65         assertPage( "Apache Archiva \\ Audit Log Report" );
66         assertTextPresent( "Results" );
67         assertTextPresent( "No audit logs found." );
68     }
69
70     // TODO: add test for adding via WebDAV
71     @Test( dependsOnMethods = { "testAddArtifactValidValues" }, groups = "requiresUpload" )
72     public void testViewAuditLogsDataFound()
73     {
74         goToAuditLogReports();
75         assertAuditLogsReportPage();
76
77         selectValue( "repository", "internal" );
78         setFieldValue( "groupId", getProperty( "VALIDARTIFACT_GROUPID" ) );
79         submit();
80
81         assertAuditLogsReportPage();
82         assertTextPresent( "Results" );
83         assertTextNotPresent( "No audit logs found." );
84         assertTextPresent(
85             getProperty( "VALIDARTIFACT_ARTIFACTID" ) + "-" + getProperty( "ARTIFACT_VERSION" ) + "." + getProperty(
86                 "ARTIFACT_PACKAGING" ) );
87         assertTextPresent( "Uploaded File" );
88         assertTextPresent( "internal" );
89         assertTextPresent( "admin" );
90     }
91
92     // TODO: add test for adding via WebDAV
93     @Test( dependsOnMethods = { "testAddArtifactValidValues" }, groups = "requiresUpload" )
94     public void testViewAuditLogsOnlyArtifactIdIsSpecified()
95     {
96         goToAuditLogReports();
97         assertAuditLogsReportPage();
98
99         selectValue( "repository", "internal" );
100         setFieldValue( "artifactId", getProperty( "AUDITLOGARTIFACT_ARTIFACTID" ) );
101         submit();
102
103         assertAuditLogsReportPage();
104         assertTextPresent( "If you specify an artifact ID, you must specify a group ID" );
105         assertTextNotPresent( "Results" );
106         assertTextNotPresent( "No audit logs found." );
107         assertTextNotPresent(
108             getProperty( "VALIDARTIFACT_ARTIFACTID" ) + "-" + getProperty( "ARTIFACT_VERSION" ) + "." + getProperty(
109                 "ARTIFACT_PACKAGING" ) );
110         assertTextNotPresent( "Uploaded File" );
111     }
112
113     // TODO: add test for adding via WebDAV
114     @Test( dependsOnMethods = { "testAddArtifactValidValues" }, groups = "requiresUpload" )
115     public void testViewAuditLogsForAllRepositories()
116     {
117         goToAuditLogReports();
118         assertAuditLogsReportPage();
119
120         selectValue( "repository", "all" );
121         submit();
122
123         assertAuditLogsReportPage();
124         assertTextPresent( "Results" );
125         assertTextNotPresent( "No audit logs found." );
126         assertTextPresent(
127             getProperty( "VALIDARTIFACT_ARTIFACTID" ) + "-" + getProperty( "ARTIFACT_VERSION" ) + "." + getProperty(
128                 "ARTIFACT_PACKAGING" ) );
129         assertTextPresent( "Uploaded File" );
130         assertTextPresent( "internal" );
131         assertTextPresent( "admin" );
132     }
133
134     @Test( dependsOnMethods = { "testAddArtifactValidValues", "testUserWithRepoManagerInternalRole" },
135            groups = "requiresUpload" )
136     public void testViewAuditLogsViewAuditEventsForManageableRepositoriesOnly()
137     {
138         String groupId = getProperty( "SNAPSHOT_GROUPID" );
139         String artifactId = getProperty( "SNAPSHOT_ARTIFACTID" );
140         String version = getProperty( "SNAPSHOT_VERSION" );
141         String repo = getProperty( "SNAPSHOT_REPOSITORYID" );
142         String packaging = getProperty( "SNAPSHOT_PACKAGING" );
143
144         addArtifact( groupId, artifactId, version, packaging, getProperty( "SNAPSHOT_ARTIFACTFILEPATH" ), repo, true );
145         assertTextPresent(
146             "Artifact '" + groupId + ":" + artifactId + ":" + version + "' was successfully deployed to repository '"
147                 + repo + "'" );
148
149         clickLinkWithText( "Logout" );
150
151         login( getProperty( "REPOMANAGER_INTERNAL_USERNAME" ), getUserRoleNewPassword() );
152
153         goToAuditLogReports();
154         assertAuditLogsReportPage();
155
156         selectValue( "repository", "all" );
157         submit();
158
159         assertAuditLogsReportPage();
160         assertTextPresent( "Results" );
161         assertTextNotPresent( "No audit logs found." );
162         assertTextPresent(
163             getProperty( "VALIDARTIFACT_ARTIFACTID" ) + "-" + getProperty( "ARTIFACT_VERSION" ) + "." + packaging );
164         assertTextPresent( "Uploaded File" );
165         assertTextPresent( "internal" );
166         assertTextPresent( "admin" );
167
168         assertTextNotPresent( artifactId + "-" + version + "." + packaging );
169         clickLinkWithText( "Logout" );
170         login( getProperty( "ADMIN_USERNAME" ), getProperty( "ADMIN_PASSWORD" ) );
171     }
172
173     // MRM-1304
174     @Test( dependsOnMethods = { "testAddArtifactValidValues" }, groups = "requiresUpload" )
175     public void testViewAuditLogsReportForGroupId()
176     {
177         String groupId = getProperty( "AUDITLOGARTIFACT_GROUPID" );
178         String artifactId = getProperty( "AUDITLOGARTIFACT_ARTIFACTID" );
179         String version = getProperty( "VERSION" );
180         String packaging = getProperty( "PACKAGING" );
181         String repositoryId = getProperty( "REPOSITORYID" );
182         String expectedArtifact = getProperty( "AUDITLOG_EXPECTED_ARTIFACT" );
183
184         addArtifact( groupId, artifactId, version, packaging, getProperty( "SNAPSHOT_ARTIFACTFILEPATH" ), repositoryId,
185                      true );
186
187         goToAuditLogReports();
188
189         selectValue( "repository", repositoryId );
190         setFieldValue( "groupId", groupId );
191         submit();
192
193         assertAuditLogsReportPage();
194         assertTextPresent( expectedArtifact );
195         assertTextPresent( repositoryId );
196     }
197 }