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.model.beans.RemoteRepository;
22 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
23 import org.apache.archiva.audit.AuditEvent;
24 import org.junit.Test;
26 import java.util.List;
29 * @author Olivier Lamy
31 public class RemoteRepositoryAdminTest
32 extends AbstractRepositoryAdminTest
39 List<RemoteRepository> remoteRepositories = remoteRepositoryAdmin.getRemoteRepositories();
40 assertNotNull( remoteRepositories );
41 assertTrue( remoteRepositories.size() > 0 );
42 log.info( "remote " + remoteRepositories );
49 RemoteRepository central = remoteRepositoryAdmin.getRemoteRepository( "central" );
50 assertNotNull( central );
51 assertEquals( "http://repo1.maven.org/maven2", central.getUrl() );
52 assertEquals( 60, central.getTimeout() );
53 assertNull( central.getUserName() );
54 assertNull( central.getPassword() );
58 public void addAndDelete()
61 mockAuditListener.clearEvents();
62 int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
64 RemoteRepository remoteRepository = getRemoteRepository();
66 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
68 assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
70 RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
71 assertNotNull( repo );
72 assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
73 assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
74 assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
75 assertEquals( getRemoteRepository().getName(), repo.getName() );
76 assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
78 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
80 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
82 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
85 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
87 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
88 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
89 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
91 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
92 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
98 public void addAndUpdateAndDelete()
101 mockAuditListener.clearEvents();
102 int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
104 RemoteRepository remoteRepository = getRemoteRepository();
106 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
108 assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
110 RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
111 assertNotNull( repo );
112 assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
113 assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
114 assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
115 assertEquals( getRemoteRepository().getName(), repo.getName() );
116 assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
117 assertEquals( getRemoteRepository().getRemoteDownloadNetworkProxyId(), repo.getRemoteDownloadNetworkProxyId() );
119 repo.setUserName( "foo-name-changed" );
120 repo.setPassword( "titi" );
121 repo.setUrl( "http://foo.com/maven-really-rocks" );
122 repo.setRemoteDownloadNetworkProxyId( "toto" );
124 remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() );
126 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
128 assertEquals( "foo-name-changed", repo.getUserName() );
129 assertEquals( "titi", repo.getPassword() );
130 assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() );
131 assertEquals( "toto", repo.getRemoteDownloadNetworkProxyId() );
133 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
135 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
137 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
140 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
142 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
143 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
144 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
146 assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
147 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
148 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 1 ).getRemoteIP() );
150 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
151 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );