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.repository.remote.DefaultRemoteRepositoryAdmin;
24 import org.apache.archiva.admin.repository.remote.RemoteRepository;
25 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
26 import org.apache.maven.archiva.configuration.Configuration;
27 import org.apache.maven.archiva.web.action.AbstractActionTestCase;
28 import org.codehaus.redback.integration.interceptor.SecureActionBundle;
29 import org.codehaus.redback.integration.interceptor.SecureActionException;
30 import org.easymock.MockControl;
32 import java.util.Collections;
35 * AddRemoteRepositoryActionTest
39 public class AddRemoteRepositoryActionTest
40 extends AbstractActionTestCase
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) getActionProxy( "/admin/addRemoteRepository.action" ).getAction();
57 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
58 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
59 action.setArchivaConfiguration( archivaConfiguration );
60 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
61 archivaConfiguration );
64 public void testSecureActionBundle()
65 throws SecureActionException
67 archivaConfiguration.getConfiguration();
68 archivaConfigurationControl.setReturnValue( new Configuration() );
69 archivaConfigurationControl.replay();
72 SecureActionBundle bundle = action.getSecureActionBundle();
73 assertTrue( bundle.requiresAuthentication() );
74 assertEquals( 1, bundle.getAuthorizationTuples().size() );
77 public void testAddRemoteRepositoryInitialPage()
80 archivaConfiguration.getConfiguration();
81 archivaConfigurationControl.setReturnValue( new Configuration() );
82 archivaConfigurationControl.replay();
85 RemoteRepository configuration = action.getRepository();
86 assertNotNull( configuration );
87 assertNull( configuration.getId() );
89 String status = action.input();
90 assertEquals( Action.INPUT, status );
93 public void testAddRemoteRepository()
96 Configuration configuration = new Configuration();
97 archivaConfiguration.getConfiguration();
98 archivaConfigurationControl.setReturnValue( configuration );
100 archivaConfiguration.save( configuration );
102 archivaConfiguration.getConfiguration();
103 archivaConfigurationControl.setReturnValue( configuration );
105 archivaConfigurationControl.replay();
108 RemoteRepository repository = action.getRepository();
109 populateRepository( repository );
111 assertEquals( "url ", repository.getUrl() );
113 String status = action.commit();
114 assertEquals( Action.SUCCESS, status );
116 assertEquals( Collections.singletonList( repository ),
117 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
119 assertEquals( "url", repository.getUrl() );
121 archivaConfigurationControl.verify();
124 private void populateRepository( RemoteRepository repository )
126 repository.setId( REPO_ID );
127 repository.setName( "repo name" );
128 repository.setUrl( "url " );
129 repository.setLayout( "default" );
132 // TODO: test errors during add, other actions