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.components.registry.RegistryException;
34 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
35 import org.easymock.MockControl;
38 * ProxyConnectorsActionTest
42 public class ProxyConnectorsActionTest
43 extends AbstractWebworkTestCase
45 private static final String JAVAX = "javax";
47 private static final String CENTRAL = "central";
49 private static final String CORPORATE = "corporate";
51 private ProxyConnectorsAction action;
53 private MockControl archivaConfigurationControl;
55 private ArchivaConfiguration archivaConfiguration;
58 protected void setUp()
63 action = (ProxyConnectorsAction) getActionProxy( "/admin/proxyConnectors.action" ).getAction();
65 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
66 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
67 ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
68 archivaConfiguration );
69 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
70 archivaConfiguration );
71 ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration(
72 archivaConfiguration );
75 public void testSecureActionBundle()
78 expectConfigurationRequests( 5 );
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 archivaConfiguration.getConfiguration();
112 archivaConfigurationControl.setReturnValue( config, requestConfigCount + 1 );
114 archivaConfiguration.save( config );
117 private Configuration createInitialConfiguration()
119 Configuration config = new Configuration();
121 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
122 managedRepo.setId( CORPORATE );
123 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
124 managedRepo.setReleases( true );
126 config.addManagedRepository( managedRepo );
128 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
129 remoteRepo.setId( CENTRAL );
130 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
132 config.addRemoteRepository( remoteRepo );
134 remoteRepo = new RemoteRepositoryConfiguration();
135 remoteRepo.setId( JAVAX );
136 remoteRepo.setUrl( "http://download.java.net/maven/2/" );
138 config.addRemoteRepository( remoteRepo );
140 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
141 connector.setSourceRepoId( CORPORATE );
142 connector.setTargetRepoId( CENTRAL );
144 config.addProxyConnector( connector );
146 connector = new ProxyConnectorConfiguration();
147 connector.setSourceRepoId( CORPORATE );
148 connector.setTargetRepoId( JAVAX );
150 config.addProxyConnector( connector );