1 package org.apache.archiva.admin.repository.networkproxy;
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.NetworkProxy;
22 import org.apache.archiva.admin.model.beans.RemoteRepository;
23 import org.apache.archiva.admin.model.networkproxy.NetworkProxyAdmin;
24 import org.apache.archiva.admin.repository.AbstractRepositoryAdminTest;
25 import org.apache.archiva.audit.AuditEvent;
26 import org.junit.Test;
28 import javax.inject.Inject;
31 * @author Olivier Lamy
33 public class NetworkProxyAdminTest
34 extends AbstractRepositoryAdminTest
38 private NetworkProxyAdmin networkProxyAdmin;
41 public void getAllEmpty()
44 assertNotNull( networkProxyAdmin.getNetworkProxies() );
48 public void addAndDelete()
51 mockAuditListener.clearEvents();
52 int initialSize = networkProxyAdmin.getNetworkProxies().size();
53 NetworkProxy networkProxy = getNetworkProxyTest( "foo" );
55 networkProxyAdmin.addNetworkProxy( networkProxy, getFakeAuditInformation() );
57 assertEquals( initialSize + 1, networkProxyAdmin.getNetworkProxies().size() );
59 networkProxy = networkProxyAdmin.getNetworkProxy( "foo" );
61 assertNotNull( networkProxy );
62 assertEquals( getNetworkProxyTest( "foo" ).getId(), networkProxy.getId() );
63 assertEquals( getNetworkProxyTest( "foo" ).getHost(), networkProxy.getHost() );
64 assertEquals( getNetworkProxyTest( "foo" ).getPassword(), networkProxy.getPassword() );
65 assertEquals( getNetworkProxyTest( "foo" ).getPort(), networkProxy.getPort() );
66 assertEquals( getNetworkProxyTest( "foo" ).getUsername(), networkProxy.getUsername() );
67 assertEquals( getNetworkProxyTest( "foo" ).getProtocol(), networkProxy.getProtocol() );
69 networkProxyAdmin.deleteNetworkProxy( "foo", getFakeAuditInformation() );
71 assertNull( networkProxyAdmin.getNetworkProxy( "foo" ) );
73 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
75 assertEquals( AuditEvent.ADD_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
76 assertEquals( AuditEvent.DELETE_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
78 mockAuditListener.clearEvents();
82 public void addAndUpdateAndDelete()
85 mockAuditListener.clearEvents();
86 int initialSize = networkProxyAdmin.getNetworkProxies().size();
87 NetworkProxy networkProxy = getNetworkProxyTest( "foo" );
89 networkProxyAdmin.addNetworkProxy( networkProxy, getFakeAuditInformation() );
91 assertEquals( initialSize + 1, networkProxyAdmin.getNetworkProxies().size() );
93 networkProxy = networkProxyAdmin.getNetworkProxy( "foo" );
95 assertNotNull( networkProxy );
96 assertEquals( getNetworkProxyTest( "foo" ).getId(), networkProxy.getId() );
97 assertEquals( getNetworkProxyTest( "foo" ).getHost(), networkProxy.getHost() );
98 assertEquals( getNetworkProxyTest( "foo" ).getPassword(), networkProxy.getPassword() );
99 assertEquals( getNetworkProxyTest( "foo" ).getPort(), networkProxy.getPort() );
100 assertEquals( getNetworkProxyTest( "foo" ).getUsername(), networkProxy.getUsername() );
101 assertEquals( getNetworkProxyTest( "foo" ).getProtocol(), networkProxy.getProtocol() );
103 networkProxy.setHost( "https://toto.com" );
104 networkProxy.setPassword( "newpasswd" );
105 networkProxy.setPort( 9191 );
106 networkProxy.setProtocol( "http" );
107 networkProxy.setUsername( "newusername" );
109 networkProxyAdmin.updateNetworkProxy( networkProxy, getFakeAuditInformation() );
111 NetworkProxy updatedNetworkProxy = networkProxyAdmin.getNetworkProxy( "foo" );
113 assertNotNull( updatedNetworkProxy );
114 assertEquals( networkProxy.getId(), updatedNetworkProxy.getId() );
115 assertEquals( networkProxy.getHost(), updatedNetworkProxy.getHost() );
116 assertEquals( networkProxy.getPassword(), updatedNetworkProxy.getPassword() );
117 assertEquals( networkProxy.getPort(), updatedNetworkProxy.getPort() );
118 assertEquals( networkProxy.getUsername(), updatedNetworkProxy.getUsername() );
119 assertEquals( networkProxy.getProtocol(), updatedNetworkProxy.getProtocol() );
121 networkProxyAdmin.deleteNetworkProxy( "foo", getFakeAuditInformation() );
123 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
125 assertEquals( AuditEvent.ADD_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
126 assertEquals( AuditEvent.MODIFY_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
127 assertEquals( AuditEvent.DELETE_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
129 mockAuditListener.clearEvents();
133 * ensure we cleanup remote repos linked to a network proxy
136 public void addAndDeleteWithRemoteRepoLinked()
139 mockAuditListener.clearEvents();
140 int initialSize = networkProxyAdmin.getNetworkProxies().size();
141 NetworkProxy networkProxy = getNetworkProxyTest( "foo" );
143 networkProxyAdmin.addNetworkProxy( networkProxy, getFakeAuditInformation() );
145 assertEquals( initialSize + 1, networkProxyAdmin.getNetworkProxies().size() );
147 networkProxy = networkProxyAdmin.getNetworkProxy( "foo" );
149 assertNotNull( networkProxy );
151 RemoteRepository remoteRepository = getRemoteRepository();
152 remoteRepository.setRemoteDownloadNetworkProxyId( networkProxy.getId() );
154 remoteRepositoryAdmin.addRemoteRepository( remoteRepository, getFakeAuditInformation() );
156 networkProxyAdmin.deleteNetworkProxy( "foo", getFakeAuditInformation() );
158 remoteRepository = remoteRepositoryAdmin.getRemoteRepository( getRemoteRepository().getId() );
160 assertNull( remoteRepository.getRemoteDownloadNetworkProxyId() );
162 remoteRepositoryAdmin.deleteRemoteRepository( getRemoteRepository().getId(), getFakeAuditInformation() );
166 protected NetworkProxy getNetworkProxyTest( String id )
168 NetworkProxy networkProxy = new NetworkProxy();
169 networkProxy.setId( "foo" );
170 networkProxy.setHost( "http://foo.com" );
171 networkProxy.setPassword( "passwd" );
172 networkProxy.setPort( 9090 );
173 networkProxy.setUsername( "root" );
174 networkProxy.setProtocol( "https" );