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.apache.archiva.redback.integration.interceptor.SecureActionBundle;
31 import org.apache.archiva.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, 4, 6 );
78 archivaConfiguration.save( configuration );
79 archivaConfigurationControl.replay();
81 action.setRepoid( REPO_ID );
84 assertEquals( REPO_ID, action.getRepoid() );
85 RemoteRepository repository = action.getRepository();
86 populateRepository( repository );
87 repository.setName( "new repo name" );
89 String status = action.commit();
90 assertEquals( Action.SUCCESS, status );
92 RemoteRepository newRepository = createRepository();
93 newRepository.setName( "new repo name" );
94 assertRepositoryEquals( repository, newRepository );
95 assertEquals( Collections.singletonList( repository ),
96 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
98 archivaConfigurationControl.verify();
101 public void testEditRemoteRepositoryInitialPage()
104 Configuration configuration = createConfigurationForEditing( createRepository() );
106 archivaConfiguration.getConfiguration();
107 archivaConfigurationControl.setReturnValue( configuration, 2 );
108 archivaConfigurationControl.replay();
110 action.setRepoid( REPO_ID );
113 assertEquals( REPO_ID, action.getRepoid() );
114 RemoteRepository repository = action.getRepository();
115 assertNotNull( repository );
116 assertRepositoryEquals( repository, createRepository() );
118 String status = action.input();
119 assertEquals( Action.INPUT, status );
120 repository = action.getRepository();
121 assertRepositoryEquals( repository, createRepository() );
124 public void testSecureActionBundle()
125 throws SecureActionException, RepositoryAdminException
127 archivaConfiguration.getConfiguration();
128 archivaConfigurationControl.setReturnValue( new Configuration() );
129 archivaConfigurationControl.replay();
132 SecureActionBundle bundle = action.getSecureActionBundle();
133 assertTrue( bundle.requiresAuthentication() );
134 assertEquals( 1, bundle.getAuthorizationTuples().size() );
137 private void assertRepositoryEquals( RemoteRepository expectedRepository, RemoteRepository actualRepository )
139 assertEquals( expectedRepository.getId(), actualRepository.getId() );
140 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
141 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
142 assertEquals( expectedRepository.getName(), actualRepository.getName() );
145 private Configuration createConfigurationForEditing( RemoteRepository repositoryConfiguration )
147 Configuration configuration = new Configuration();
148 RemoteRepositoryConfiguration conf = new RemoteRepositoryConfiguration();
149 conf.setId( repositoryConfiguration.getId() );
150 conf.setLayout( repositoryConfiguration.getLayout() );
151 conf.setUrl( repositoryConfiguration.getUrl() );
152 conf.setName( repositoryConfiguration.getName() );
153 configuration.addRemoteRepository( conf );
154 return configuration;
157 private RemoteRepository createRepository()
159 RemoteRepository r = new RemoteRepository();
161 populateRepository( r );
165 private void populateRepository( RemoteRepository repository )
167 repository.setId( REPO_ID );
168 repository.setName( "repo name" );
169 repository.setUrl( "url" );
170 repository.setLayout( "default" );