]> source.dussan.org Git - archiva.git/blob
e76abcec9aacaa29ee959d0a6dbfe76f6a3c094c
[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 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
37 /**
38  * ProxyConnectorsActionTest
39  *
40  * @version $Id$
41  */
42 public class ProxyConnectorsActionTest
43     extends AbstractWebworkTestCase
44 {
45     private static final String JAVAX = "javax";
46
47     private static final String CENTRAL = "central";
48
49     private static final String CORPORATE = "corporate";
50
51     private ProxyConnectorsAction action;
52
53     private MockControl archivaConfigurationControl;
54
55     private ArchivaConfiguration archivaConfiguration;
56
57     @Override
58     protected void setUp()
59         throws Exception
60     {
61         super.setUp();
62
63         action = (ProxyConnectorsAction) getActionProxy( "/admin/proxyConnectors.action" ).getAction();
64
65         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
66         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
67         ( (DefaultManagedRepositoryAdmin) action.getManagedRepositoryAdmin() ).setArchivaConfiguration(
68             archivaConfiguration );
69         ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
70             archivaConfiguration );
71         ( (DefaultProxyConnectorAdmin) action.getProxyConnectorAdmin() ).setArchivaConfiguration(
72             archivaConfiguration );
73     }
74
75     public void testSecureActionBundle()
76         throws Exception
77     {
78         expectConfigurationRequests( 5 );
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         archivaConfiguration.getConfiguration();
112         archivaConfigurationControl.setReturnValue( config, requestConfigCount + 1 );
113
114         archivaConfiguration.save( config );
115     }
116
117     private Configuration createInitialConfiguration()
118     {
119         Configuration config = new Configuration();
120
121         ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
122         managedRepo.setId( CORPORATE );
123         managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
124         managedRepo.setReleases( true );
125
126         config.addManagedRepository( managedRepo );
127
128         RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
129         remoteRepo.setId( CENTRAL );
130         remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
131
132         config.addRemoteRepository( remoteRepo );
133
134         remoteRepo = new RemoteRepositoryConfiguration();
135         remoteRepo.setId( JAVAX );
136         remoteRepo.setUrl( "http://download.java.net/maven/2/" );
137
138         config.addRemoteRepository( remoteRepo );
139
140         ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
141         connector.setSourceRepoId( CORPORATE );
142         connector.setTargetRepoId( CENTRAL );
143
144         config.addProxyConnector( connector );
145
146         connector = new ProxyConnectorConfiguration();
147         connector.setSourceRepoId( CORPORATE );
148         connector.setTargetRepoId( JAVAX );
149
150         config.addProxyConnector( connector );
151
152         return config;
153     }
154 }