1 package org.apache.maven.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.repository.RepositoryAdminException;
24 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
25 import org.apache.archiva.admin.repository.remote.RemoteRepository;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
29 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
30 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
31 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
32 import org.apache.maven.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();
64 action.setArchivaConfiguration( archivaConfiguration );
66 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
67 archivaConfiguration );
70 public void testDeleteRemoteRepositoryConfirmation()
73 RemoteRepository originalRepository = createRepository();
74 Configuration configuration = createConfigurationForEditing( originalRepository );
76 archivaConfiguration.getConfiguration();
77 archivaConfigurationControl.setReturnValue( configuration );
79 archivaConfiguration.getConfiguration();
80 archivaConfigurationControl.setReturnValue( configuration );
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() );
100 public void testDeleteRemoteRepository()
101 throws RegistryException, IndeterminateConfigurationException, RepositoryAdminException
103 Configuration configuration = createConfigurationForEditing( createRepository() );
104 configuration.addManagedRepository( createManagedRepository( "internal", "target/repo/internal" ) );
105 configuration.addManagedRepository( createManagedRepository( "snapshots", "target/repo/snapshots" ) );
106 configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID ) );
108 archivaConfiguration.getConfiguration();
109 archivaConfigurationControl.setReturnValue( configuration, 4 );
111 archivaConfiguration.save( configuration );
112 archivaConfigurationControl.replay();
114 action.setRepoid( REPO_ID );
117 assertEquals( REPO_ID, action.getRepoid() );
118 RemoteRepository repository = action.getRepository();
119 assertNotNull( repository );
120 assertRepositoryEquals( repository, createRepository() );
122 assertEquals( 1, configuration.getProxyConnectors().size() );
124 String status = action.delete();
125 assertEquals( Action.SUCCESS, status );
127 assertTrue( configuration.getRemoteRepositories().isEmpty() );
128 assertEquals( 0, configuration.getProxyConnectors().size() );
131 public void testDeleteRemoteRepositoryCancelled()
134 RemoteRepository originalRepository = createRepository();
135 Configuration configuration = createConfigurationForEditing( originalRepository );
137 archivaConfiguration.getConfiguration();
138 archivaConfigurationControl.setReturnValue( configuration, 2 );
140 archivaConfiguration.save( configuration );
141 archivaConfigurationControl.replay();
143 action.setRepoid( REPO_ID );
146 assertEquals( REPO_ID, action.getRepoid() );
147 RemoteRepository repositoryConfiguration = action.getRepository();
148 assertNotNull( repositoryConfiguration );
149 assertRepositoryEquals( repositoryConfiguration, createRepository() );
151 String status = action.execute();
152 assertEquals( Action.SUCCESS, status );
154 RemoteRepository repository = action.getRepository();
155 assertRepositoryEquals( repository, createRepository() );
156 assertEquals( Collections.singletonList( originalRepository ),
157 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
160 private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration )
162 Configuration configuration = new Configuration();
163 RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
164 conf.setId( repositoryConfiguration.getId() );
165 conf.setLayout( repositoryConfiguration.getLayout() );
166 conf.setUrl( repositoryConfiguration.getUrl() );
167 conf.setName( repositoryConfiguration.getName() );
168 configuration.addRemoteRepository( conf );
169 return configuration;
172 private RemoteRepository createRepository()
174 RemoteRepository r = new RemoteRepository();
176 populateRepository( r );
180 private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository actualRepository )
182 assertEquals( expectedRepository.getId(), actualRepository.getId() );
183 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
184 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
185 assertEquals( expectedRepository.getName(), actualRepository.getName() );
188 private ManagedRepositoryConfiguration createManagedRepository( String string, String testPath )
190 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
192 r.setName( "repo name" );
193 r.setLocation( testPath );
194 r.setLayout( "default" );
195 r.setRefreshCronExpression( "* 0/5 * * * ?" );
197 r.setRetentionCount( 0 );
198 r.setReleases( true );
199 r.setSnapshots( true );
200 r.setScanned( false );
201 r.setDeleteReleasedSnapshots( false );
205 private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
207 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
208 connector.setSourceRepoId( managedRepoId );
209 connector.setTargetRepoId( remoteRepoId );
214 private void populateRepository( RemoteRepository repository )
216 repository.setId( REPO_ID );
217 repository.setName( "repo name" );
218 repository.setUrl( "url" );
219 repository.setLayout( "default" );
222 // TODO: what about removing proxied content if a proxy is removed?