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.maven.archiva.configuration.ArchivaConfiguration;
24 import org.apache.maven.archiva.configuration.Configuration;
25 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
26 import org.apache.struts2.StrutsSpringTestCase;
27 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
28 import org.codehaus.redback.integration.interceptor.SecureActionException;
29 import org.easymock.MockControl;
31 import java.util.Collections;
34 * EditRemoteRepositoryActionTest
38 public class EditRemoteRepositoryActionTest
39 extends StrutsSpringTestCase
41 private static final String REPO_ID = "remote-repo-ident";
43 private EditRemoteRepositoryAction action;
45 private MockControl archivaConfigurationControl;
47 private ArchivaConfiguration archivaConfiguration;
50 protected String[] getContextLocations()
52 return new String[]{ "classpath*:/META-INF/spring-context.xml", "classpath*:/spring-context.xml" };
55 public void testEditRemoteRepository()
58 Configuration configuration = createConfigurationForEditing( createRepository() );
59 archivaConfiguration.getConfiguration();
60 archivaConfigurationControl.setReturnValue( configuration );
61 archivaConfigurationControl.setReturnValue( configuration );
62 archivaConfiguration.save( configuration );
63 archivaConfigurationControl.replay();
65 action.setRepoid( REPO_ID );
67 assertEquals( REPO_ID, action.getRepoid() );
68 RemoteRepositoryConfiguration repository = action.getRepository();
69 populateRepository( repository );
70 repository.setName( "new repo name" );
72 String status = action.commit();
73 assertEquals( Action.SUCCESS, status );
75 RemoteRepositoryConfiguration newRepository = createRepository();
76 newRepository.setName( "new repo name" );
77 assertRepositoryEquals( repository, newRepository );
78 assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() );
80 archivaConfigurationControl.verify();
83 public void testEditRemoteRepositoryInitialPage()
86 Configuration configuration = createConfigurationForEditing( createRepository() );
88 archivaConfiguration.getConfiguration();
89 archivaConfigurationControl.setReturnValue( configuration );
90 archivaConfigurationControl.replay();
92 action.setRepoid( REPO_ID );
95 assertEquals( REPO_ID, action.getRepoid() );
96 RemoteRepositoryConfiguration repository = action.getRepository();
97 assertNotNull( repository );
98 assertRepositoryEquals( repository, createRepository() );
100 String status = action.input();
101 assertEquals( Action.INPUT, status );
102 repository = action.getRepository();
103 assertRepositoryEquals( repository, createRepository() );
106 public void testSecureActionBundle()
107 throws SecureActionException
109 archivaConfiguration.getConfiguration();
110 archivaConfigurationControl.setReturnValue( new Configuration() );
111 archivaConfigurationControl.replay();
114 SecureActionBundle bundle = action.getSecureActionBundle();
115 assertTrue( bundle.requiresAuthentication() );
116 assertEquals( 1, bundle.getAuthorizationTuples().size() );
119 private void assertRepositoryEquals( RemoteRepositoryConfiguration expectedRepository,
120 RemoteRepositoryConfiguration actualRepository )
122 assertEquals( expectedRepository.getId(), actualRepository.getId() );
123 assertEquals( expectedRepository.getLayout(), actualRepository.getLayout() );
124 assertEquals( expectedRepository.getUrl(), actualRepository.getUrl() );
125 assertEquals( expectedRepository.getName(), actualRepository.getName() );
128 private Configuration createConfigurationForEditing( RemoteRepositoryConfiguration repositoryConfiguration )
130 Configuration configuration = new Configuration();
131 configuration.addRemoteRepository( repositoryConfiguration );
132 return configuration;
135 private RemoteRepositoryConfiguration createRepository()
137 RemoteRepositoryConfiguration r = new RemoteRepositoryConfiguration();
139 populateRepository( r );
143 private void populateRepository( RemoteRepositoryConfiguration repository )
145 repository.setId( REPO_ID );
146 repository.setName( "repo name" );
147 repository.setUrl( "url" );
148 repository.setLayout( "default" );
151 protected void setUp()
156 //action = (EditRemoteRepositoryAction) lookup( Action.class.getName(), "editRemoteRepositoryAction" );
158 action = (EditRemoteRepositoryAction) getActionProxy( "editRemoteRepository.action" ).getAction();
160 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
161 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
162 action.setArchivaConfiguration( archivaConfiguration );