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;
37 * DeleteProxyConnectorActionTest
41 public class DeleteProxyConnectorActionTest
42 extends AbstractWebworkTestCase
44 private static final String TEST_TARGET_ID = "central";
46 private static final String TEST_SOURCE_ID = "corporate";
48 private DeleteProxyConnectorAction action;
50 private MockControl archivaConfigurationControl;
52 private ArchivaConfiguration archivaConfiguration;
55 protected void setUp()
60 action = (DeleteProxyConnectorAction) getActionProxy( "/admin/deleteProxyConnector.action" ).getAction();
62 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
63 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
64 ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
65 archivaConfiguration );
66 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
67 archivaConfiguration );
68 ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration(
69 archivaConfiguration );
72 public void testConfirmDelete()
75 expectConfigurationRequests( 1 );
76 archivaConfigurationControl.replay();
78 // Show the confirm the delete of proxy connector screen.
80 action.setSource( TEST_SOURCE_ID );
81 action.setTarget( TEST_TARGET_ID );
82 String status = action.confirmDelete();
83 assertEquals( Action.INPUT, status );
84 assertNoErrors( action );
87 public void testConfirmDeleteBadSourceOrTarget()
90 expectConfigurationRequests( 4 );
91 archivaConfigurationControl.replay();
93 // Attempt to show the confirm delete screen, but provide
94 // a bad source id or target id to actually delete
97 action.setSource( "bad-source" ); // id doesn't exist.
98 action.setTarget( "bad-target" ); // id doesn't exist.
99 String status = action.confirmDelete();
100 // Should have resulted in an error.
101 assertEquals( Action.ERROR, status );
102 assertHasErrors( action );
104 preRequest( action );
105 action.setSource( "bad" ); // Bad doesn't exist.
106 action.setTarget( TEST_TARGET_ID );
107 status = action.confirmDelete();
108 // Should have resulted in an error.
109 assertEquals( Action.ERROR, status );
110 assertHasErrors( action );
112 preRequest( action );
113 action.setSource( TEST_SOURCE_ID );
114 action.setTarget( "bad" ); // Bad doesn't exist.
115 status = action.confirmDelete();
116 // Should have resulted in an error.
117 assertEquals( Action.ERROR, status );
118 assertHasErrors( action );
121 public void testConfirmDeleteNoSourceOrTarget()
124 expectConfigurationRequests( 1 );
125 archivaConfigurationControl.replay();
127 // Attempt to show the confirm delete screen, but don't provide
128 // the source id or target id to actually delete
130 preRequest( action );
131 action.setSource( null ); // No source Id.
132 action.setTarget( null ); // No target Id.
133 String status = action.confirmDelete();
134 // Should have resulted in an error.
135 assertEquals( Action.ERROR, status );
136 assertHasErrors( action );
138 preRequest( action );
139 action.setSource( TEST_SOURCE_ID );
140 action.setTarget( null ); // No target Id.
141 status = action.confirmDelete();
142 // Should have resulted in an error.
143 assertEquals( Action.ERROR, status );
144 assertHasErrors( action );
146 preRequest( action );
147 action.setSource( null ); // No source Id.
148 action.setTarget( TEST_TARGET_ID );
149 status = action.confirmDelete();
150 // Should have resulted in an error.
151 assertEquals( Action.ERROR, status );
152 assertHasErrors( action );
155 public void testDelete()
158 expectConfigurationRequests( 5 );
159 archivaConfigurationControl.replay();
161 // Show the confirm the delete of proxy connector screen.
162 preRequest( action );
163 action.setSource( TEST_SOURCE_ID );
164 action.setTarget( TEST_TARGET_ID );
165 String status = action.confirmDelete();
166 assertEquals( Action.INPUT, status );
167 assertNoErrors( action );
169 // Perform the delete.
170 preRequest( action );
171 status = action.delete();
172 assertEquals( Action.SUCCESS, status );
173 assertNoErrors( action );
174 assertHasMessages( action );
176 // Test the configuration.
177 assertEquals( 0, archivaConfiguration.getConfiguration().getProxyConnectors().size() );
180 public void testSecureActionBundle()
183 expectConfigurationRequests( 1 );
184 archivaConfigurationControl.replay();
186 SecureActionBundle bundle = action.getSecureActionBundle();
187 assertTrue( bundle.requiresAuthentication() );
188 assertEquals( 1, bundle.getAuthorizationTuples().size() );
191 private Configuration createInitialConfiguration()
193 Configuration config = new Configuration();
195 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
196 managedRepo.setId( TEST_SOURCE_ID );
197 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
198 managedRepo.setReleases( true );
200 config.addManagedRepository( managedRepo );
202 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
203 remoteRepo.setId( TEST_TARGET_ID );
204 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
206 config.addRemoteRepository( remoteRepo );
208 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
209 connector.setSourceRepoId( TEST_SOURCE_ID );
210 connector.setTargetRepoId( TEST_TARGET_ID );
212 config.addProxyConnector( connector );
217 private void expectConfigurationRequests( int requestConfigCount )
218 throws org.apache.archiva.redback.components.registry.RegistryException, IndeterminateConfigurationException
220 Configuration config = createInitialConfiguration();
222 for ( int i = 0; i < requestConfigCount; i++ )
224 archivaConfiguration.getConfiguration();
225 archivaConfigurationControl.setReturnValue( config );
228 archivaConfiguration.save( config );