1 package org.apache.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.beans.RemoteRepository;
25 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
26 import org.apache.archiva.configuration.ArchivaConfiguration;
27 import org.apache.archiva.configuration.Configuration;
28 import org.apache.archiva.configuration.RemoteRepositoryConfiguration;
29 import org.apache.struts2.StrutsSpringTestCase;
30 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
31 import org.codehaus.redback.integration.interceptor.SecureActionException;
32 import org.easymock.MockControl;
34 import java.util.Collections;
37 * EditRemoteRepositoryActionTest
41 public class EditRemoteRepositoryActionTest
42 extends StrutsSpringTestCase
44 private static final String REPO_ID = "remote-repo-ident";
46 private EditRemoteRepositoryAction action;
48 private MockControl archivaConfigurationControl;
50 private ArchivaConfiguration archivaConfiguration;
53 protected String[] getContextLocations()
55 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
58 protected void setUp()
63 action = (EditRemoteRepositoryAction) getActionProxy( "/admin/editRemoteRepository.action" ).getAction();
65 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
66 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
68 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
69 archivaConfiguration );
72 public void testEditRemoteRepository()
75 Configuration configuration = createConfigurationForEditing( createRepository() );
76 archivaConfiguration.getConfiguration();
77 archivaConfigurationControl.setReturnValue( configuration );
78 archivaConfigurationControl.setReturnValue( configuration );
79 archivaConfigurationControl.setReturnValue( configuration );
80 archivaConfiguration.save( configuration );
81 archivaConfigurationControl.replay();
83 action.setRepoid( REPO_ID );
86 assertEquals( REPO_ID, action.getRepoid() );
87 RemoteRepository repository = action.getRepository();
88 populateRepository( repository );
89 repository.setName( "new repo name" );
91 String status = action.commit();
92 assertEquals( Action.SUCCESS, status );
94 RemoteRepository newRepository = createRepository();
95 newRepository.setName( "new repo name" );
96 assertRepositoryEquals( repository, newRepository );
97 assertEquals( Collections.singletonList( repository ),
98 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
100 archivaConfigurationControl.verify();
103 public void testEditRemoteRepositoryInitialPage()
106 Configuration configuration = createConfigurationForEditing( createRepository() );
108 archivaConfiguration.getConfiguration();
109 archivaConfigurationControl.setReturnValue( configuration );
110 archivaConfigurationControl.replay();
112 action.setRepoid( REPO_ID );
115 assertEquals( REPO_ID, action.getRepoid() );
116 RemoteRepository repository = action.getRepository();
117 assertNotNull( repository );
118 assertRepositoryEquals( repository, createRepository() );
120 String status = action.input();
121 assertEquals( Action.INPUT, status );
122 repository = action.getRepository();
123 assertRepositoryEquals( repository, createRepository() );
126 public void testSecureActionBundle()
127 throws SecureActionException, RepositoryAdminException
129 archivaConfiguration.getConfiguration();
130 archivaConfigurationControl.setReturnValue( new Configuration() );
131 archivaConfigurationControl.replay();
134 SecureActionBundle bundle = action.getSecureActionBundle();
135 assertTrue( bundle.requiresAuthentication() );
136 assertEquals( 1, bundle.getAuthorizationTuples().size() );
139 private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository actualRepository )
141 assertEquals( expectedRepository.getId(), actualRepository.getId() );
142 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
143 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
144 assertEquals( expectedRepository.getName(), actualRepository.getName() );
147 private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration )
149 Configuration configuration = new Configuration();
150 RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
151 conf.setId( repositoryConfiguration.getId() );
152 conf.setLayout( repositoryConfiguration.getLayout() );
153 conf.setUrl( repositoryConfiguration.getUrl() );
154 conf.setName( repositoryConfiguration.getName() );
155 configuration.addRemoteRepository( conf );
156 return configuration;
159 private RemoteRepository createRepository()
161 RemoteRepository r = new RemoteRepository();
163 populateRepository( r );
167 private void populateRepository( RemoteRepository repository )
169 repository.setId( REPO_ID );
170 repository.setName( "repo name" );
171 repository.setUrl( "url" );
172 repository.setLayout( "default" );