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;
24 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
25 import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin;
26 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
27 import org.apache.archiva.configuration.ArchivaConfiguration;
28 import org.apache.archiva.configuration.Configuration;
29 import org.apache.archiva.configuration.IndeterminateConfigurationException;
30 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
32 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
33 import org.apache.archiva.web.action.AbstractWebworkTestCase;
34 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
35 import org.codehaus.plexus.registry.RegistryException;
36 import org.easymock.MockControl;
39 * ProxyConnectorsActionTest
43 public class ProxyConnectorsActionTest
44 extends AbstractWebworkTestCase
46 private static final String JAVAX = "javax";
48 private static final String CENTRAL = "central";
50 private static final String CORPORATE = "corporate";
52 private ProxyConnectorsAction action;
54 private MockControl archivaConfigurationControl;
56 private ArchivaConfiguration archivaConfiguration;
59 protected void setUp()
64 action = (ProxyConnectorsAction) getActionProxy("/admin/proxyConnectors.action" ).getAction();
66 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
67 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
68 ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
69 archivaConfiguration );
70 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
71 archivaConfiguration );
72 ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( archivaConfiguration );
75 public void testSecureActionBundle()
78 expectConfigurationRequests( 4 );
79 archivaConfigurationControl.replay();
82 SecureActionBundle bundle = action.getSecureActionBundle();
83 assertTrue( bundle.requiresAuthentication() );
84 assertEquals( 1, bundle.getAuthorizationTuples().size() );
87 public void testExecute()
90 expectConfigurationRequests( 5 );
91 archivaConfigurationControl.replay();
95 String status = action.execute();
96 assertEquals( Action.SUCCESS, status );
97 assertNoErrors( action );
99 assertNotNull( action.getProxyConnectorMap() );
100 assertNotNull( action.getRepoMap() );
102 assertEquals( 1, action.getProxyConnectorMap().size() );
103 assertEquals( 3, action.getRepoMap().size() );
106 private void expectConfigurationRequests( int requestConfigCount )
107 throws RegistryException, IndeterminateConfigurationException
109 Configuration config = createInitialConfiguration();
111 for ( int i = 0; i < requestConfigCount; i++ )
113 archivaConfiguration.getConfiguration();
114 archivaConfigurationControl.setReturnValue( config );
117 archivaConfiguration.save( config );
120 private Configuration createInitialConfiguration()
122 Configuration config = new Configuration();
124 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
125 managedRepo.setId( CORPORATE );
126 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
127 managedRepo.setReleases( true );
129 config.addManagedRepository( managedRepo );
131 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
132 remoteRepo.setId( CENTRAL );
133 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
135 config.addRemoteRepository( remoteRepo );
137 remoteRepo = new RemoteRepositoryConfiguration();
138 remoteRepo.setId( JAVAX );
139 remoteRepo.setUrl( "http://download.java.net/maven/2/" );
141 config.addRemoteRepository( remoteRepo );
143 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
144 connector.setSourceRepoId( CORPORATE );
145 connector.setTargetRepoId( CENTRAL );
147 config.addProxyConnector( connector );
149 connector = new ProxyConnectorConfiguration();
150 connector.setSourceRepoId( CORPORATE );
151 connector.setTargetRepoId( JAVAX );
153 config.addProxyConnector( connector );