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 * AddRemoteRepositoryActionTest
36 * @author <a href="mailto:joakime@apache.org">Joakim Erdfelt</a>
39 public class AddRemoteRepositoryActionTest
40 extends PlexusInSpringTestCase
42 private AddRemoteRepositoryAction action;
44 private MockControl archivaConfigurationControl;
46 private ArchivaConfiguration archivaConfiguration;
48 private static final String REPO_ID = "remote-repo-ident";
50 protected void setUp()
55 action = (AddRemoteRepositoryAction) lookup( Action.class.getName(), "addRemoteRepositoryAction" );
57 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
58 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
59 action.setArchivaConfiguration( archivaConfiguration );
62 public void testSecureActionBundle()
63 throws SecureActionException
65 archivaConfiguration.getConfiguration();
66 archivaConfigurationControl.setReturnValue( new Configuration() );
67 archivaConfigurationControl.replay();
70 SecureActionBundle bundle = action.getSecureActionBundle();
71 assertTrue( bundle.requiresAuthentication() );
72 assertEquals( 1, bundle.getAuthorizationTuples().size() );
75 public void testAddRemoteRepositoryInitialPage()
78 archivaConfiguration.getConfiguration();
79 archivaConfigurationControl.setReturnValue( new Configuration() );
80 archivaConfigurationControl.replay();
83 RemoteRepositoryConfiguration configuration = action.getRepository();
84 assertNotNull( configuration );
85 assertNull( configuration.getId() );
87 String status = action.input();
88 assertEquals( Action.INPUT, status );
91 public void testAddRemoteRepository()
94 Configuration configuration = new Configuration();
95 archivaConfiguration.getConfiguration();
96 archivaConfigurationControl.setReturnValue( configuration );
98 archivaConfiguration.save( configuration );
100 archivaConfigurationControl.replay();
103 RemoteRepositoryConfiguration repository = action.getRepository();
104 populateRepository( repository );
106 assertEquals("url ", repository.getUrl());
108 String status = action.commit();
109 assertEquals( Action.SUCCESS, status );
111 assertEquals( Collections.singletonList( repository ), configuration.getRemoteRepositories() );
113 assertEquals("url", repository.getUrl());
115 archivaConfigurationControl.verify();
118 private void populateRepository( RemoteRepositoryConfiguration repository )
120 repository.setId( REPO_ID );
121 repository.setName( "repo name" );
122 repository.setUrl( "url " );
123 repository.setLayout( "default" );
126 // TODO: test errors during add, other actions