1 package org.apache.archiva.admin.repository.remote;
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
21 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
22 import org.apache.archiva.audit.AuditEvent;
23 import org.junit.Test;
25 import javax.inject.Inject;
26 import java.util.List;
29 * @author Olivier Lamy
31 public class RemoteRepositoryAdminTest
32 extends AbstractRepositoryAdminTest
36 private RemoteRepositoryAdmin remoteRepositoryAdmin;
42 List<RemoteRepository> remoteRepositories = remoteRepositoryAdmin.getRemoteRepositories();
43 assertNotNull( remoteRepositories );
44 assertTrue( remoteRepositories.size() > 0 );
45 log.info( "remote " + remoteRepositories );
52 RemoteRepository central = remoteRepositoryAdmin.getRemoteRepository( "central" );
53 assertNotNull( central );
54 assertEquals( "http://repo1.maven.org/maven2", central.getUrl() );
55 assertEquals( 60, central.getTimeout() );
56 assertNull( central.getUserName() );
57 assertNull( central.getPassword() );
61 public void addAndDelete()
64 mockAuditListener.clearEvents();
65 int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
67 RemoteRepository remoteRepository = getRemoteRepository();
69 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
71 assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
73 RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
74 assertNotNull( repo );
75 assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
76 assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
77 assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
78 assertEquals( getRemoteRepository().getName(), repo.getName() );
79 assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
81 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
83 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
85 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
88 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
90 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
91 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
92 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
94 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
95 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
101 public void addAndUpdateAndDelete()
104 mockAuditListener.clearEvents();
105 int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
107 RemoteRepository remoteRepository = getRemoteRepository();
109 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
111 assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
113 RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
114 assertNotNull( repo );
115 assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
116 assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
117 assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
118 assertEquals( getRemoteRepository().getName(), repo.getName() );
119 assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
121 repo.setUserName( "foo-name-changed" );
122 repo.setPassword( "titi" );
123 repo.setUrl( "http://foo.com/maven-really-rocks" );
126 remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() );
129 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
131 assertEquals( "foo-name-changed", repo.getUserName() );
132 assertEquals( "titi", repo.getPassword() );
133 assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() );
137 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
139 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
141 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
144 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
146 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
147 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
148 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
150 assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
151 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
152 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get(1 ).getRemoteIP() );
154 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
155 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
160 private RemoteRepository getRemoteRepository()
162 RemoteRepository remoteRepository = new RemoteRepository();
163 remoteRepository.setUrl( "http://foo.com/maven-it-rocks" );
164 remoteRepository.setTimeout( 10 );
165 remoteRepository.setName( "maven foo" );
166 remoteRepository.setUserName( "foo-name" );
167 remoteRepository.setPassword( "toto" );
168 remoteRepository.setId( "foo" );
169 return remoteRepository;