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 assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
40 proxyConnectorAdmin.getProxyConnectors().size() );
41 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
42 ProxyConnector proxyConnector = new ProxyConnector();
43 proxyConnector.setSourceRepoId( "snapshots" );
44 proxyConnector.setTargetRepoId( "central" );
45 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
47 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
48 assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
50 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
52 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
54 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
55 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
57 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
59 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
60 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
61 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
63 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
64 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
66 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
68 mockAuditListener.clearEvents();
72 public void addAndUpdateAndDelete()
76 RemoteRepository remoteRepository = getRemoteRepository( "test-new-one" );
78 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
80 assertEquals( "not proxyConnectors 2 " + proxyConnectorAdmin.getProxyConnectors(), 2,
81 proxyConnectorAdmin.getProxyConnectors().size() );
82 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
83 ProxyConnector proxyConnector = new ProxyConnector();
84 proxyConnector.setSourceRepoId( "snapshots" );
85 proxyConnector.setTargetRepoId( "central" );
86 proxyConnector.setWhiteListPatterns( Arrays.asList( "foo", "bar" ) );
87 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
89 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
90 assertEquals( 3, proxyConnectorAdmin.getProxyConnectors().size() );
92 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
93 assertEquals( Arrays.asList( "foo", "bar" ),
94 proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ).getWhiteListPatterns() );
96 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
98 proxyConnector.setTargetRepoId( remoteRepository.getId() );
99 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
101 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
102 assertNotNull( remoteRepository.getId(),
103 proxyConnectorAdmin.getProxyConnector( "snapshots", remoteRepository.getId() ) );
105 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
107 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
109 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
110 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
112 assertEquals( 5, mockAuditListener.getAuditEvents().size() );
114 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
116 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
117 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
118 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 2 ).getRemoteIP() );
120 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
122 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 3 ).getAction() );
124 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 4 ).getAction() );
125 assertEquals( "root", mockAuditListener.getAuditEvents().get( 4 ).getUserId() );
127 remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
128 mockAuditListener.clearEvents();
132 public void findProxyConnector()
135 ProxyConnector proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
136 assertNotNull( proxyConnector );
140 public void updateProxyConnector()
143 ProxyConnector proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
144 assertNotNull( proxyConnector );
145 proxyConnector.setDisabled( false );
146 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
147 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
148 assertFalse( proxyConnector.isDisabled() );
150 proxyConnector.setDisabled( true );
151 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
152 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
153 assertTrue( proxyConnector.isDisabled() );
155 proxyConnector.setOrder( 4 );
156 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
157 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
158 assertEquals( 4, proxyConnector.getOrder() );