1 package org.apache.archiva.admin.repository.proxyconnector;
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.admin.repository.remote.RemoteRepository;
23 import org.apache.archiva.audit.AuditEvent;
24 import org.junit.Test;
27 * @author Olivier Lamy
29 public class ProxyConnectorAdminTest
30 extends AbstractRepositoryAdminTest
34 public void addAndDelete()
37 assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
38 proxyConnectorAdmin.getProxyConnectors().size() );
39 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
40 ProxyConnector proxyConnector = new ProxyConnector();
41 proxyConnector.setSourceRepoId( "snapshots" );
42 proxyConnector.setTargetRepoId( "central" );
43 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
45 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
46 assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
48 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
50 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
52 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
53 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
55 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
57 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
58 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
59 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
61 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
62 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
64 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
66 mockAuditListener.clearEvents();
70 public void addAndUpdateAndDelete()
74 RemoteRepository remoteRepository = getRemoteRepository( "test-new-one" );
76 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
78 assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
79 proxyConnectorAdmin.getProxyConnectors().size() );
80 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
81 ProxyConnector proxyConnector = new ProxyConnector();
82 proxyConnector.setSourceRepoId( "snapshots" );
83 proxyConnector.setTargetRepoId( "central" );
84 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
86 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
87 assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
89 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
91 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
93 proxyConnector.setTargetRepoId( remoteRepository.getId() );
94 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
96 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
97 assertNotNull( remoteRepository.getId(),
98 proxyConnectorAdmin.getProxyConnector( "snapshots", remoteRepository.getId() ) );
100 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
102 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
104 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
105 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
107 assertEquals( 5, mockAuditListener.getAuditEvents().size() );
109 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
111 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
112 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
113 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 2 ).getRemoteIP() );
115 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
117 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 3 ).getAction() );
119 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 4 ).getAction() );
120 assertEquals( "root", mockAuditListener.getAuditEvents().get( 4 ).getUserId() );
122 remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
123 mockAuditListener.clearEvents();