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.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.Configuration;
25 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
26 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
27 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
28 import org.codehaus.redback.integration.interceptor.SecureActionException;
29 import org.easymock.MockControl;
31 import java.util.Collections;
34 * DeleteRepositoryGroupActionTest
36 public class DeleteRepositoryGroupActionTest
37 extends AbstractActionTestCase
39 private static final String REPO_GROUP_ID = "repo-group-ident";
41 private DeleteRepositoryGroupAction action;
43 private MockControl archivaConfigurationControl;
45 private ArchivaConfiguration archivaConfiguration;
47 protected void setUp()
52 //action = (DeleteRepositoryGroupAction) lookup ( Action.class.getName(), "deleteRepositoryGroupAction" );
53 action = (DeleteRepositoryGroupAction) getActionProxy( "/admin/deleteRepositoryGroup.action" ).getAction();
55 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
56 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
57 action.setArchivaConfiguration( archivaConfiguration );
60 public void testSecureActionBundle()
61 throws SecureActionException
63 archivaConfiguration.getConfiguration();
64 archivaConfigurationControl.setReturnValue( new Configuration() );
65 archivaConfigurationControl.replay();
68 SecureActionBundle bundle = action.getSecureActionBundle();
69 assertTrue( bundle.requiresAuthentication() );
70 assertEquals( 1, bundle.getAuthorizationTuples().size() );
73 public void testDeleteRepositoryGroupConfirmation()
76 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
77 Configuration configuration = createConfigurationForEditing( origRepoGroup );
79 archivaConfiguration.getConfiguration();
80 archivaConfigurationControl.setReturnValue( configuration );
81 archivaConfigurationControl.replay();
83 action.setRepoGroupId( REPO_GROUP_ID );
86 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
87 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
88 assertNotNull( repoGroup );
89 assertEquals( repoGroup.getId(), action.getRepoGroupId() );
90 assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() );
93 public void testDeleteRepositoryGroup()
96 Configuration configuration = createConfigurationForEditing( createRepositoryGroup() );
98 archivaConfiguration.getConfiguration();
99 archivaConfigurationControl.setReturnValue( configuration, 3 );
100 archivaConfiguration.save( configuration );
101 archivaConfigurationControl.replay();
103 action.setRepoGroupId( REPO_GROUP_ID );
106 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
107 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
108 assertNotNull( repoGroup );
109 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
111 String status = action.delete();
112 assertEquals( Action.SUCCESS, status );
113 assertTrue( configuration.getRepositoryGroups().isEmpty() );
116 public void testDeleteRepositoryGroupCancelled()
119 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
120 Configuration configuration = createConfigurationForEditing( origRepoGroup );
122 archivaConfiguration.getConfiguration();
123 archivaConfigurationControl.setReturnValue( configuration, 2 );
125 archivaConfiguration.save( configuration );
126 archivaConfigurationControl.replay();
128 action.setRepoGroupId( REPO_GROUP_ID );
131 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
132 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
133 assertNotNull( repoGroup );
135 String status = action.execute();
136 assertEquals( Action.SUCCESS, status );
137 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
140 private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup )
142 Configuration configuration = new Configuration();
143 configuration.addRepositoryGroup( repoGroup );
144 return configuration;
147 private RepositoryGroupConfiguration createRepositoryGroup()
149 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
150 repoGroup.setId( REPO_GROUP_ID );