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 java.util.Collections;
24 import com.opensymphony.xwork2.Action;
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.codehaus.redback.integration.interceptor.SecureActionBundle;
29 import org.codehaus.redback.integration.interceptor.SecureActionException;
30 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
31 import org.easymock.MockControl;
34 * DeleteRepositoryGroupActionTest
38 public class DeleteRepositoryGroupActionTest
39 extends PlexusInSpringTestCase
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" );
56 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
57 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
58 action.setArchivaConfiguration( archivaConfiguration );
61 public void testSecureActionBundle()
62 throws SecureActionException
64 archivaConfiguration.getConfiguration();
65 archivaConfigurationControl.setReturnValue( new Configuration() );
66 archivaConfigurationControl.replay();
69 SecureActionBundle bundle = action.getSecureActionBundle();
70 assertTrue( bundle.requiresAuthentication() );
71 assertEquals( 1, bundle.getAuthorizationTuples().size() );
74 public void testDeleteRepositoryGroupConfirmation()
77 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
78 Configuration configuration = createConfigurationForEditing( origRepoGroup );
80 archivaConfiguration.getConfiguration();
81 archivaConfigurationControl.setReturnValue( configuration );
82 archivaConfigurationControl.replay();
84 action.setRepoGroupId( REPO_GROUP_ID );
87 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
88 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
89 assertNotNull( repoGroup );
90 assertEquals( repoGroup.getId(), action.getRepoGroupId() );
91 assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() );
94 public void testDeleteRepositoryGroup()
97 Configuration configuration = createConfigurationForEditing( createRepositoryGroup() );
99 archivaConfiguration.getConfiguration();
100 archivaConfigurationControl.setReturnValue( configuration, 3 );
101 archivaConfiguration.save( configuration );
102 archivaConfigurationControl.replay();
104 action.setRepoGroupId( REPO_GROUP_ID );
107 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
108 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
109 assertNotNull( repoGroup );
110 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
112 String status = action.delete();
113 assertEquals( Action.SUCCESS, status );
114 assertTrue( configuration.getRepositoryGroups().isEmpty() );
117 public void testDeleteRepositoryGroupCancelled()
120 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
121 Configuration configuration = createConfigurationForEditing ( origRepoGroup );
123 archivaConfiguration.getConfiguration();
124 archivaConfigurationControl.setReturnValue( configuration, 2 );
126 archivaConfiguration.save( configuration );
127 archivaConfigurationControl.replay();
129 action.setRepoGroupId( REPO_GROUP_ID );
132 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
133 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
134 assertNotNull( repoGroup );
136 String status = action.execute();
137 assertEquals( Action.SUCCESS, status );
138 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
141 private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup )
143 Configuration configuration = new Configuration();
144 configuration.addRepositoryGroup( repoGroup );
145 return configuration;
148 private RepositoryGroupConfiguration createRepositoryGroup()
150 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
151 repoGroup.setId( REPO_GROUP_ID );