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 * ProxyConnectorsActionTest
40 public class ProxyConnectorsActionTest
41 extends AbstractWebworkTestCase
43 private static final String JAVAX = "javax";
45 private static final String CENTRAL = "central";
47 private static final String CORPORATE = "corporate";
49 private ProxyConnectorsAction action;
51 private MockControl archivaConfigurationControl;
53 private ArchivaConfiguration archivaConfiguration;
56 protected void setUp()
61 action = (ProxyConnectorsAction) lookup( Action.class.getName(), "proxyConnectorsAction" );
63 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
64 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
65 action.setArchivaConfiguration( archivaConfiguration );
68 public void testSecureActionBundle()
71 expectConfigurationRequests( 3 );
72 archivaConfigurationControl.replay();
75 SecureActionBundle bundle = action.getSecureActionBundle();
76 assertTrue( bundle.requiresAuthentication() );
77 assertEquals( 1, bundle.getAuthorizationTuples().size() );
80 public void testExecute()
83 expectConfigurationRequests( 3 );
84 archivaConfigurationControl.replay();
88 String status = action.execute();
89 assertEquals( Action.SUCCESS, status );
90 assertNoErrors( action );
92 assertNotNull( action.getProxyConnectorMap() );
93 assertNotNull( action.getRepoMap() );
95 assertEquals( 1, action.getProxyConnectorMap().size() );
96 assertEquals( 3, action.getRepoMap().size() );
99 private void expectConfigurationRequests( int requestConfigCount )
100 throws RegistryException, IndeterminateConfigurationException
102 Configuration config = createInitialConfiguration();
104 for ( int i = 0; i < requestConfigCount; i++ )
106 archivaConfiguration.getConfiguration();
107 archivaConfigurationControl.setReturnValue( config );
110 archivaConfiguration.save( config );
113 private Configuration createInitialConfiguration()
115 Configuration config = new Configuration();
117 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
118 managedRepo.setId( CORPORATE );
119 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
120 managedRepo.setReleases( true );
122 config.addManagedRepository( managedRepo );
124 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
125 remoteRepo.setId( CENTRAL );
126 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
128 config.addRemoteRepository( remoteRepo );
130 remoteRepo = new RemoteRepositoryConfiguration();
131 remoteRepo.setId( JAVAX );
132 remoteRepo.setUrl( "http://download.java.net/maven/2/" );
134 config.addRemoteRepository( remoteRepo );
136 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
137 connector.setSourceRepoId( CORPORATE );
138 connector.setTargetRepoId( CENTRAL );
140 config.addProxyConnector( connector );
142 connector = new ProxyConnectorConfiguration();
143 connector.setSourceRepoId( CORPORATE );
144 connector.setTargetRepoId( JAVAX );
146 config.addProxyConnector( connector );