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