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 java.util.List;
28 * @author Olivier Lamy
30 public class RemoteRepositoryAdminTest
31 extends AbstractRepositoryAdminTest
38 List<RemoteRepository> remoteRepositories = remoteRepositoryAdmin.getRemoteRepositories();
39 assertNotNull( remoteRepositories );
40 assertTrue( remoteRepositories.size() > 0 );
41 log.info( "remote " + remoteRepositories );
48 RemoteRepository central = remoteRepositoryAdmin.getRemoteRepository( "central" );
49 assertNotNull( central );
50 assertEquals( "http://repo1.maven.org/maven2", central.getUrl() );
51 assertEquals( 60, central.getTimeout() );
52 assertNull( central.getUserName() );
53 assertNull( central.getPassword() );
57 public void addAndDelete()
60 mockAuditListener.clearEvents();
61 int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
63 RemoteRepository remoteRepository = getRemoteRepository();
65 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
67 assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
69 RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
70 assertNotNull( repo );
71 assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
72 assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
73 assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
74 assertEquals( getRemoteRepository().getName(), repo.getName() );
75 assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
77 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
79 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
81 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
84 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
86 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
87 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
88 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
90 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
91 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
97 public void addAndUpdateAndDelete()
100 mockAuditListener.clearEvents();
101 int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
103 RemoteRepository remoteRepository = getRemoteRepository();
105 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
107 assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
109 RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
110 assertNotNull( repo );
111 assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
112 assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
113 assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
114 assertEquals( getRemoteRepository().getName(), repo.getName() );
115 assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
117 repo.setUserName( "foo-name-changed" );
118 repo.setPassword( "titi" );
119 repo.setUrl( "http://foo.com/maven-really-rocks" );
121 remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() );
123 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
125 assertEquals( "foo-name-changed", repo.getUserName() );
126 assertEquals( "titi", repo.getPassword() );
127 assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() );
129 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
131 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
133 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
136 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
138 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
139 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
140 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
142 assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
143 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
144 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 1 ).getRemoteIP() );
146 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
147 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );