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