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.archiva.admin.model.RepositoryAdminException;
24 import org.apache.archiva.admin.model.remote.RemoteRepository;
25 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
26 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
27 import org.apache.maven.archiva.configuration.Configuration;
28 import org.apache.maven.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();
67 action.setArchivaConfiguration( archivaConfiguration );
69 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
70 archivaConfiguration );
73 public void testEditRemoteRepository()
76 Configuration configuration = createConfigurationForEditing( createRepository() );
77 archivaConfiguration.getConfiguration();
78 archivaConfigurationControl.setReturnValue( configuration );
79 archivaConfigurationControl.setReturnValue( configuration );
80 archivaConfigurationControl.setReturnValue( configuration );
81 archivaConfiguration.save( configuration );
82 archivaConfigurationControl.replay();
84 action.setRepoid( REPO_ID );
87 assertEquals( REPO_ID, action.getRepoid() );
88 RemoteRepository repository = action.getRepository();
89 populateRepository( repository );
90 repository.setName( "new repo name" );
92 String status = action.commit();
93 assertEquals( Action.SUCCESS, status );
95 RemoteRepository newRepository = createRepository();
96 newRepository.setName( "new repo name" );
97 assertRepositoryEquals( repository, newRepository );
98 assertEquals( Collections.singletonList( repository ),
99 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
101 archivaConfigurationControl.verify();
104 public void testEditRemoteRepositoryInitialPage()
107 Configuration configuration = createConfigurationForEditing( createRepository() );
109 archivaConfiguration.getConfiguration();
110 archivaConfigurationControl.setReturnValue( configuration );
111 archivaConfigurationControl.replay();
113 action.setRepoid( REPO_ID );
116 assertEquals( REPO_ID, action.getRepoid() );
117 RemoteRepository repository = action.getRepository();
118 assertNotNull( repository );
119 assertRepositoryEquals( repository, createRepository() );
121 String status = action.input();
122 assertEquals( Action.INPUT, status );
123 repository = action.getRepository();
124 assertRepositoryEquals( repository, createRepository() );
127 public void testSecureActionBundle()
128 throws SecureActionException, RepositoryAdminException
130 archivaConfiguration.getConfiguration();
131 archivaConfigurationControl.setReturnValue( new Configuration() );
132 archivaConfigurationControl.replay();
135 SecureActionBundle bundle = action.getSecureActionBundle();
136 assertTrue( bundle.requiresAuthentication() );
137 assertEquals( 1, bundle.getAuthorizationTuples().size() );
140 private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository actualRepository )
142 assertEquals( expectedRepository.getId(), actualRepository.getId() );
143 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
144 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
145 assertEquals( expectedRepository.getName(), actualRepository.getName() );
148 private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration )
150 Configuration configuration = new Configuration();
151 RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
152 conf.setId( repositoryConfiguration.getId() );
153 conf.setLayout( repositoryConfiguration.getLayout() );
154 conf.setUrl( repositoryConfiguration.getUrl() );
155 conf.setName( repositoryConfiguration.getName() );
156 configuration.addRemoteRepository( conf );
157 return configuration;
160 private RemoteRepository createRepository()
162 RemoteRepository r = new RemoteRepository();
164 populateRepository( r );
168 private void populateRepository( RemoteRepository repository )
170 repository.setId( REPO_ID );
171 repository.setName( "repo name" );
172 repository.setUrl( "url" );
173 repository.setLayout( "default" );