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 org.apache.maven.archiva.configuration.ArchivaConfiguration;
25 import org.apache.maven.archiva.configuration.Configuration;
26 import org.apache.maven.archiva.configuration.RepositoryGroupConfiguration;
27 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
28 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
29 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
30 import org.codehaus.redback.integration.interceptor.SecureActionException;
31 import org.easymock.MockControl;
33 import com.opensymphony.xwork2.Action;
36 * DeleteRepositoryGroupActionTest
40 public class DeleteRepositoryGroupActionTest
41 extends AbstractActionTestCase
43 private static final String REPO_GROUP_ID = "repo-group-ident";
45 private DeleteRepositoryGroupAction action;
47 private MockControl archivaConfigurationControl;
49 private ArchivaConfiguration archivaConfiguration;
51 protected void setUp()
56 action = (DeleteRepositoryGroupAction) lookup ( Action.class.getName(), "deleteRepositoryGroupAction" );
58 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
59 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
60 action.setArchivaConfiguration( archivaConfiguration );
63 public void testSecureActionBundle()
64 throws SecureActionException
66 archivaConfiguration.getConfiguration();
67 archivaConfigurationControl.setReturnValue( new Configuration() );
68 archivaConfigurationControl.replay();
71 SecureActionBundle bundle = action.getSecureActionBundle();
72 assertTrue( bundle.requiresAuthentication() );
73 assertEquals( 1, bundle.getAuthorizationTuples().size() );
76 public void testDeleteRepositoryGroupConfirmation()
79 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
80 Configuration configuration = createConfigurationForEditing( origRepoGroup );
82 archivaConfiguration.getConfiguration();
83 archivaConfigurationControl.setReturnValue( configuration );
84 archivaConfigurationControl.replay();
86 action.setRepoGroupId( REPO_GROUP_ID );
89 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
90 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
91 assertNotNull( repoGroup );
92 assertEquals( repoGroup.getId(), action.getRepoGroupId() );
93 assertEquals( Collections.singletonList( origRepoGroup ), configuration.getRepositoryGroups() );
96 public void testDeleteRepositoryGroup()
99 Configuration configuration = createConfigurationForEditing( createRepositoryGroup() );
101 archivaConfiguration.getConfiguration();
102 archivaConfigurationControl.setReturnValue( configuration, 3 );
103 archivaConfiguration.save( configuration );
104 archivaConfigurationControl.replay();
106 action.setRepoGroupId( REPO_GROUP_ID );
109 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
110 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
111 assertNotNull( repoGroup );
112 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
114 String status = action.delete();
115 assertEquals( Action.SUCCESS, status );
116 assertTrue( configuration.getRepositoryGroups().isEmpty() );
119 public void testDeleteRepositoryGroupCancelled()
122 RepositoryGroupConfiguration origRepoGroup = createRepositoryGroup();
123 Configuration configuration = createConfigurationForEditing ( origRepoGroup );
125 archivaConfiguration.getConfiguration();
126 archivaConfigurationControl.setReturnValue( configuration, 2 );
128 archivaConfiguration.save( configuration );
129 archivaConfigurationControl.replay();
131 action.setRepoGroupId( REPO_GROUP_ID );
134 assertEquals( REPO_GROUP_ID, action.getRepoGroupId() );
135 RepositoryGroupConfiguration repoGroup = action.getRepositoryGroup();
136 assertNotNull( repoGroup );
138 String status = action.execute();
139 assertEquals( Action.SUCCESS, status );
140 assertEquals( Collections.singletonList( repoGroup ), configuration.getRepositoryGroups() );
143 private Configuration createConfigurationForEditing( RepositoryGroupConfiguration repoGroup )
145 Configuration configuration = new Configuration();
146 configuration.addRepositoryGroup( repoGroup );
147 return configuration;
150 private RepositoryGroupConfiguration createRepositoryGroup()
152 RepositoryGroupConfiguration repoGroup = new RepositoryGroupConfiguration();
153 repoGroup.setId( REPO_GROUP_ID );