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.repository.AbstractRepositoryAdminTest;
22 import org.apache.archiva.audit.AuditEvent;
23 import org.junit.Test;
25 import javax.inject.Inject;
28 * @author Olivier Lamy
30 public class NetworkProxyAdminTest
31 extends AbstractRepositoryAdminTest
35 private NetworkProxyAdmin networkProxyAdmin;
38 public void getAllEmpty()
41 assertNotNull( networkProxyAdmin.getNetworkProxies() );
45 public void addAndDelete()
48 mockAuditListener.clearEvents();
49 int initialSize = networkProxyAdmin.getNetworkProxies().size();
50 NetworkProxy networkProxy = getNetworkProxyTest( "foo" );
52 networkProxyAdmin.addNetworkProxy( networkProxy, getFakeAuditInformation() );
54 assertEquals( initialSize + 1, networkProxyAdmin.getNetworkProxies().size() );
56 networkProxy = networkProxyAdmin.getNetworkProxy( "foo" );
58 assertNotNull( networkProxy );
59 assertEquals( getNetworkProxyTest( "foo" ).getId(), networkProxy.getId() );
60 assertEquals( getNetworkProxyTest( "foo" ).getHost(), networkProxy.getHost() );
61 assertEquals( getNetworkProxyTest( "foo" ).getPassword(), networkProxy.getPassword() );
62 assertEquals( getNetworkProxyTest( "foo" ).getPort(), networkProxy.getPort() );
63 assertEquals( getNetworkProxyTest( "foo" ).getUsername(), networkProxy.getUsername() );
64 assertEquals( getNetworkProxyTest( "foo" ).getProtocol(), networkProxy.getProtocol() );
66 networkProxyAdmin.deleteNetworkProxy( "foo", getFakeAuditInformation() );
68 assertNull( networkProxyAdmin.getNetworkProxy( "foo" ) );
70 assertEquals( 2, mockAuditListener.getAuditEvents().size() );
72 assertEquals( AuditEvent.ADD_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
73 assertEquals( AuditEvent.DELETE_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
75 mockAuditListener.clearEvents();
79 public void addAndUpdateAndDelete()
82 mockAuditListener.clearEvents();
83 int initialSize = networkProxyAdmin.getNetworkProxies().size();
84 NetworkProxy networkProxy = getNetworkProxyTest( "foo" );
86 networkProxyAdmin.addNetworkProxy( networkProxy, getFakeAuditInformation() );
88 assertEquals( initialSize + 1, networkProxyAdmin.getNetworkProxies().size() );
90 networkProxy = networkProxyAdmin.getNetworkProxy( "foo" );
92 assertNotNull( networkProxy );
93 assertEquals( getNetworkProxyTest( "foo" ).getId(), networkProxy.getId() );
94 assertEquals( getNetworkProxyTest( "foo" ).getHost(), networkProxy.getHost() );
95 assertEquals( getNetworkProxyTest( "foo" ).getPassword(), networkProxy.getPassword() );
96 assertEquals( getNetworkProxyTest( "foo" ).getPort(), networkProxy.getPort() );
97 assertEquals( getNetworkProxyTest( "foo" ).getUsername(), networkProxy.getUsername() );
98 assertEquals( getNetworkProxyTest( "foo" ).getProtocol(), networkProxy.getProtocol() );
100 networkProxy.setHost( "https://toto.com" );
101 networkProxy.setPassword( "newpasswd" );
102 networkProxy.setPort( 9191 );
103 networkProxy.setProtocol( "http" );
104 networkProxy.setUsername( "newusername" );
106 networkProxyAdmin.updateNetworkProxy( networkProxy, getFakeAuditInformation() );
108 NetworkProxy updatedNetworkProxy = networkProxyAdmin.getNetworkProxy( "foo" );
110 assertNotNull( updatedNetworkProxy );
111 assertEquals( networkProxy.getId(), updatedNetworkProxy.getId() );
112 assertEquals( networkProxy.getHost(), updatedNetworkProxy.getHost() );
113 assertEquals( networkProxy.getPassword(), updatedNetworkProxy.getPassword() );
114 assertEquals( networkProxy.getPort(), updatedNetworkProxy.getPort() );
115 assertEquals( networkProxy.getUsername(), updatedNetworkProxy.getUsername() );
116 assertEquals( networkProxy.getProtocol(), updatedNetworkProxy.getProtocol() );
118 networkProxyAdmin.deleteNetworkProxy( "foo", getFakeAuditInformation() );
120 assertEquals( 3, mockAuditListener.getAuditEvents().size() );
122 assertEquals( AuditEvent.ADD_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 0 ).getAction() );
123 assertEquals( AuditEvent.MODIFY_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 1 ).getAction() );
124 assertEquals( AuditEvent.DELETE_NETWORK_PROXY, mockAuditListener.getAuditEvents().get( 2 ).getAction() );
126 mockAuditListener.clearEvents();
130 protected NetworkProxy getNetworkProxyTest( String id )
132 NetworkProxy networkProxy = new NetworkProxy();
133 networkProxy.setId( "foo" );
134 networkProxy.setHost( "http://foo.com" );
135 networkProxy.setPassword( "passwd" );
136 networkProxy.setPort( 9090 );
137 networkProxy.setUsername( "root" );
138 networkProxy.setProtocol( "https" );