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.metadata.model.facets.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://repo.maven.apache.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() );
77 assertEquals( getRemoteRepository().getDescription(), repo.getDescription() );
78 assertEquals( 1, remoteRepository.getExtraHeaders().size() );
79 assertEquals( "wine", remoteRepository.getExtraHeaders().get( "beer" ) );
81 assertEquals( 1, remoteRepository.getExtraParameters().size() );
82 assertEquals( "bar", remoteRepository.getExtraParameters().get( "foo" ) );
84 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
86 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
88 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
91 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
93 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
94 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
95 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
97 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
98 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
104 public void addAndUpdateAndDelete()
107 mockAuditListener.clearEvents();
108 int initialSize = remoteRepositoryAdmin.getRemoteRepositories().size();
110 RemoteRepository remoteRepository = getRemoteRepository();
112 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
114 assertEquals( initialSize + 1, remoteRepositoryAdmin.getRemoteRepositories().size() );
116 RemoteRepository repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
117 assertNotNull( repo );
118 assertEquals( getRemoteRepository().getPassword(), repo.getPassword() );
119 assertEquals( getRemoteRepository().getUrl(), repo.getUrl() );
120 assertEquals( getRemoteRepository().getUserName(), repo.getUserName() );
121 assertEquals( getRemoteRepository().getName(), repo.getName() );
122 assertEquals( getRemoteRepository().getTimeout(), repo.getTimeout() );
123 assertEquals( getRemoteRepository().getRemoteDownloadNetworkProxyId(), repo.getRemoteDownloadNetworkProxyId() );
125 repo.setUserName( "foo-name-changed" );
126 repo.setPassword( "titi" );
127 repo.setUrl( "http://foo.com/maven-really-rocks" );
128 repo.setRemoteDownloadNetworkProxyId( "toto" );
129 repo.setDescription( "archiva rocks!" );
131 remoteRepositoryAdmin.updateRemoteRepository( repo, getFakeAuditInformation() );
133 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
135 assertEquals( "foo-name-changed", repo.getUserName() );
136 assertEquals( "titi", repo.getPassword() );
137 assertEquals( "http://foo.com/maven-really-rocks", repo.getUrl() );
138 assertEquals( "toto", repo.getRemoteDownloadNetworkProxyId() );
139 assertEquals( "archiva rocks!", repo.getDescription() );
141 remoteRepositoryAdmin.deleteRemoteRepository( "foo", getFakeAuditInformation() );
143 assertEquals( initialSize, remoteRepositoryAdmin.getRemoteRepositories().size() );
145 repo = remoteRepositoryAdmin.getRemoteRepository( "foo" );
148 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
150 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
151 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
152 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
154 assertEquals( AuditEvent.MODIFY_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
155 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
156 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 1 ).getRemoteIP() );
158 assertEquals( AuditEvent.DELETE_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
159 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );