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;
24 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.IndeterminateConfigurationException;
27 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
28 import org.codehaus.plexus.PlexusTestCase;
29 import org.codehaus.plexus.registry.RegistryException;
30 import org.easymock.MockControl;
32 import java.util.Collections;
35 * DeleteRemoteRepositoryActionTest
37 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
40 public class DeleteRemoteRepositoryActionTest
41 extends PlexusTestCase
43 private static final String REPO_ID = "remote-repo-ident";
45 private DeleteRemoteRepositoryAction action;
47 private MockControl archivaConfigurationControl;
49 private ArchivaConfiguration archivaConfiguration;
51 protected void setUp()
56 action = (DeleteRemoteRepositoryAction) lookup( Action.class.getName(), "deleteRemoteRepositoryAction" );
58 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
59 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
60 action.setArchivaConfiguration( archivaConfiguration );
63 public void testDeleteRemoteRepositoryConfirmation()
66 RemoteRepositoryConfiguration originalRepository = createRepository();
67 Configuration configuration = createConfigurationForEditing( originalRepository );
69 archivaConfiguration.getConfiguration();
70 archivaConfigurationControl.setReturnValue( configuration );
71 archivaConfigurationControl.replay();
73 action.setRepoid( REPO_ID );
76 assertEquals( REPO_ID, action.getRepoid() );
77 RemoteRepositoryConfiguration repository = action.getRepository();
78 assertNotNull( repository );
79 assertRepositoryEquals( repository, createRepository() );
81 String status = action.confirmDelete();
82 assertEquals( Action.INPUT, status );
83 repository = action.getRepository();
84 assertRepositoryEquals( repository, createRepository() );
85 assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
88 public void testDeleteRemoteRepository()
89 throws RegistryException, IndeterminateConfigurationException
91 Configuration configuration = createConfigurationForEditing( createRepository() );
93 archivaConfiguration.getConfiguration();
94 archivaConfigurationControl.setReturnValue( configuration );
95 archivaConfiguration.getConfiguration();
96 archivaConfigurationControl.setReturnValue( configuration );
98 archivaConfiguration.save( configuration );
99 archivaConfigurationControl.replay();
101 action.setRepoid( REPO_ID );
104 assertEquals( REPO_ID, action.getRepoid() );
105 RemoteRepositoryConfiguration repository = action.getRepository();
106 assertNotNull( repository );
107 assertRepositoryEquals( repository, createRepository() );
109 String status = action.delete();
110 assertEquals( Action.SUCCESS, status );
112 assertTrue( configuration.getRemoteRepositories().isEmpty() );
115 public void testDeleteRemoteRepositoryCancelled()
118 RemoteRepositoryConfiguration originalRepository = createRepository();
119 Configuration configuration = createConfigurationForEditing( originalRepository );
121 archivaConfiguration.getConfiguration();
122 archivaConfigurationControl.setReturnValue( configuration );
123 archivaConfiguration.getConfiguration();
124 archivaConfigurationControl.setReturnValue( configuration );
126 archivaConfiguration.save( configuration );
127 archivaConfigurationControl.replay();
129 action.setRepoid( REPO_ID );
132 assertEquals( REPO_ID, action.getRepoid() );
133 RemoteRepositoryConfiguration repositoryConfiguration = action.getRepository();
134 assertNotNull( repositoryConfiguration );
135 assertRepositoryEquals( repositoryConfiguration, createRepository() );
137 String status = action.execute();
138 assertEquals( Action.SUCCESS, status );
140 RemoteRepositoryConfiguration repository = action.getRepository();
141 assertRepositoryEquals( repository, createRepository() );
142 assertEquals( Collections.singletonList( originalRepository ), configuration.getRemoteRepositories() );
145 private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration )
147 Configuration configuration = new Configuration();
148 configuration.addRemoteRepository( repositoryConfiguration );
149 return configuration;
152 private RemoteRepositoryConfiguration createRepository()
154 RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
156 populateRepository( r );
160 private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
161 RemoteRepositoryConfiguration actualRepository )
163 assertEquals( expectedRepository.getId(), actualRepository.getId() );
164 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
165 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
166 assertEquals( expectedRepository.getName(), actualRepository.getName() );
169 private void populateRepository( RemoteRepositoryConfiguration repository )
171 repository.setId( REPO_ID );
172 repository.setName( "repo name" );
173 repository.setUrl( "url" );
174 repository.setLayout( "default" );
177 // TODO: what if there are proxy connectors attached to a deleted repository?
178 // TODO: what about removing proxied content if a proxy is removed?