]> source.dussan.org Git - archiva.git/blob
12adeb4983f4f24c054fb82277ad40a5d30fa4cb
[archiva.git] /
1 package org.apache.archiva.web.action.admin.connectors.proxy;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
22 import com.opensymphony.xwork2.Action;
23
24 import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin;
25 import org.apache.archiva.admin.repository.proxyconnector.DefaultProxyConnectorAdmin;
26 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
27 import org.apache.archiva.configuration.ArchivaConfiguration;
28 import org.apache.archiva.configuration.Configuration;
29 import org.apache.archiva.configuration.IndeterminateConfigurationException;
30 import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
31 import org.apache.archiva.configuration.ProxyConnectorConfiguration;
32 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
33 import org.apache.archiva.web.action.AbstractWebworkTestCase;
34 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
35 import org.codehaus.plexus.registry.RegistryException;
36 import org.easymock.MockControl;
37
38 /**
39  * ProxyConnectorsActionTest 
40  *
41  * @version $Id$
42  */
43 public class ProxyConnectorsActionTest
44     extends AbstractWebworkTestCase
45 {
46     private static final String JAVAX = "javax";
47
48     private static final String CENTRAL = "central";
49
50     private static final String CORPORATE = "corporate";
51
52     private ProxyConnectorsAction action;
53
54     private MockControl archivaConfigurationControl;
55
56     private ArchivaConfiguration archivaConfiguration;
57
58     @Override
59     protected void setUp()
60         throws Exception
61     {
62         super.setUp();
63
64         action = (ProxyConnectorsAction) getActionProxy("/admin/proxyConnectors.action" ).getAction();
65
66         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
67         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
68         ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
69             archivaConfiguration );
70         ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
71             archivaConfiguration );
72         ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration( archivaConfiguration );
73     }
74
75     public void testSecureActionBundle()
76         throws Exception
77     {
78         expectConfigurationRequests( 4 );
79         archivaConfigurationControl.replay();
80
81         action.prepare();
82         SecureActionBundle bundle = action.getSecureActionBundle();
83         assertTrue( bundle.requiresAuthentication() );
84         assertEquals( 1, bundle.getAuthorizationTuples().size() );
85     }
86
87     public void testExecute()
88         throws Exception
89     {
90         expectConfigurationRequests( 5 );
91         archivaConfigurationControl.replay();
92
93         action.prepare();
94
95         String status = action.execute();
96         assertEquals( Action.SUCCESS, status );
97         assertNoErrors( action );
98         
99         assertNotNull( action.getProxyConnectorMap() );
100         assertNotNull( action.getRepoMap() );
101
102         assertEquals( 1, action.getProxyConnectorMap().size() );
103         assertEquals( 3, action.getRepoMap().size() );
104     }
105
106     private void expectConfigurationRequests( int requestConfigCount )
107         throws RegistryException, IndeterminateConfigurationException
108     {
109         Configuration config = createInitialConfiguration();
110
111         for ( int i = 0; i < requestConfigCount; i++ )
112         {
113             archivaConfiguration.getConfiguration();
114             archivaConfigurationControl.setReturnValue( config );
115         }
116
117         archivaConfiguration.save( config );
118     }
119
120     private Configuration createInitialConfiguration()
121     {
122         Configuration config = new Configuration();
123
124         ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
125         managedRepo.setId( CORPORATE );
126         managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
127         managedRepo.setReleases( true );
128
129         config.addManagedRepository( managedRepo );
130
131         RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
132         remoteRepo.setId( CENTRAL );
133         remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
134
135         config.addRemoteRepository( remoteRepo );
136
137         remoteRepo = new RemoteRepositoryConfiguration();
138         remoteRepo.setId( JAVAX );
139         remoteRepo.setUrl( "http://download.java.net/maven/2/" );
140
141         config.addRemoteRepository( remoteRepo );
142
143         ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
144         connector.setSourceRepoId( CORPORATE );
145         connector.setTargetRepoId( CENTRAL );
146
147         config.addProxyConnector( connector );
148
149         connector = new ProxyConnectorConfiguration();
150         connector.setSourceRepoId( CORPORATE );
151         connector.setTargetRepoId( JAVAX );
152
153         config.addProxyConnector( connector );
154
155         return config;
156     }
157 }