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.xwork.Action;
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.Configuration;
25 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
26 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
27 import org.apache.maven.archiva.configuration.ProxyConnectorConfiguration;
28 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
29 import org.codehaus.plexus.registry.RegistryException;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31 import org.easymock.MockControl;
33 import java.util.Collections;
36 * DeleteRemoteRepositoryActionTest
38 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
41 public class DeleteRemoteRepositoryActionTest
42 extends PlexusInSpringTestCase
44 private static final String REPO_ID = "remote-repo-ident";
46 private DeleteRemoteRepositoryAction action;
48 private MockControl archivaConfigurationControl;
50 private ArchivaConfiguration archivaConfiguration;
52 protected void setUp()
57 action = (DeleteRemoteRepositoryAction) lookup( Action.class.getName(), "deleteRemoteRepositoryAction" );
59 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
60 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
61 action.setArchivaConfiguration( archivaConfiguration );
64 public void testDeleteRemoteRepositoryConfirmation()
67 RemoteRepositoryConfiguration originalRepository = createRepository();
68 Configuration configuration = createConfigurationForEditing( originalRepository );
70 archivaConfiguration.getConfiguration();
71 archivaConfigurationControl.setReturnValue( configuration );
72 archivaConfigurationControl.replay();
74 action.setRepoid( REPO_ID );
77 assertEquals( REPO_ID, action.getRepoid() );
78 RemoteRepositoryConfiguration repository = action.getRepository();
79 assertNotNull( repository );
80 assertRepositoryEquals( repository, createRepository() );
82 String status = action.confirmDelete();
83 assertEquals( Action.INPUT, status );
84 repository = action.getRepository();
85 assertRepositoryEquals( repository, createRepository() );
86 assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
89 public void testDeleteRemoteRepository()
90 throws RegistryException, IndeterminateConfigurationException
92 Configuration configuration = createConfigurationForEditing( createRepository() );
93 configuration.addManagedRepository( createManagedRepository( "internal", getTestPath( "target/repo/internal" ) ) );
94 configuration.addManagedRepository( createManagedRepository( "snapshots", getTestPath( "target/repo/snapshots" ) ) );
95 configuration.addProxyConnector( createProxyConnector( "internal", REPO_ID) );
97 archivaConfiguration.getConfiguration();
98 archivaConfigurationControl.setReturnValue( configuration, 4 );
100 archivaConfiguration.save( configuration );
101 archivaConfigurationControl.replay();
103 action.setRepoid( REPO_ID );
106 assertEquals( REPO_ID, action.getRepoid() );
107 RemoteRepositoryConfiguration repository = action.getRepository();
108 assertNotNull( repository );
109 assertRepositoryEquals( repository, createRepository() );
111 assertEquals( 1, configuration.getProxyConnectors().size() );
113 String status = action.delete();
114 assertEquals( Action.SUCCESS, status );
116 assertTrue( configuration.getRemoteRepositories().isEmpty() );
117 assertEquals( 0, configuration.getProxyConnectors().size() );
120 public void testDeleteRemoteRepositoryCancelled()
123 RemoteRepositoryConfiguration originalRepository = createRepository();
124 Configuration configuration = createConfigurationForEditing( originalRepository );
126 archivaConfiguration.getConfiguration();
127 archivaConfigurationControl.setReturnValue( configuration, 2 );
129 archivaConfiguration.save( configuration );
130 archivaConfigurationControl.replay();
132 action.setRepoid( REPO_ID );
135 assertEquals( REPO_ID, action.getRepoid() );
136 RemoteRepositoryConfiguration repositoryConfiguration = action.getRepository();
137 assertNotNull( repositoryConfiguration );
138 assertRepositoryEquals( repositoryConfiguration, createRepository() );
140 String status = action.execute();
141 assertEquals( Action.SUCCESS, status );
143 RemoteRepositoryConfiguration repository = action.getRepository();
144 assertRepositoryEquals( repository, createRepository() );
145 assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
148 private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration )
150 Configuration configuration = new Configuration();
151 configuration.addRemoteRepository( repositoryConfiguration );
152 return configuration;
155 private RemoteRepositoryConfiguration createRepository()
157 RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
159 populateRepository( r );
163 private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
164 RemoteRepositoryConfiguration actualRepository )
166 assertEquals( expectedRepository.getId(), actualRepository.getId() );
167 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
168 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
169 assertEquals( expectedRepository.getName(), actualRepository.getName() );
172 private ManagedRepositoryConfiguration createManagedRepository( String string, String testPath )
174 ManagedRepositoryConfiguration r = new ManagedRepositoryConfiguration();
176 r.setName( "repo name" );
177 r.setLocation( testPath );
178 r.setLayout( "default" );
179 r.setRefreshCronExpression( "* 0/5 * * * ?" );
181 r.setRetentionCount( 0 );
182 r.setReleases( true );
183 r.setSnapshots( true );
184 r.setScanned( false );
185 r.setDeleteReleasedSnapshots( false );
189 private ProxyConnectorConfiguration createProxyConnector( String managedRepoId, String remoteRepoId )
191 ProxyConnectorConfiguration connector = new ProxyConnectorConfiguration();
192 connector.setSourceRepoId( managedRepoId );
193 connector.setTargetRepoId( remoteRepoId );
198 private void populateRepository( RemoteRepositoryConfiguration repository )
200 repository.setId( REPO_ID );
201 repository.setName( "repo name" );
202 repository.setUrl( "url" );
203 repository.setLayout( "default" );
206 // TODO: what about removing proxied content if a proxy is removed?