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.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.group.RepositoryGroup;
25 import org.apache.archiva.admin.repository.group.DefaultRepositoryGroupAdmin;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
29 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
30 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
31 import org.codehaus.redback.integration.interceptor.SecureActionException;
32 import org.easymock.MockControl;
34 import java.util.Collections;
37 * DeleteRepositoryGroupActionTest
39 public class DeleteRepositoryGroupActionTest
40 extends AbstractActionTestCase
42 private static final String REPO_GROUP_ID = "repo-group-ident";
44 private DeleteRepositoryGroupAction action;
46 private MockControl archivaConfigurationControl;
48 private ArchivaConfiguration archivaConfiguration;
50 protected void setUp()
55 action = (DeleteRepositoryGroupAction) getActionProxy( "/admin/deleteRepositoryGroup.action" ).getAction();
57 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
58 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
59 action.setArchivaConfiguration( archivaConfiguration );
61 ( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).setArchivaConfiguration(
62 archivaConfiguration );
65 public void testSecureActionBundle()
66 throws SecureActionException, RepositoryAdminException
68 archivaConfiguration.getConfiguration();
69 archivaConfigurationControl.setReturnValue( new Configuration() );
70 archivaConfigurationControl.replay();
73 SecureActionBundle bundle = action.getSecureActionBundle();
74 assertTrue( bundle.requiresAuthentication() );
75 assertEquals( 1, bundle.getAuthorizationTuples().size() );
78 public void testDeleteRepositoryGroupConfirmation()
81 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
82 Configuration configuration = createConfigurationForEditing( origRepoGroup );
84 archivaConfiguration.getConfiguration();
85 archivaConfigurationControl.setReturnValue( configuration );
86 archivaConfigurationControl.replay();
88 action.setRepoGroupId( REPO_GROUP_ID );
91 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
92 RepositoryGroup repoGroup = action.getRepositoryGroup();
93 assertNotNull( repoGroup );
94 assertEquals( repoGroup.getId(), action.getRepoGroupId() );
95 assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() );
98 public void testDeleteRepositoryGroup()
101 Configuration configuration = createConfigurationForEditing( createRepositoryGroup() );
103 archivaConfiguration.getConfiguration();
104 archivaConfigurationControl.setReturnValue( configuration, 5 );
105 archivaConfiguration.save( configuration );
106 archivaConfigurationControl.replay();
108 action.setRepoGroupId( REPO_GROUP_ID );
111 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
112 RepositoryGroup repoGroup = action.getRepositoryGroup();
113 assertNotNull( repoGroup );
114 assertEquals( Collections.singletonList( repoGroup ),
115 action.getRepositoryGroupAdmin().getRepositoriesGroups() );
117 String status = action.delete();
118 assertEquals( Action.SUCCESS, status );
119 assertTrue( configuration.getRepositoryGroups().isEmpty() );
122 public void testDeleteRepositoryGroupCancelled()
125 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
126 Configuration configuration = createConfigurationForEditing( origRepoGroup );
128 archivaConfiguration.getConfiguration();
129 archivaConfigurationControl.setReturnValue( configuration, 2 );
131 archivaConfiguration.save( configuration );
132 archivaConfigurationControl.replay();
134 action.setRepoGroupId( REPO_GROUP_ID );
137 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
138 RepositoryGroup repoGroup = action.getRepositoryGroup();
139 assertNotNull( repoGroup );
141 String status = action.execute();
142 assertEquals( Action.SUCCESS, status );
143 assertEquals( Collections.singletonList( repoGroup ),
144 action.getRepositoryGroupAdmin().getRepositoriesGroups() );
147 private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup )
149 Configuration configuration = new Configuration();
150 configuration.addRepositoryGroup( repoGroup );
151 return configuration;
154 private RepositoryGroupConfiguration createRepositoryGroup()
156 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
157 repoGroup.setId( REPO_GROUP_ID );