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.beans.RemoteRepository;
24 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
25 import org.apache.archiva.configuration.ArchivaConfiguration;
26 import org.apache.archiva.configuration.Configuration;
27 import org.apache.archiva.web.action.AbstractActionTestCase;
28 import org.apache.archiva.redback.integration.interceptor.SecureActionBundle;
29 import org.easymock.MockControl;
31 import java.util.Collections;
34 * AddRemoteRepositoryActionTest
38 public class AddRemoteRepositoryActionTest
39 extends AbstractActionTestCase
41 private AddRemoteRepositoryAction action;
43 private MockControl archivaConfigurationControl;
45 private ArchivaConfiguration archivaConfiguration;
47 private static final String REPO_ID = "remote-repo-ident";
49 protected void setUp()
54 action = (AddRemoteRepositoryAction) getActionProxy( "/admin/addRemoteRepository.action" ).getAction();
56 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
57 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
59 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
60 archivaConfiguration );
63 public void testSecureActionBundle()
66 archivaConfiguration.getConfiguration();
67 archivaConfigurationControl.setReturnValue( new Configuration() );
68 archivaConfigurationControl.replay();
71 SecureActionBundle bundle = action.getSecureActionBundle();
72 assertTrue( bundle.requiresAuthentication() );
73 assertEquals( 1, bundle.getAuthorizationTuples().size() );
76 public void testAddRemoteRepositoryInitialPage()
79 archivaConfiguration.getConfiguration();
80 archivaConfigurationControl.setReturnValue( new Configuration() );
81 archivaConfigurationControl.replay();
84 RemoteRepository configuration = action.getRepository();
85 assertNotNull( configuration );
86 assertNull( configuration.getId() );
88 String status = action.input();
89 assertEquals( Action.INPUT, status );
92 public void testAddRemoteRepository()
95 Configuration configuration = new Configuration();
96 archivaConfiguration.getConfiguration();
97 archivaConfigurationControl.setReturnValue( configuration, 2 );
99 archivaConfiguration.save( configuration );
101 archivaConfiguration.getConfiguration();
102 archivaConfigurationControl.setReturnValue( configuration, 1 );
104 archivaConfigurationControl.replay();
107 RemoteRepository repository = action.getRepository();
108 populateRepository( repository );
110 assertEquals( "url ", repository.getUrl() );
112 String status = action.commit();
113 assertEquals( Action.SUCCESS, status );
115 assertEquals( Collections.singletonList( repository ),
116 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
118 assertEquals( "url", repository.getUrl() );
120 archivaConfigurationControl.verify();
123 private void populateRepository( RemoteRepository repository )
125 repository.setId( REPO_ID );
126 repository.setName( "repo name" );
127 repository.setUrl( "url " );
128 repository.setLayout( "default" );
131 // TODO: test errors during add, other actions