1 package org.apache.maven.archiva.web.test;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
23 * Archiva's webapp UI test for adding/editing/deleting managed repositories.
26 public class ManagedRepositoryTest
27 extends AbstractArchivaTestCase
29 private static final String TEST_REPOSITORY_ID = "test-repository-id";
31 private static final String TEST_REPOSITORY_URL = "test-repository-url";
33 private static final String TEST_REPOSITORY_NAME = "test-repository-name";
35 private static final String TEST_REPOSITORY_DIRECTORY = "test-repository-directory";
38 private void clickManagedRepositories()
41 submitLoginPage( adminUsername, adminPassword );
43 clickLinkWithText( "Managed Repositories" );
44 assertPage( "Administration" );
45 assertTextPresent( "Administration" );
48 private void createManagedRepository( String id, String url, String name, String directory )
50 clickManagedRepositories();
52 clickLinkWithText( "Add Repository" );
53 assertTextPresent( "Configuration" );
55 setFieldValue( "addRepository_id", id );
56 setFieldValue( "urlName", url );
57 setFieldValue( "addRepository_name", name );
58 setFieldValue( "addRepository_directory", directory );
60 clickButtonWithValue( "Add Repository", false );
63 private void removeManagedRepository( String id )
67 clickManagedRepositories();
69 clickLinkWithLocator( "//a[contains(@href, '/admin/deleteRepository!input.action?repoId=" + id + "')]" );
70 clickLinkWithLocator( "deleteRepository_operationdelete-contents", false );
71 clickButtonWithValue( "Go" );
73 assertPage( "Administration" );
74 assertTextNotPresent( TEST_REPOSITORY_ID );
77 public void testAddRepositoryWithValidValues()
79 createManagedRepository( TEST_REPOSITORY_ID, TEST_REPOSITORY_URL, TEST_REPOSITORY_NAME, TEST_REPOSITORY_DIRECTORY );
82 assertPage( "Administration" );
83 assertTextPresent( TEST_REPOSITORY_ID );
85 removeManagedRepository( TEST_REPOSITORY_ID );
88 public void testAddRepositoryWithInvalidValues()
90 createManagedRepository( "", "", "", "" );
92 assertTextPresent( "You must enter the repository identifier." );
93 assertTextPresent( "You must enter the url name." );
94 assertTextPresent( "You must enter the repository name." );
95 assertTextPresent( "You must enter the repository directory." );
98 public void testEditRepositoryWithValidValues()
100 createManagedRepository( TEST_REPOSITORY_ID, TEST_REPOSITORY_URL, TEST_REPOSITORY_NAME, TEST_REPOSITORY_DIRECTORY );
103 assertPage( "Administration" );
104 assertTextPresent( TEST_REPOSITORY_NAME );
106 clickLinkWithLocator( "//a[contains(@href, '/admin/editRepository!input.action?repoId=" + TEST_REPOSITORY_ID + "')]" );
107 assertPage( "Configuration" );
108 assertTextPresent( "Configuration" );
110 assertTextPresent( "Edit Managed Repository" );
111 assertEquals( TEST_REPOSITORY_URL, getFieldValue( "urlName" ) );
112 assertEquals( TEST_REPOSITORY_NAME, getFieldValue( "editRepository_name" ) );
113 assertTrue( getFieldValue( "editRepository_directory" ).endsWith( TEST_REPOSITORY_DIRECTORY ) );
115 setFieldValue( "urlName", "edited-" + TEST_REPOSITORY_URL );
116 setFieldValue( "editRepository_name", "edited-" + TEST_REPOSITORY_NAME );
117 setFieldValue( "editRepository_directory", "edited-" + TEST_REPOSITORY_DIRECTORY );
119 clickButtonWithValue( "Update Repository" );
120 assertPage( "Administration" );
121 assertTextPresent( TEST_REPOSITORY_ID );
122 assertTextPresent( "edited-" + TEST_REPOSITORY_NAME );
124 removeManagedRepository( TEST_REPOSITORY_ID );
127 public void testEditRepositoryWithInvalidValues()
129 createManagedRepository( TEST_REPOSITORY_ID, TEST_REPOSITORY_URL, TEST_REPOSITORY_NAME, TEST_REPOSITORY_DIRECTORY );
132 assertPage( "Administration" );
133 assertTextPresent( TEST_REPOSITORY_NAME );
135 clickLinkWithLocator( "//a[contains(@href, '/admin/editRepository!input.action?repoId=" + TEST_REPOSITORY_ID + "')]" );
136 assertPage( "Configuration" );
137 assertTextPresent( "Configuration" );
139 assertTextPresent( "Edit Managed Repository" );
140 assertEquals( TEST_REPOSITORY_URL, getFieldValue( "urlName" ) );
141 assertEquals( TEST_REPOSITORY_NAME, getFieldValue( "editRepository_name" ) );
142 assertTrue( getFieldValue( "editRepository_directory" ).endsWith( TEST_REPOSITORY_DIRECTORY ) );
144 setFieldValue( "urlName", "" );
145 setFieldValue( "editRepository_name", "" );
146 setFieldValue( "editRepository_directory", "" );
148 clickButtonWithValue( "Update Repository", false );
149 assertTextPresent( "You must enter the url name." );
150 assertTextPresent( "You must enter the repository name." );
151 assertTextPresent( "You must enter the repository directory." );
153 removeManagedRepository( TEST_REPOSITORY_ID );
156 public void testDeleteRepositoryButLeaveUnmodified()
158 createManagedRepository( TEST_REPOSITORY_ID, TEST_REPOSITORY_URL, TEST_REPOSITORY_NAME, TEST_REPOSITORY_DIRECTORY );
161 assertPage( "Administration" );
162 assertTextPresent( TEST_REPOSITORY_ID );
164 clickLinkWithLocator( "//a[contains(@href, '/admin/deleteRepository!input.action?repoId=" + TEST_REPOSITORY_ID + "')]" );
165 clickLinkWithLocator( "deleteRepository_operationunmodified", false );
166 clickButtonWithValue( "Go" );
168 assertPage( "Administration" );
169 assertTextPresent( TEST_REPOSITORY_ID );
171 removeManagedRepository( TEST_REPOSITORY_ID );
174 public void testDeleteRepositoryAndContents()
176 createManagedRepository( TEST_REPOSITORY_ID, TEST_REPOSITORY_URL, TEST_REPOSITORY_NAME, TEST_REPOSITORY_DIRECTORY );
179 assertPage( "Administration" );
180 assertTextPresent( TEST_REPOSITORY_ID );
182 removeManagedRepository( TEST_REPOSITORY_ID );
185 public void testDeleteRepositoryButLeaveContentsUnmodified()
187 createManagedRepository( TEST_REPOSITORY_ID, TEST_REPOSITORY_URL, TEST_REPOSITORY_NAME, TEST_REPOSITORY_DIRECTORY );
190 assertPage( "Administration" );
191 assertTextPresent( TEST_REPOSITORY_ID );
193 clickLinkWithLocator( "//a[contains(@href, '/admin/deleteRepository!input.action?repoId=" + TEST_REPOSITORY_ID + "')]" );
194 clickLinkWithLocator( "deleteRepository_operationdelete-entry", false );
195 clickButtonWithValue( "Go" );
197 assertPage( "Administration" );
198 assertTextNotPresent( TEST_REPOSITORY_ID );