1 package org.apache.archiva.web.action.admin.repositories;
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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
22 import com.opensymphony.xwork2.Action;
23 import org.apache.archiva.admin.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.beans.RemoteRepository;
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.AbstractActionTestCase;
33 import org.codehaus.plexus.registry.RegistryException;
34 import org.easymock.MockControl;
36 import java.util.Collections;
39 * DeleteRemoteRepositoryActionTest
43 public class DeleteRemoteRepositoryActionTest
44 extends AbstractActionTestCase
46 private static final String REPO_ID = "remote-repo-ident";
48 private DeleteRemoteRepositoryAction action;
50 private MockControl archivaConfigurationControl;
52 private ArchivaConfiguration archivaConfiguration;
54 protected void setUp()
59 //action = (DeleteRemoteRepositoryAction) lookup( Action.class.getName(), "deleteRemoteRepositoryAction" );
60 action = (DeleteRemoteRepositoryAction) getActionProxy( "/admin/deleteRemoteRepository.action" ).getAction();
62 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
63 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
65 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
66 archivaConfiguration );
69 public void testDeleteRemoteRepositoryConfirmation()
72 RemoteRepository originalRepository = createRepository();
73 Configuration configuration = createConfigurationForEditing( originalRepository );
75 archivaConfiguration.getConfiguration();
76 archivaConfigurationControl.setReturnValue( configuration );
78 archivaConfiguration.getConfiguration();
79 archivaConfigurationControl.setReturnValue( configuration );
81 archivaConfigurationControl.replay();
83 action.setRepoid( REPO_ID );
86 assertEquals( REPO_ID, action.getRepoid() );
87 RemoteRepository repository = action.getRepository();
88 assertNotNull( repository );
89 assertRepositoryEquals( repository, createRepository() );
91 String status = action.confirmDelete();
92 assertEquals( Action.INPUT, status );
93 repository = action.getRepository();
94 assertRepositoryEquals( repository, createRepository() );
95 assertEquals( Collections.singletonList( originalRepository ),
96 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
99 public void testDeleteRemoteRepository()
100 throws RegistryException, IndeterminateConfigurationException, RepositoryAdminException
102 Configuration configuration = createConfigurationForEditing( createRepository() );
103 configuration.addManagedRepository( createManagedRepository( "internal", "target/repo/internal" ) );
104 configuration.addManagedRepository( createManagedRepository( "snapshots", "target/repo/snapshots" ) );
105 configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID ) );
107 archivaConfiguration.getConfiguration();
108 archivaConfigurationControl.setReturnValue( configuration, 4 );
110 archivaConfiguration.save( configuration );
111 archivaConfigurationControl.replay();
113 action.setRepoid( REPO_ID );
116 assertEquals( REPO_ID, action.getRepoid() );
117 RemoteRepository repository = action.getRepository();
118 assertNotNull( repository );
119 assertRepositoryEquals( repository, createRepository() );
121 assertEquals( 1, configuration.getProxyConnectors().size() );
123 String status = action.delete();
124 assertEquals( Action.SUCCESS, status );
126 assertTrue( configuration.getRemoteRepositories().isEmpty() );
127 assertEquals( 0, configuration.getProxyConnectors().size() );
130 public void testDeleteRemoteRepositoryCancelled()
133 RemoteRepository originalRepository = createRepository();
134 Configuration configuration = createConfigurationForEditing( originalRepository );
136 archivaConfiguration.getConfiguration();
137 archivaConfigurationControl.setReturnValue( configuration, 2 );
139 archivaConfiguration.save( configuration );
140 archivaConfigurationControl.replay();
142 action.setRepoid( REPO_ID );
145 assertEquals( REPO_ID, action.getRepoid() );
146 RemoteRepository repositoryConfiguration = action.getRepository();
147 assertNotNull( repositoryConfiguration );
148 assertRepositoryEquals( repositoryConfiguration, createRepository() );
150 String status = action.execute();
151 assertEquals( Action.SUCCESS, status );
153 RemoteRepository repository = action.getRepository();
154 assertRepositoryEquals( repository, createRepository() );
155 assertEquals( Collections.singletonList( originalRepository ),
156 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
159 private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration )
161 Configuration configuration = new Configuration();
162 RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
163 conf.setId( repositoryConfiguration.getId() );
164 conf.setLayout( repositoryConfiguration.getLayout() );
165 conf.setUrl( repositoryConfiguration.getUrl() );
166 conf.setName( repositoryConfiguration.getName() );
167 configuration.addRemoteRepository( conf );
168 return configuration;
171 private RemoteRepository createRepository()
173 RemoteRepository r = new RemoteRepository();
175 populateRepository( r );
179 private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository actualRepository )
181 assertEquals( expectedRepository.getId(), actualRepository.getId() );
182 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
183 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
184 assertEquals( expectedRepository.getName(), actualRepository.getName() );
187 private ManagedRepositoryConfiguration createManagedRepository( String string, String testPath )
189 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
191 r.setName( "repo name" );
192 r.setLocation( testPath );
193 r.setLayout( "default" );
194 r.setRefreshCronExpression( "* 0/5 * * * ?" );
196 r.setRetentionCount( 0 );
197 r.setReleases( true );
198 r.setSnapshots( true );
199 r.setScanned( false );
200 r.setDeleteReleasedSnapshots( false );
204 private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
206 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
207 connector.setSourceRepoId( managedRepoId );
208 connector.setTargetRepoId( remoteRepoId );
213 private void populateRepository( RemoteRepository repository )
215 repository.setId( REPO_ID );
216 repository.setName( "repo name" );
217 repository.setUrl( "url" );
218 repository.setLayout( "default" );
221 // TODO: what about removing proxied content if a proxy is removed?