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.easymock.MockControl;
35 import java.util.Collections;
36 import org.junit.Before;
37 import org.junit.Test;
40 * DeleteRemoteRepositoryActionTest
44 public class DeleteRemoteRepositoryActionTest
45 extends AbstractActionTestCase
47 private static final String REPO_ID = "remote-repo-ident";
49 private DeleteRemoteRepositoryAction action;
51 private MockControl archivaConfigurationControl;
53 private ArchivaConfiguration archivaConfiguration;
62 //action = (DeleteRemoteRepositoryAction) lookup( Action.class.getName(), "deleteRemoteRepositoryAction" );
63 action = (DeleteRemoteRepositoryAction) getActionProxy( "/admin/deleteRemoteRepository.action" ).getAction();
65 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
66 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
68 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
69 archivaConfiguration );
73 public void testDeleteRemoteRepositoryConfirmation()
76 RemoteRepository originalRepository = createRepository();
77 Configuration configuration = createConfigurationForEditing( originalRepository );
79 archivaConfiguration.getConfiguration();
80 archivaConfigurationControl.setReturnValue( configuration, 3, 4 );
82 archivaConfigurationControl.replay();
84 action.setRepoid( REPO_ID );
87 assertEquals( REPO_ID, action.getRepoid() );
88 RemoteRepository repository = action.getRepository();
89 assertNotNull( repository );
90 assertRepositoryEquals( repository, createRepository() );
92 String status = action.confirmDelete();
93 assertEquals( Action.INPUT, status );
94 repository = action.getRepository();
95 assertRepositoryEquals( repository, createRepository() );
96 assertEquals( Collections.singletonList( originalRepository ),
97 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
101 public void testDeleteRemoteRepository()
102 throws org.apache.archiva.redback.components.registry.RegistryException, IndeterminateConfigurationException, RepositoryAdminException
104 Configuration configuration = createConfigurationForEditing( createRepository() );
105 configuration.addManagedRepository( createManagedRepository( "internal", "target/repo/internal" ) );
106 configuration.addManagedRepository( createManagedRepository( "snapshots", "target/repo/snapshots" ) );
107 configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID ) );
109 archivaConfiguration.getConfiguration();
110 archivaConfigurationControl.setReturnValue( configuration, 4 );
112 archivaConfiguration.save( configuration );
113 archivaConfigurationControl.replay();
115 action.setRepoid( REPO_ID );
118 assertEquals( REPO_ID, action.getRepoid() );
119 RemoteRepository repository = action.getRepository();
120 assertNotNull( repository );
121 assertRepositoryEquals( repository, createRepository() );
123 assertEquals( 1, configuration.getProxyConnectors().size() );
125 String status = action.delete();
126 assertEquals( Action.SUCCESS, status );
128 assertTrue( configuration.getRemoteRepositories().isEmpty() );
129 assertEquals( 0, configuration.getProxyConnectors().size() );
133 public void testDeleteRemoteRepositoryCancelled()
136 RemoteRepository originalRepository = createRepository();
137 Configuration configuration = createConfigurationForEditing( originalRepository );
139 archivaConfiguration.getConfiguration();
140 archivaConfigurationControl.setReturnValue( configuration, 4 );
142 archivaConfiguration.save( configuration );
143 archivaConfigurationControl.replay();
145 action.setRepoid( REPO_ID );
148 assertEquals( REPO_ID, action.getRepoid() );
149 RemoteRepository repositoryConfiguration = action.getRepository();
150 assertNotNull( repositoryConfiguration );
151 assertRepositoryEquals( repositoryConfiguration, createRepository() );
153 String status = action.execute();
154 assertEquals( Action.SUCCESS, status );
156 RemoteRepository repository = action.getRepository();
157 assertRepositoryEquals( repository, createRepository() );
158 assertEquals( Collections.singletonList( originalRepository ),
159 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
162 private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration )
164 Configuration configuration = new Configuration();
165 RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
166 conf.setId( repositoryConfiguration.getId() );
167 conf.setLayout( repositoryConfiguration.getLayout() );
168 conf.setUrl( repositoryConfiguration.getUrl() );
169 conf.setName( repositoryConfiguration.getName() );
170 configuration.addRemoteRepository( conf );
171 return configuration;
174 private RemoteRepository createRepository()
176 RemoteRepository r = new RemoteRepository();
178 populateRepository( r );
182 private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository actualRepository )
184 assertEquals( expectedRepository.getId(), actualRepository.getId() );
185 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
186 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
187 assertEquals( expectedRepository.getName(), actualRepository.getName() );
190 private ManagedRepositoryConfiguration createManagedRepository( String string, String testPath )
192 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
194 r.setName( "repo name" );
195 r.setLocation( testPath );
196 r.setLayout( "default" );
197 r.setRefreshCronExpression( "* 0/5 * * * ?" );
199 r.setRetentionCount( 0 );
200 r.setReleases( true );
201 r.setSnapshots( true );
202 r.setScanned( false );
203 r.setDeleteReleasedSnapshots( false );
207 private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
209 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
210 connector.setSourceRepoId( managedRepoId );
211 connector.setTargetRepoId( remoteRepoId );
216 private void populateRepository( RemoteRepository repository )
218 repository.setId( REPO_ID );
219 repository.setName( "repo name" );
220 repository.setUrl( "url" );
221 repository.setLayout( "default" );
224 // TODO: what about removing proxied content if a proxy is removed?