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;
36 import org.junit.Before;
37 import org.junit.Test;
40 * ProxyConnectorsActionTest
44 public class ProxyConnectorsActionTest
45 extends AbstractWebworkTestCase
47 private static final String JAVAX = "javax";
49 private static final String CENTRAL = "central";
51 private static final String CORPORATE = "corporate";
53 private ProxyConnectorsAction action;
55 private MockControl archivaConfigurationControl;
57 private ArchivaConfiguration archivaConfiguration;
66 action = (ProxyConnectorsAction) getActionProxy( "/admin/proxyConnectors.action" ).getAction();
68 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
69 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
70 ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
71 archivaConfiguration );
72 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
73 archivaConfiguration );
74 ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration(
75 archivaConfiguration );
79 public void testSecureActionBundle()
82 expectConfigurationRequests( 5 );
83 archivaConfigurationControl.replay();
86 SecureActionBundle bundle = action.getSecureActionBundle();
87 assertTrue( bundle.requiresAuthentication() );
88 assertEquals( 1, bundle.getAuthorizationTuples().size() );
92 public void testExecute()
95 expectConfigurationRequests( 5 );
96 archivaConfigurationControl.replay();
100 String status = action.execute();
101 assertEquals( Action.SUCCESS, status );
102 assertNoErrors( action );
104 assertNotNull( action.getProxyConnectorMap() );
105 assertNotNull( action.getRepoMap() );
107 assertEquals( 1, action.getProxyConnectorMap().size() );
108 assertEquals( 3, action.getRepoMap().size() );
111 private void expectConfigurationRequests( int requestConfigCount )
112 throws RegistryException, IndeterminateConfigurationException
114 Configuration config = createInitialConfiguration();
116 archivaConfiguration.getConfiguration();
117 archivaConfigurationControl.setReturnValue( config, requestConfigCount + 1 );
119 archivaConfiguration.save( config );
122 private Configuration createInitialConfiguration()
124 Configuration config = new Configuration();
126 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
127 managedRepo.setId( CORPORATE );
128 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
129 managedRepo.setReleases( true );
131 config.addManagedRepository( managedRepo );
133 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
134 remoteRepo.setId( CENTRAL );
135 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
137 config.addRemoteRepository( remoteRepo );
139 remoteRepo = new RemoteRepositoryConfiguration();
140 remoteRepo.setId( JAVAX );
141 remoteRepo.setUrl( "http://download.java.net/maven/2/" );
143 config.addRemoteRepository( remoteRepo );
145 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
146 connector.setSourceRepoId( CORPORATE );
147 connector.setTargetRepoId( CENTRAL );
149 config.addProxyConnector( connector );
151 connector = new ProxyConnectorConfiguration();
152 connector.setSourceRepoId( CORPORATE );
153 connector.setTargetRepoId( JAVAX );
155 config.addProxyConnector( connector );