]> source.dussan.org Git - archiva.git/blob
5fde0bbc284386c431ad02cd47f91318e91a72fc
[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         archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
64         archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
65         action.setArchivaConfiguration( archivaConfiguration );
66     }
67
68     public void testSecureActionBundle()
69         throws Exception
70     {
71         expectConfigurationRequests( 3 );
72         archivaConfigurationControl.replay();
73
74         action.prepare();
75         SecureActionBundle bundle = action.getSecureActionBundle();
76         assertTrue( bundle.requiresAuthentication() );
77         assertEquals( 1, bundle.getAuthorizationTuples().size() );
78     }
79
80     public void testExecute()
81         throws Exception
82     {
83         expectConfigurationRequests( 3 );
84         archivaConfigurationControl.replay();
85
86         action.prepare();
87
88         String status = action.execute();
89         assertEquals( Action.SUCCESS, status );
90         assertNoErrors( action );
91         
92         assertNotNull( action.getProxyConnectorMap() );
93         assertNotNull( action.getRepoMap() );
94
95         assertEquals( 1, action.getProxyConnectorMap().size() );
96         assertEquals( 3, action.getRepoMap().size() );
97     }
98
99     private void expectConfigurationRequests( int requestConfigCount )
100         throws RegistryException, IndeterminateConfigurationException
101     {
102         Configuration config = createInitialConfiguration();
103
104         for ( int i = 0; i < requestConfigCount; i++ )
105         {
106             archivaConfiguration.getConfiguration();
107             archivaConfigurationControl.setReturnValue( config );
108         }
109
110         archivaConfiguration.save( config );
111     }
112
113     private Configuration createInitialConfiguration()
114     {
115         Configuration config = new Configuration();
116
117         ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration();
118         managedRepo.setId( CORPORATE );
119         managedRepo.setLayout( "${java.io.tmpdir}/archiva-test/managed-repo" );
120         managedRepo.setReleases( true );
121
122         config.addManagedRepository( managedRepo );
123
124         RemoteRepositoryConfiguration remoteRepo = new RemoteRepositoryConfiguration();
125         remoteRepo.setId( CENTRAL );
126         remoteRepo.setUrl( "http://repo1.maven.org/maven2/" );
127
128         config.addRemoteRepository( remoteRepo );
129
130         remoteRepo = new RemoteRepositoryConfiguration();
131         remoteRepo.setId( JAVAX );
132         remoteRepo.setUrl( "http://download.java.net/maven/2/" );
133
134         config.addRemoteRepository( remoteRepo );
135
136         ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
137         connector.setSourceRepoId( CORPORATE );
138         connector.setTargetRepoId( CENTRAL );
139
140         config.addProxyConnector( connector );
141
142         connector = new ProxyConnectorConfiguration();
143         connector.setSourceRepoId( CORPORATE );
144         connector.setTargetRepoId( JAVAX );
145
146         config.addProxyConnector( connector );
147
148         return config;
149     }
150 }