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.xwork.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.plexus.redback.xwork.interceptor.SecureActionBundle;
32 import org.codehaus.plexus.registry.RegistryException;
33 import org.easymock.MockControl;
36 * ProxyConnectorsActionTest
38 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
41 public class ProxyConnectorsActionTest
42 extends AbstractWebworkTestCase
44 private static final String JAVAX = "javax";
46 private static final String CENTRAL = "central";
48 private static final String CORPORATE = "corporate";
50 private ProxyConnectorsAction action;
52 private MockControl archivaConfigurationControl;
54 private ArchivaConfiguration archivaConfiguration;
57 protected void setUp()
62 action = (ProxyConnectorsAction) lookup( Action.class.getName(), "proxyConnectorsAction" );
64 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
65 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
66 action.setArchivaConfiguration( archivaConfiguration );
69 public void testSecureActionBundle()
72 expectConfigurationRequests( 3 );
73 archivaConfigurationControl.replay();
76 SecureActionBundle bundle = action.getSecureActionBundle();
77 assertTrue( bundle.requiresAuthentication() );
78 assertEquals( 1, bundle.getAuthorizationTuples().size() );
81 public void testExecute()
84 expectConfigurationRequests( 3 );
85 archivaConfigurationControl.replay();
89 String status = action.execute();
90 assertEquals( Action.SUCCESS, status );
91 assertNoErrors( action );
93 assertNotNull( action.getProxyConnectorMap() );
94 assertNotNull( action.getRepoMap() );
96 assertEquals( 1, action.getProxyConnectorMap().size() );
97 assertEquals( 3, action.getRepoMap().size() );
100 private void expectConfigurationRequests( int requestConfigCount )
101 throws RegistryException, IndeterminateConfigurationException
103 Configuration config = createInitialConfiguration();
105 for ( int i = 0; i < requestConfigCount; i++ )
107 archivaConfiguration.getConfiguration();
108 archivaConfigurationControl.setReturnValue( config );
111 archivaConfiguration.save( config );
114 private Configuration createInitialConfiguration()
116 Configuration config = new Configuration();
118 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
119 managedRepo.setId( CORPORATE );
120 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
121 managedRepo.setReleases( true );
123 config.addManagedRepository( managedRepo );
125 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
126 remoteRepo.setId( CENTRAL );
127 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
129 config.addRemoteRepository( remoteRepo );
131 remoteRepo = new RemoteRepositoryConfiguration();
132 remoteRepo.setId( JAVAX );
133 remoteRepo.setUrl( "http://download.java.net/maven/2/" );
135 config.addRemoteRepository( remoteRepo );
137 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
138 connector.setSourceRepoId( CORPORATE );
139 connector.setTargetRepoId( CENTRAL );
141 config.addProxyConnector( connector );
143 connector = new ProxyConnectorConfiguration();
144 connector.setSourceRepoId( CORPORATE );
145 connector.setTargetRepoId( JAVAX );
147 config.addProxyConnector( connector );