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.model.beans.ProxyConnector;
22 import org.apache.archiva.admin.model.beans.RemoteRepository;
23 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
24 import org.apache.archiva.audit.AuditEvent;
25 import org.junit.Test;
27 import java.util.Arrays;
30 * @author Olivier Lamy
32 public class ProxyConnectorAdminTest
33 extends AbstractRepositoryAdminTest
37 public void addAndDelete()
40 mockAuditListener.clearEvents();
41 assertEquals( "not proxyConnectors 1 " + proxyConnectorAdmin.getProxyConnectors(), 1,
42 proxyConnectorAdmin.getProxyConnectors().size() );
43 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
44 ProxyConnector proxyConnector = new ProxyConnector();
45 proxyConnector.setSourceRepoId( "snapshots" );
46 proxyConnector.setTargetRepoId( "central" );
47 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
49 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
50 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
52 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
54 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
56 assertEquals( 1, proxyConnectorAdmin.getProxyConnectors().size() );
57 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
59 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
61 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
62 assertEquals( "root", mockAuditListener.getAuditEvents().get( 0 ).getUserId() );
63 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 0 ).getRemoteIP() );
65 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
66 assertEquals( "root", mockAuditListener.getAuditEvents().get( 1 ).getUserId() );
68 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
70 mockAuditListener.clearEvents();
74 public void addAndUpdateAndDelete()
77 mockAuditListener.clearEvents();
78 RemoteRepository remoteRepository = getRemoteRepository( "test-new-one" );
80 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
82 assertEquals( "not proxyConnectors 1 " + proxyConnectorAdmin.getProxyConnectors(), 1,
83 proxyConnectorAdmin.getProxyConnectors().size() );
84 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
85 ProxyConnector proxyConnector = new ProxyConnector();
86 proxyConnector.setSourceRepoId( "snapshots" );
87 proxyConnector.setTargetRepoId( "central" );
88 proxyConnector.setWhiteListPatterns( Arrays.asList( "foo", "bar" ) );
89 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
91 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
92 assertEquals( 2, proxyConnectorAdmin.getProxyConnectors().size() );
94 assertNotNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
95 assertEquals( Arrays.asList( "foo", "bar" ),
96 proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ).getWhiteListPatterns() );
98 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
100 proxyConnector.setTargetRepoId( remoteRepository.getId() );
101 proxyConnectorAdmin.addProxyConnector( proxyConnector, getFakeAuditInformation() );
103 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
104 assertNotNull( remoteRepository.getId(),
105 proxyConnectorAdmin.getProxyConnector( "snapshots", remoteRepository.getId() ) );
107 proxyConnectorAdmin.deleteProxyConnector( proxyConnector, getFakeAuditInformation() );
109 assertNull( proxyConnectorAdmin.getProxyConnector( "snapshots", "central" ) );
111 assertEquals( 1, proxyConnectorAdmin.getProxyConnectors().size() );
112 assertFalse( proxyConnectorAdmin.getProxyConnectors().isEmpty() );
114 assertEquals( 5, mockAuditListener.getAuditEvents().size() );
116 assertEquals( AuditEvent.ADD_REMOTE_REPO, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
118 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
119 assertEquals( "root", mockAuditListener.getAuditEvents().get( 2 ).getUserId() );
120 assertEquals( "archiva-localhost", mockAuditListener.getAuditEvents().get( 2 ).getRemoteIP() );
122 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
124 assertEquals( AuditEvent.ADD_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 3 ).getAction() );
126 assertEquals( AuditEvent.DELETE_PROXY_CONNECTOR, mockAuditListener.getAuditEvents().get( 4 ).getAction() );
127 assertEquals( "root", mockAuditListener.getAuditEvents().get( 4 ).getUserId() );
129 remoteRepositoryAdmin.deleteRemoteRepository( remoteRepository.getId(), getFakeAuditInformation() );
130 mockAuditListener.clearEvents();
134 public void findProxyConnector()
137 ProxyConnector proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
138 assertNotNull( proxyConnector );
142 public void updateProxyConnector()
145 mockAuditListener.clearEvents();
146 ProxyConnector proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
147 assertNotNull( proxyConnector );
148 proxyConnector.setDisabled( false );
149 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
150 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
151 assertFalse( proxyConnector.isDisabled() );
153 proxyConnector.setDisabled( true );
154 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
155 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
156 assertTrue( proxyConnector.isDisabled() );
158 proxyConnector.setOrder( 4 );
159 proxyConnectorAdmin.updateProxyConnector( proxyConnector, getFakeAuditInformation() );
160 proxyConnector = proxyConnectorAdmin.getProxyConnector( "internal", "central" );
161 assertEquals( 4, proxyConnector.getOrder() );
162 mockAuditListener.clearEvents();