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;
35 import org.junit.Before;
36 import org.junit.Test;
39 * DeleteRepositoryGroupActionTest
41 public class DeleteRepositoryGroupActionTest
42 extends AbstractActionTestCase
44 private static final String REPO_GROUP_ID = "repo-group-ident";
46 private DeleteRepositoryGroupAction action;
48 private MockControl archivaConfigurationControl;
50 private ArchivaConfiguration archivaConfiguration;
59 action = (DeleteRepositoryGroupAction) getActionProxy( "/admin/deleteRepositoryGroup.action" ).getAction();
61 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
62 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
64 ( (DefaultRepositoryGroupAdmin) action.getRepositoryGroupAdmin() ).setArchivaConfiguration(
65 archivaConfiguration );
69 public void testSecureActionBundle()
70 throws SecureActionException, RepositoryAdminException
72 archivaConfiguration.getConfiguration();
73 archivaConfigurationControl.setReturnValue( new Configuration() );
74 archivaConfigurationControl.replay();
77 SecureActionBundle bundle = action.getSecureActionBundle();
78 assertTrue( bundle.requiresAuthentication() );
79 assertEquals( 1, bundle.getAuthorizationTuples().size() );
83 public void testDeleteRepositoryGroupConfirmation()
86 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
87 Configuration configuration = createConfigurationForEditing( origRepoGroup );
89 archivaConfiguration.getConfiguration();
90 archivaConfigurationControl.setReturnValue( configuration, 2 );
91 archivaConfigurationControl.replay();
93 action.setRepoGroupId( REPO_GROUP_ID );
96 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
97 RepositoryGroup repoGroup = action.getRepositoryGroup();
98 assertNotNull( repoGroup );
99 assertEquals( repoGroup.getId(), action.getRepoGroupId() );
100 assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() );
104 public void testDeleteRepositoryGroup()
107 Configuration configuration = createConfigurationForEditing( createRepositoryGroup() );
109 archivaConfiguration.getConfiguration();
110 archivaConfigurationControl.setReturnValue( configuration, 7 );
111 archivaConfiguration.save( configuration );
112 archivaConfigurationControl.replay();
114 action.setRepoGroupId( REPO_GROUP_ID );
117 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
118 RepositoryGroup repoGroup = action.getRepositoryGroup();
119 assertNotNull( repoGroup );
120 assertEquals( Collections.singletonList( repoGroup ),
121 action.getRepositoryGroupAdmin().getRepositoriesGroups() );
123 String status = action.delete();
124 assertEquals( Action.SUCCESS, status );
125 assertTrue( configuration.getRepositoryGroups().isEmpty() );
129 public void testDeleteRepositoryGroupCancelled()
132 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
133 Configuration configuration = createConfigurationForEditing( origRepoGroup );
135 archivaConfiguration.getConfiguration();
136 archivaConfigurationControl.setReturnValue( configuration, 4 );
138 archivaConfiguration.save( configuration );
139 archivaConfigurationControl.replay();
141 action.setRepoGroupId( REPO_GROUP_ID );
144 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
145 RepositoryGroup repoGroup = action.getRepositoryGroup();
146 assertNotNull( repoGroup );
148 String status = action.execute();
149 assertEquals( Action.SUCCESS, status );
150 assertEquals( Collections.singletonList( repoGroup ),
151 action.getRepositoryGroupAdmin().getRepositoriesGroups() );
154 private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup )
156 Configuration configuration = new Configuration();
157 configuration.addRepositoryGroup( repoGroup );
158 return configuration;
161 private RepositoryGroupConfiguration createRepositoryGroup()
163 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
164 repoGroup.setId( REPO_GROUP_ID );