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;
38 * DeleteRemoteRepositoryActionTest
42 public class DeleteRemoteRepositoryActionTest
43 extends AbstractActionTestCase
45 private static final String REPO_ID = "remote-repo-ident";
47 private DeleteRemoteRepositoryAction action;
49 private MockControl archivaConfigurationControl;
51 private ArchivaConfiguration archivaConfiguration;
53 protected void setUp()
58 //action = (DeleteRemoteRepositoryAction) lookup( Action.class.getName(), "deleteRemoteRepositoryAction" );
59 action = (DeleteRemoteRepositoryAction) getActionProxy( "/admin/deleteRemoteRepository.action" ).getAction();
61 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
62 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
64 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
65 archivaConfiguration );
68 public void testDeleteRemoteRepositoryConfirmation()
71 RemoteRepository originalRepository = createRepository();
72 Configuration configuration = createConfigurationForEditing( originalRepository );
74 archivaConfiguration.getConfiguration();
75 archivaConfigurationControl.setReturnValue( configuration, 3, 4 );
77 archivaConfigurationControl.replay();
79 action.setRepoid( REPO_ID );
82 assertEquals( REPO_ID, action.getRepoid() );
83 RemoteRepository repository = action.getRepository();
84 assertNotNull( repository );
85 assertRepositoryEquals( repository, createRepository() );
87 String status = action.confirmDelete();
88 assertEquals( Action.INPUT, status );
89 repository = action.getRepository();
90 assertRepositoryEquals( repository, createRepository() );
91 assertEquals( Collections.singletonList( originalRepository ),
92 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
95 public void testDeleteRemoteRepository()
96 throws org.apache.archiva.redback.components.registry.RegistryException, IndeterminateConfigurationException, RepositoryAdminException
98 Configuration configuration = createConfigurationForEditing( createRepository() );
99 configuration.addManagedRepository( createManagedRepository( "internal", "target/repo/internal" ) );
100 configuration.addManagedRepository( createManagedRepository( "snapshots", "target/repo/snapshots" ) );
101 configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID ) );
103 archivaConfiguration.getConfiguration();
104 archivaConfigurationControl.setReturnValue( configuration, 4 );
106 archivaConfiguration.save( configuration );
107 archivaConfigurationControl.replay();
109 action.setRepoid( REPO_ID );
112 assertEquals( REPO_ID, action.getRepoid() );
113 RemoteRepository repository = action.getRepository();
114 assertNotNull( repository );
115 assertRepositoryEquals( repository, createRepository() );
117 assertEquals( 1, configuration.getProxyConnectors().size() );
119 String status = action.delete();
120 assertEquals( Action.SUCCESS, status );
122 assertTrue( configuration.getRemoteRepositories().isEmpty() );
123 assertEquals( 0, configuration.getProxyConnectors().size() );
126 public void testDeleteRemoteRepositoryCancelled()
129 RemoteRepository originalRepository = createRepository();
130 Configuration configuration = createConfigurationForEditing( originalRepository );
132 archivaConfiguration.getConfiguration();
133 archivaConfigurationControl.setReturnValue( configuration, 4 );
135 archivaConfiguration.save( configuration );
136 archivaConfigurationControl.replay();
138 action.setRepoid( REPO_ID );
141 assertEquals( REPO_ID, action.getRepoid() );
142 RemoteRepository repositoryConfiguration = action.getRepository();
143 assertNotNull( repositoryConfiguration );
144 assertRepositoryEquals( repositoryConfiguration, createRepository() );
146 String status = action.execute();
147 assertEquals( Action.SUCCESS, status );
149 RemoteRepository repository = action.getRepository();
150 assertRepositoryEquals( repository, createRepository() );
151 assertEquals( Collections.singletonList( originalRepository ),
152 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
155 private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration )
157 Configuration configuration = new Configuration();
158 RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
159 conf.setId( repositoryConfiguration.getId() );
160 conf.setLayout( repositoryConfiguration.getLayout() );
161 conf.setUrl( repositoryConfiguration.getUrl() );
162 conf.setName( repositoryConfiguration.getName() );
163 configuration.addRemoteRepository( conf );
164 return configuration;
167 private RemoteRepository createRepository()
169 RemoteRepository r = new RemoteRepository();
171 populateRepository( r );
175 private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository actualRepository )
177 assertEquals( expectedRepository.getId(), actualRepository.getId() );
178 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
179 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
180 assertEquals( expectedRepository.getName(), actualRepository.getName() );
183 private ManagedRepositoryConfiguration createManagedRepository( String string, String testPath )
185 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
187 r.setName( "repo name" );
188 r.setLocation( testPath );
189 r.setLayout( "default" );
190 r.setRefreshCronExpression( "* 0/5 * * * ?" );
192 r.setRetentionCount( 0 );
193 r.setReleases( true );
194 r.setSnapshots( true );
195 r.setScanned( false );
196 r.setDeleteReleasedSnapshots( false );
200 private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
202 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
203 connector.setSourceRepoId( managedRepoId );
204 connector.setTargetRepoId( remoteRepoId );
209 private void populateRepository( RemoteRepository repository )
211 repository.setId( REPO_ID );
212 repository.setName( "repo name" );
213 repository.setUrl( "url" );
214 repository.setLayout( "default" );
217 // TODO: what about removing proxied content if a proxy is removed?