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.xwork.Action;
23 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.Configuration;
25 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
26 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionBundle;
27 import org.codehaus.plexus.redback.xwork.interceptor.SecureActionException;
28 import org.codehaus.plexus.spring.PlexusInSpringTestCase;
29 import org.easymock.MockControl;
31 import java.util.Collections;
34 * EditRemoteRepositoryActionTest
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 public class EditRemoteRepositoryActionTest
40 extends PlexusInSpringTestCase
42 private static final String REPO_ID = "remote-repo-ident";
44 private EditRemoteRepositoryAction action;
46 private MockControl archivaConfigurationControl;
48 private ArchivaConfiguration archivaConfiguration;
50 public void testEditRemoteRepository()
53 Configuration configuration = createConfigurationForEditing( createRepository() );
54 archivaConfiguration.getConfiguration();
55 archivaConfigurationControl.setReturnValue( configuration );
56 archivaConfigurationControl.setReturnValue( configuration );
57 archivaConfiguration.save( configuration );
58 archivaConfigurationControl.replay();
60 action.setRepoid( REPO_ID );
62 assertEquals( REPO_ID, action.getRepoid() );
63 RemoteRepositoryConfiguration repository = action.getRepository();
64 populateRepository( repository );
65 repository.setName( "new repo name" );
67 String status = action.commit();
68 assertEquals( Action.SUCCESS, status );
70 RemoteRepositoryConfiguration newRepository = createRepository();
71 newRepository.setName( "new repo name" );
72 assertRepositoryEquals( repository, newRepository );
73 assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() );
75 archivaConfigurationControl.verify();
78 public void testEditRemoteRepositoryInitialPage()
81 Configuration configuration = createConfigurationForEditing( createRepository() );
83 archivaConfiguration.getConfiguration();
84 archivaConfigurationControl.setReturnValue( configuration );
85 archivaConfigurationControl.replay();
87 action.setRepoid( REPO_ID );
90 assertEquals( REPO_ID, action.getRepoid() );
91 RemoteRepositoryConfiguration repository = action.getRepository();
92 assertNotNull( repository );
93 assertRepositoryEquals( repository, createRepository() );
95 String status = action.input();
96 assertEquals( Action.INPUT, status );
97 repository = action.getRepository();
98 assertRepositoryEquals( repository, createRepository() );
101 public void testSecureActionBundle()
102 throws SecureActionException
104 archivaConfiguration.getConfiguration();
105 archivaConfigurationControl.setReturnValue( new Configuration() );
106 archivaConfigurationControl.replay();
109 SecureActionBundle bundle = action.getSecureActionBundle();
110 assertTrue( bundle.requiresAuthentication() );
111 assertEquals( 1, bundle.getAuthorizationTuples().size() );
114 private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
115 RemoteRepositoryConfiguration actualRepository )
117 assertEquals( expectedRepository.getId(), actualRepository.getId() );
118 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
119 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
120 assertEquals( expectedRepository.getName(), actualRepository.getName() );
123 private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration )
125 Configuration configuration = new Configuration();
126 configuration.addRemoteRepository( repositoryConfiguration );
127 return configuration;
130 private RemoteRepositoryConfiguration createRepository()
132 RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
134 populateRepository( r );
138 private void populateRepository( RemoteRepositoryConfiguration repository )
140 repository.setId( REPO_ID );
141 repository.setName( "repo name" );
142 repository.setUrl( "url" );
143 repository.setLayout( "default" );
146 protected void setUp()
151 action = (EditRemoteRepositoryAction) lookup( Action.class.getName(), "editRemoteRepositoryAction" );
153 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
154 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
155 action.setArchivaConfiguration( archivaConfiguration );