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;
32 import org.junit.Before;
33 import org.junit.Test;
36 * AddRemoteRepositoryActionTest
40 public class AddRemoteRepositoryActionTest
41 extends AbstractActionTestCase
43 private AddRemoteRepositoryAction action;
45 private MockControl archivaConfigurationControl;
47 private ArchivaConfiguration archivaConfiguration;
49 private static final String REPO_ID = "remote-repo-ident";
58 action = (AddRemoteRepositoryAction) getActionProxy( "/admin/addRemoteRepository.action" ).getAction();
60 archivaConfigurationControl = MockControl.createControl( ArchivaConfiguration.class );
61 archivaConfiguration = (ArchivaConfiguration) archivaConfigurationControl.getMock();
63 ( (DefaultRemoteRepositoryAdmin) action.getRemoteRepositoryAdmin() ).setArchivaConfiguration(
64 archivaConfiguration );
68 public void testSecureActionBundle()
71 archivaConfiguration.getConfiguration();
72 archivaConfigurationControl.setReturnValue( new Configuration() );
73 archivaConfigurationControl.replay();
76 SecureActionBundle bundle = action.getSecureActionBundle();
77 assertTrue( bundle.requiresAuthentication() );
78 assertEquals( 1, bundle.getAuthorizationTuples().size() );
82 public void testAddRemoteRepositoryInitialPage()
85 archivaConfiguration.getConfiguration();
86 archivaConfigurationControl.setReturnValue( new Configuration() );
87 archivaConfigurationControl.replay();
90 RemoteRepository configuration = action.getRepository();
91 assertNotNull( configuration );
92 assertNull( configuration.getId() );
94 String status = action.input();
95 assertEquals( Action.INPUT, status );
99 public void testAddRemoteRepository()
102 Configuration configuration = new Configuration();
103 archivaConfiguration.getConfiguration();
104 archivaConfigurationControl.setReturnValue( configuration, 2 );
106 archivaConfiguration.save( configuration );
108 archivaConfiguration.getConfiguration();
109 archivaConfigurationControl.setReturnValue( configuration, 1 );
111 archivaConfigurationControl.replay();
114 RemoteRepository repository = action.getRepository();
115 populateRepository( repository );
117 assertEquals( "url ", repository.getUrl() );
119 String status = action.commit();
120 assertEquals( Action.SUCCESS, status );
122 assertEquals( Collections.singletonList( repository ),
123 action.getRemoteRepositoryAdmin().getRemoteRepositories() );
125 assertEquals( "url", repository.getUrl() );
127 archivaConfigurationControl.verify();
130 private void populateRepository( RemoteRepository repository )
132 repository.setId( REPO_ID );
133 repository.setName( "repo name" );
134 repository.setUrl( "url " );
135 repository.setLayout( "default" );
138 // TODO: test errors during add, other actions