1 package org.apache.maven.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;
24 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
27 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
28 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
29 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
30 import org.apache.maven.archiva.web.action.AbstractWebworkTestCase;
31 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
32 import org.codehaus.plexus.registry.RegistryException;
33 import org.easymock.MockControl;
36 * DeleteProxyConnectorActionTest
40 public class DeleteProxyConnectorActionTest
41 extends AbstractWebworkTestCase
43 private static final String TEST_TARGET_ID = "central";
45 private static final String TEST_SOURCE_ID = "corporate";
47 private DeleteProxyConnectorAction action;
49 private MockControl archivaConfigurationControl;
51 private ArchivaConfiguration archivaConfiguration;
53 public void testConfirmDelete()
56 expectConfigurationRequests( 1 );
57 archivaConfigurationControl.replay();
59 // Show the confirm the delete of proxy connector screen.
61 action.setSource( TEST_SOURCE_ID );
62 action.setTarget( TEST_TARGET_ID );
63 String status = action.confirmDelete();
64 assertEquals( Action.INPUT, status );
65 assertNoErrors( action );
68 public void testConfirmDeleteBadSourceOrTarget()
71 expectConfigurationRequests( 4 );
72 archivaConfigurationControl.replay();
74 // Attempt to show the confirm delete screen, but provide
75 // a bad source id or target id to actually delete
78 action.setSource( "bad-source" ); // id doesn't exist.
79 action.setTarget( "bad-target" ); // id doesn't exist.
80 String status = action.confirmDelete();
81 // Should have resulted in an error.
82 assertEquals( Action.ERROR, status );
83 assertHasErrors( action );
86 action.setSource( "bad" ); // Bad doesn't exist.
87 action.setTarget( TEST_TARGET_ID );
88 status = action.confirmDelete();
89 // Should have resulted in an error.
90 assertEquals( Action.ERROR, status );
91 assertHasErrors( action );
94 action.setSource( TEST_SOURCE_ID );
95 action.setTarget( "bad" ); // Bad doesn't exist.
96 status = action.confirmDelete();
97 // Should have resulted in an error.
98 assertEquals( Action.ERROR, status );
99 assertHasErrors( action );
102 public void testConfirmDeleteNoSourceOrTarget()
105 expectConfigurationRequests( 1 );
106 archivaConfigurationControl.replay();
108 // Attempt to show the confirm delete screen, but don't provide
109 // the source id or target id to actually delete
111 preRequest( action );
112 action.setSource( null ); // No source Id.
113 action.setTarget( null ); // No target Id.
114 String status = action.confirmDelete();
115 // Should have resulted in an error.
116 assertEquals( Action.ERROR, status );
117 assertHasErrors( action );
119 preRequest( action );
120 action.setSource( TEST_SOURCE_ID );
121 action.setTarget( null ); // No target Id.
122 status = action.confirmDelete();
123 // Should have resulted in an error.
124 assertEquals( Action.ERROR, status );
125 assertHasErrors( action );
127 preRequest( action );
128 action.setSource( null ); // No source Id.
129 action.setTarget( TEST_TARGET_ID );
130 status = action.confirmDelete();
131 // Should have resulted in an error.
132 assertEquals( Action.ERROR, status );
133 assertHasErrors( action );
136 public void testDelete()
139 expectConfigurationRequests( 5 );
140 archivaConfigurationControl.replay();
142 // Show the confirm the delete of proxy connector screen.
143 preRequest( action );
144 action.setSource( TEST_SOURCE_ID );
145 action.setTarget( TEST_TARGET_ID );
146 String status = action.confirmDelete();
147 assertEquals( Action.INPUT, status );
148 assertNoErrors( action );
150 // Perform the delete.
151 preRequest( action );
152 status = action.delete();
153 assertEquals( Action.SUCCESS, status );
154 assertNoErrors( action );
155 assertHasMessages( action );
157 // Test the configuration.
158 assertEquals( 0, archivaConfiguration.getConfiguration().getProxyConnectors().size() );
161 public void testSecureActionBundle()
164 expectConfigurationRequests( 1 );
165 archivaConfigurationControl.replay();
167 SecureActionBundle bundle = action.getSecureActionBundle();
168 assertTrue( bundle.requiresAuthentication() );
169 assertEquals( 1, bundle.getAuthorizationTuples().size() );
172 private Configuration createInitialConfiguration()
174 Configuration config = new Configuration();
176 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
177 managedRepo.setId( TEST_SOURCE_ID );
178 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
179 managedRepo.setReleases( true );
181 config.addManagedRepository( managedRepo );
183 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
184 remoteRepo.setId( TEST_TARGET_ID );
185 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
187 config.addRemoteRepository( remoteRepo );
189 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
190 connector.setSourceRepoId( TEST_SOURCE_ID );
191 connector.setTargetRepoId( TEST_TARGET_ID );
193 config.addProxyConnector( connector );
198 private void expectConfigurationRequests( int requestConfigCount )
199 throws RegistryException, IndeterminateConfigurationException
201 Configuration config = createInitialConfiguration();
203 for ( int i = 0; i < requestConfigCount; i++ )
205 archivaConfiguration.getConfiguration();
206 archivaConfigurationControl.setReturnValue( config );
209 archivaConfiguration.save( config );
213 protected void setUp()
218 //action = (DeleteProxyConnectorAction) lookup( Action.class.getName(), "deleteProxyConnectorAction" );
220 action = (DeleteProxyConnectorAction) getActionProxy( "/admin/deleteProxyConnector.action" ).getAction();
222 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
223 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
224 action.setArchivaConfiguration( archivaConfiguration );