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.RepositoryGroup;
25 import org.apache.archiva.admin.repository.group.DefaultRepositoryGroupAdmin;
26 import org.apache.archiva.configuration.ArchivaConfiguration;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.RepositoryGroupConfiguration;
29 import org.apache.archiva.web.action.AbstractActionTestCase;
30 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
31 import org.apache.archiva.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();
60 ( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).setArchivaConfiguration(
61 archivaConfiguration );
64 public void testSecureActionBundle()
65 throws SecureActionException, RepositoryAdminException
67 archivaConfiguration.getConfiguration();
68 archivaConfigurationControl.setReturnValue( new Configuration() );
69 archivaConfigurationControl.replay();
72 SecureActionBundle bundle = action.getSecureActionBundle();
73 assertTrue( bundle.requiresAuthentication() );
74 assertEquals( 1, bundle.getAuthorizationTuples().size() );
77 public void testDeleteRepositoryGroupConfirmation()
80 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
81 Configuration configuration = createConfigurationForEditing( origRepoGroup );
83 archivaConfiguration.getConfiguration();
84 archivaConfigurationControl.setReturnValue( configuration, 2 );
85 archivaConfigurationControl.replay();
87 action.setRepoGroupId( REPO_GROUP_ID );
90 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
91 RepositoryGroup repoGroup = action.getRepositoryGroup();
92 assertNotNull( repoGroup );
93 assertEquals( repoGroup.getId(), action.getRepoGroupId() );
94 assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() );
97 public void testDeleteRepositoryGroup()
100 Configuration configuration = createConfigurationForEditing( createRepositoryGroup() );
102 archivaConfiguration.getConfiguration();
103 archivaConfigurationControl.setReturnValue( configuration, 7 );
104 archivaConfiguration.save( configuration );
105 archivaConfigurationControl.replay();
107 action.setRepoGroupId( REPO_GROUP_ID );
110 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
111 RepositoryGroup repoGroup = action.getRepositoryGroup();
112 assertNotNull( repoGroup );
113 assertEquals( Collections.singletonList( repoGroup ),
114 action.getRepositoryGroupAdmin().getRepositoriesGroups() );
116 String status = action.delete();
117 assertEquals( Action.SUCCESS, status );
118 assertTrue( configuration.getRepositoryGroups().isEmpty() );
121 public void testDeleteRepositoryGroupCancelled()
124 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
125 Configuration configuration = createConfigurationForEditing( origRepoGroup );
127 archivaConfiguration.getConfiguration();
128 archivaConfigurationControl.setReturnValue( configuration, 4 );
130 archivaConfiguration.save( configuration );
131 archivaConfigurationControl.replay();
133 action.setRepoGroupId( REPO_GROUP_ID );
136 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
137 RepositoryGroup repoGroup = action.getRepositoryGroup();
138 assertNotNull( repoGroup );
140 String status = action.execute();
141 assertEquals( Action.SUCCESS, status );
142 assertEquals( Collections.singletonList( repoGroup ),
143 action.getRepositoryGroupAdmin().getRepositoriesGroups() );
146 private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup )
148 Configuration configuration = new Configuration();
149 configuration.addRepositoryGroup( repoGroup );
150 return configuration;
153 private RepositoryGroupConfiguration createRepositoryGroup()
155 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
156 repoGroup.setId( REPO_GROUP_ID );