1 package org.apache.archiva.web.action.admin.connectors.proxy;
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
22 import com.opensymphony.xwork2.Action;
23 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
24 import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin;
25 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
26 import org.apache.archiva.configuration.ArchivaConfiguration;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.IndeterminateConfigurationException;
29 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
30 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
31 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
32 import org.apache.archiva.web.action.AbstractWebworkTestCase;
33 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
34 import org.easymock.MockControl;
35 import org.junit.Before;
36 import org.junit.Test;
38 * DeleteProxyConnectorActionTest
42 public class DeleteProxyConnectorActionTest
43 extends AbstractWebworkTestCase
45 private static final String TEST_TARGET_ID = "central";
47 private static final String TEST_SOURCE_ID = "corporate";
49 private DeleteProxyConnectorAction action;
51 private MockControl archivaConfigurationControl;
53 private ArchivaConfiguration archivaConfiguration;
62 action = (DeleteProxyConnectorAction) getActionProxy( "/admin/deleteProxyConnector.action" ).getAction();
64 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
65 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
66 ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
67 archivaConfiguration );
68 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
69 archivaConfiguration );
70 ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration(
71 archivaConfiguration );
75 public void testConfirmDelete()
78 expectConfigurationRequests( 1 );
79 archivaConfigurationControl.replay();
81 // Show the confirm the delete of proxy connector screen.
83 action.setSource( TEST_SOURCE_ID );
84 action.setTarget( TEST_TARGET_ID );
85 String status = action.confirmDelete();
86 assertEquals( Action.INPUT, status );
87 assertNoErrors( action );
91 public void testConfirmDeleteBadSourceOrTarget()
94 expectConfigurationRequests( 4 );
95 archivaConfigurationControl.replay();
97 // Attempt to show the confirm delete screen, but provide
98 // a bad source id or target id to actually delete
100 preRequest( action );
101 action.setSource( "bad-source" ); // id doesn't exist.
102 action.setTarget( "bad-target" ); // id doesn't exist.
103 String status = action.confirmDelete();
104 // Should have resulted in an error.
105 assertEquals( Action.ERROR, status );
106 assertHasErrors( action );
108 preRequest( action );
109 action.setSource( "bad" ); // Bad doesn't exist.
110 action.setTarget( TEST_TARGET_ID );
111 status = action.confirmDelete();
112 // Should have resulted in an error.
113 assertEquals( Action.ERROR, status );
114 assertHasErrors( action );
116 preRequest( action );
117 action.setSource( TEST_SOURCE_ID );
118 action.setTarget( "bad" ); // Bad doesn't exist.
119 status = action.confirmDelete();
120 // Should have resulted in an error.
121 assertEquals( Action.ERROR, status );
122 assertHasErrors( action );
126 public void testConfirmDeleteNoSourceOrTarget()
129 expectConfigurationRequests( 1 );
130 archivaConfigurationControl.replay();
132 // Attempt to show the confirm delete screen, but don't provide
133 // the source id or target id to actually delete
135 preRequest( action );
136 action.setSource( null ); // No source Id.
137 action.setTarget( null ); // No target Id.
138 String status = action.confirmDelete();
139 // Should have resulted in an error.
140 assertEquals( Action.ERROR, status );
141 assertHasErrors( action );
143 preRequest( action );
144 action.setSource( TEST_SOURCE_ID );
145 action.setTarget( null ); // No target Id.
146 status = action.confirmDelete();
147 // Should have resulted in an error.
148 assertEquals( Action.ERROR, status );
149 assertHasErrors( action );
151 preRequest( action );
152 action.setSource( null ); // No source Id.
153 action.setTarget( TEST_TARGET_ID );
154 status = action.confirmDelete();
155 // Should have resulted in an error.
156 assertEquals( Action.ERROR, status );
157 assertHasErrors( action );
161 public void testDelete()
164 expectConfigurationRequests( 5 );
165 archivaConfigurationControl.replay();
167 // Show the confirm the delete of proxy connector screen.
168 preRequest( action );
169 action.setSource( TEST_SOURCE_ID );
170 action.setTarget( TEST_TARGET_ID );
171 String status = action.confirmDelete();
172 assertEquals( Action.INPUT, status );
173 assertNoErrors( action );
175 // Perform the delete.
176 preRequest( action );
177 status = action.delete();
178 assertEquals( Action.SUCCESS, status );
179 assertNoErrors( action );
180 assertHasMessages( action );
182 // Test the configuration.
183 assertEquals( 0, archivaConfiguration.getConfiguration().getProxyConnectors().size() );
187 public void testSecureActionBundle()
190 expectConfigurationRequests( 1 );
191 archivaConfigurationControl.replay();
193 SecureActionBundle bundle = action.getSecureActionBundle();
194 assertTrue( bundle.requiresAuthentication() );
195 assertEquals( 1, bundle.getAuthorizationTuples().size() );
198 private Configuration createInitialConfiguration()
200 Configuration config = new Configuration();
202 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
203 managedRepo.setId( TEST_SOURCE_ID );
204 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
205 managedRepo.setReleases( true );
207 config.addManagedRepository( managedRepo );
209 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
210 remoteRepo.setId( TEST_TARGET_ID );
211 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
213 config.addRemoteRepository( remoteRepo );
215 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
216 connector.setSourceRepoId( TEST_SOURCE_ID );
217 connector.setTargetRepoId( TEST_TARGET_ID );
219 config.addProxyConnector( connector );
224 private void expectConfigurationRequests( int requestConfigCount )
225 throws org.apache.archiva.redback.components.registry.RegistryException, IndeterminateConfigurationException
227 Configuration config = createInitialConfiguration();
229 for ( int i = 0; i < requestConfigCount; i++ )
231 archivaConfiguration.getConfiguration();
232 archivaConfigurationControl.setReturnValue( config );
235 archivaConfiguration.save( config );