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;
26 import java.util.Arrays;
29 * @author Olivier Lamy
31 public class ProxyConnectorAdminTest
32 extends AbstractRepositoryAdminTest
36 public void addAndDelete()
39 mockAuditListener.clearEvents();
40 assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
41 proxyConnectorAdmin.getProxyConnectors().size() );
42 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
43 ProxyConnector proxyConnector = new ProxyConnector();
44 proxyConnector.setSourceRepoId( "snapshots" );
45 proxyConnector.setTargetRepoId( "central" );
46 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
48 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
49 assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
51 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
53 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
55 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
56 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
58 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
60 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
61 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
62 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
64 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
65 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
67 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
69 mockAuditListener.clearEvents();
73 public void addAndUpdateAndDelete()
76 mockAuditListener.clearEvents();
77 RemoteRepository remoteRepository = getRemoteRepository( "test-new-one" );
79 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
81 assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
82 proxyConnectorAdmin.getProxyConnectors().size() );
83 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
84 ProxyConnector proxyConnector = new ProxyConnector();
85 proxyConnector.setSourceRepoId( "snapshots" );
86 proxyConnector.setTargetRepoId( "central" );
87 proxyConnector.setWhiteListPatterns( Arrays.asList( "foo", "bar" ) );
88 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
90 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
91 assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
93 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
94 assertEquals( Arrays.asList( "foo", "bar" ),
95 proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ).getWhiteListPatterns() );
97 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
99 proxyConnector.setTargetRepoId( remoteRepository.getId() );
100 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
102 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
103 assertNotNull( remoteRepository.getId(),
104 proxyConnectorAdmin.getProxyConnector( "snapshots", remoteRepository.getId() ) );
106 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
108 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
110 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
111 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
113 assertEquals( 5, mockAuditListener.getAuditEvents().size() );
115 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
117 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
118 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
119 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 2 ).getRemoteIP() );
121 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
123 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 3 ).getAction() );
125 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 4 ).getAction() );
126 assertEquals( "root", mockAuditListener.getAuditEvents().get( 4 ).getUserId() );
128 remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
129 mockAuditListener.clearEvents();
133 public void findProxyConnector()
136 ProxyConnector proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
137 assertNotNull( proxyConnector );
141 public void updateProxyConnector()
144 mockAuditListener.clearEvents();
145 ProxyConnector proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
146 assertNotNull( proxyConnector );
147 proxyConnector.setDisabled( false );
148 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
149 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
150 assertFalse( proxyConnector.isDisabled() );
152 proxyConnector.setDisabled( true );
153 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
154 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
155 assertTrue( proxyConnector.isDisabled() );
157 proxyConnector.setOrder( 4 );
158 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
159 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
160 assertEquals( 4, proxyConnector.getOrder() );
161 mockAuditListener.clearEvents();