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 action = (ProxyConnectorsAction) getActionProxy("/admin/proxyConnectors.action" ).getAction();
65 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
66 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
67 action.setArchivaConfiguration( archivaConfiguration );
70 public void testSecureActionBundle()
73 expectConfigurationRequests( 3 );
74 archivaConfigurationControl.replay();
77 SecureActionBundle bundle = action.getSecureActionBundle();
78 assertTrue( bundle.requiresAuthentication() );
79 assertEquals( 1, bundle.getAuthorizationTuples().size() );
82 public void testExecute()
85 expectConfigurationRequests( 3 );
86 archivaConfigurationControl.replay();
90 String status = action.execute();
91 assertEquals( Action.SUCCESS, status );
92 assertNoErrors( action );
94 assertNotNull( action.getProxyConnectorMap() );
95 assertNotNull( action.getRepoMap() );
97 assertEquals( 1, action.getProxyConnectorMap().size() );
98 assertEquals( 3, action.getRepoMap().size() );
101 private void expectConfigurationRequests( int requestConfigCount )
102 throws RegistryException, IndeterminateConfigurationException
104 Configuration config = createInitialConfiguration();
106 for ( int i = 0; i < requestConfigCount; i++ )
108 archivaConfiguration.getConfiguration();
109 archivaConfigurationControl.setReturnValue( config );
112 archivaConfiguration.save( config );
115 private Configuration createInitialConfiguration()
117 Configuration config = new Configuration();
119 ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
120 managedRepo.setId( CORPORATE );
121 managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
122 managedRepo.setReleases( true );
124 config.addManagedRepository( managedRepo );
126 RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
127 remoteRepo.setId( CENTRAL );
128 remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
130 config.addRemoteRepository( remoteRepo );
132 remoteRepo = new RemoteRepositoryConfiguration();
133 remoteRepo.setId( JAVAX );
134 remoteRepo.setUrl( "http://download.java.net/maven/2/" );
136 config.addRemoteRepository( remoteRepo );
138 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
139 connector.setSourceRepoId( CORPORATE );
140 connector.setTargetRepoId( CENTRAL );
142 config.addProxyConnector( connector );
144 connector = new ProxyConnectorConfiguration();
145 connector.setSourceRepoId( CORPORATE );
146 connector.setTargetRepoId( JAVAX );
148 config.addProxyConnector( connector );