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.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
28 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
29 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
30 import org.codehaus.redback.integration.interceptor.SecureActionException;
31 import org.easymock.MockControl;
33 import java.util.Collections;
36 * DeleteRepositoryGroupActionTest
38 public class DeleteRepositoryGroupActionTest
39 extends AbstractActionTestCase
41 private static final String REPO_GROUP_ID = "repo-group-ident";
43 private DeleteRepositoryGroupAction action;
45 private MockControl archivaConfigurationControl;
47 private ArchivaConfiguration archivaConfiguration;
49 protected void setUp()
54 //action = (DeleteRepositoryGroupAction) lookup ( Action.class.getName(), "deleteRepositoryGroupAction" );
55 action = (DeleteRepositoryGroupAction) getActionProxy( "/admin/deleteRepositoryGroup.action" ).getAction();
57 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
58 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
59 action.setArchivaConfiguration( archivaConfiguration );
62 public void testSecureActionBundle()
63 throws SecureActionException, RepositoryAdminException
65 archivaConfiguration.getConfiguration();
66 archivaConfigurationControl.setReturnValue( new Configuration() );
67 archivaConfigurationControl.replay();
70 SecureActionBundle bundle = action.getSecureActionBundle();
71 assertTrue( bundle.requiresAuthentication() );
72 assertEquals( 1, bundle.getAuthorizationTuples().size() );
75 public void testDeleteRepositoryGroupConfirmation()
78 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
79 Configuration configuration = createConfigurationForEditing( origRepoGroup );
81 archivaConfiguration.getConfiguration();
82 archivaConfigurationControl.setReturnValue( configuration );
83 archivaConfigurationControl.replay();
85 action.setRepoGroupId( REPO_GROUP_ID );
88 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
89 RepositoryGroup repoGroup = action.getRepositoryGroup();
90 assertNotNull( repoGroup );
91 assertEquals( repoGroup.getId(), action.getRepoGroupId() );
92 assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() );
95 public void testDeleteRepositoryGroup()
98 Configuration configuration = createConfigurationForEditing( createRepositoryGroup() );
100 archivaConfiguration.getConfiguration();
101 archivaConfigurationControl.setReturnValue( configuration, 3 );
102 archivaConfiguration.save( configuration );
103 archivaConfigurationControl.replay();
105 action.setRepoGroupId( REPO_GROUP_ID );
108 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
109 RepositoryGroup repoGroup = action.getRepositoryGroup();
110 assertNotNull( repoGroup );
111 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
113 String status = action.delete();
114 assertEquals( Action.SUCCESS, status );
115 assertTrue( configuration.getRepositoryGroups().isEmpty() );
118 public void testDeleteRepositoryGroupCancelled()
121 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
122 Configuration configuration = createConfigurationForEditing( origRepoGroup );
124 archivaConfiguration.getConfiguration();
125 archivaConfigurationControl.setReturnValue( configuration, 2 );
127 archivaConfiguration.save( configuration );
128 archivaConfigurationControl.replay();
130 action.setRepoGroupId( REPO_GROUP_ID );
133 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
134 RepositoryGroup repoGroup = action.getRepositoryGroup();
135 assertNotNull( repoGroup );
137 String status = action.execute();
138 assertEquals( Action.SUCCESS, status );
139 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
142 private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup )
144 Configuration configuration = new Configuration();
145 configuration.addRepositoryGroup( repoGroup );
146 return configuration;
149 private RepositoryGroupConfiguration createRepositoryGroup()
151 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
152 repoGroup.setId( REPO_GROUP_ID );