]> source.dussan.org Git - archiva.git/blob
ad37f07afef457f0ca6d8ca541865a1a99385ef3
[archiva.git] /
1 package org.apache.maven.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.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.struts2.interceptor.SecureActionBundle;
32 import org.codehaus.plexus.registry.RegistryException;
33 import org.easymock.MockControl;
34
35 /**
36  * ProxyConnectorsActionTest 
37  *
38  * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39  * @version $Id$
40  */
41 public class ProxyConnectorsActionTest
42     extends AbstractWebworkTestCase
43 {
44     private static final String JAVAX = "javax";
45
46     private static final String CENTRAL = "central";
47
48     private static final String CORPORATE = "corporate";
49
50     private ProxyConnectorsAction action;
51
52     private MockControl archivaConfigurationControl;
53
54     private ArchivaConfiguration archivaConfiguration;
55
56     @Override
57     protected void setUp()
58         throws Exception
59     {
60         super.setUp();
61
62         action = (ProxyConnectorsAction) lookup( Action.class.getName(), "proxyConnectorsAction" );
63
64         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
65         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
66         action.setArchivaConfiguration( archivaConfiguration );
67     }
68
69     public void testSecureActionBundle()
70         throws Exception
71     {
72         expectConfigurationRequests( 3 );
73         archivaConfigurationControl.replay();
74
75         action.prepare();
76         SecureActionBundle bundle = action.getSecureActionBundle();
77         assertTrue( bundle.requiresAuthentication() );
78         assertEquals( 1, bundle.getAuthorizationTuples().size() );
79     }
80
81     public void testExecute()
82         throws Exception
83     {
84         expectConfigurationRequests( 3 );
85         archivaConfigurationControl.replay();
86
87         action.prepare();
88
89         String status = action.execute();
90         assertEquals( Action.SUCCESS, status );
91         assertNoErrors( action );
92         
93         assertNotNull( action.getProxyConnectorMap() );
94         assertNotNull( action.getRepoMap() );
95
96         assertEquals( 1, action.getProxyConnectorMap().size() );
97         assertEquals( 3, action.getRepoMap().size() );
98     }
99
100     private void expectConfigurationRequests( int requestConfigCount )
101         throws RegistryException, IndeterminateConfigurationException
102     {
103         Configuration config = createInitialConfiguration();
104
105         for ( int i = 0; i < requestConfigCount; i++ )
106         {
107             archivaConfiguration.getConfiguration();
108             archivaConfigurationControl.setReturnValue( config );
109         }
110
111         archivaConfiguration.save( config );
112     }
113
114     private Configuration createInitialConfiguration()
115     {
116         Configuration config = new Configuration();
117
118         ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
119         managedRepo.setId( CORPORATE );
120         managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
121         managedRepo.setReleases( true );
122
123         config.addManagedRepository( managedRepo );
124
125         RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
126         remoteRepo.setId( CENTRAL );
127         remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
128
129         config.addRemoteRepository( remoteRepo );
130
131         remoteRepo = new RemoteRepositoryConfiguration();
132         remoteRepo.setId( JAVAX );
133         remoteRepo.setUrl( "http://download.java.net/maven/2/" );
134
135         config.addRemoteRepository( remoteRepo );
136
137         ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
138         connector.setSourceRepoId( CORPORATE );
139         connector.setTargetRepoId( CENTRAL );
140
141         config.addProxyConnector( connector );
142
143         connector = new ProxyConnectorConfiguration();
144         connector.setSourceRepoId( CORPORATE );
145         connector.setTargetRepoId( JAVAX );
146
147         config.addProxyConnector( connector );
148
149         return config;
150     }
151 }