View Javadoc
1   package org.apache.archiva.rest.services;
2   /*
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
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
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
18   * under the License.
19   */
20  
21  import org.apache.archiva.admin.model.beans.NetworkProxy;
22  import org.junit.Test;
23  
24  /**
25   * @author Olivier Lamy
26   */
27  public class NetworkProxyServiceTest
28      extends AbstractArchivaRestTest
29  {
30      @Test
31      public void addAndDelete()
32          throws Exception
33      {
34          assertNotNull( getNetworkProxyService().getNetworkProxies() );
35          assertTrue( getNetworkProxyService().getNetworkProxies().isEmpty() );
36  
37          getNetworkProxyService().addNetworkProxy( getNetworkProxy( "foo" ) );
38  
39          assertNotNull( getNetworkProxyService().getNetworkProxies() );
40          assertFalse( getNetworkProxyService().getNetworkProxies().isEmpty() );
41          assertEquals( 1, getNetworkProxyService().getNetworkProxies().size() );
42  
43          getNetworkProxyService().deleteNetworkProxy( "foo" );
44  
45          assertNotNull( getNetworkProxyService().getNetworkProxies() );
46          assertTrue( getNetworkProxyService().getNetworkProxies().isEmpty() );
47  
48      }
49  
50      @Test
51      public void addAndUpdateAndDelete()
52          throws Exception
53      {
54          assertNotNull( getNetworkProxyService().getNetworkProxies() );
55          assertTrue( getNetworkProxyService().getNetworkProxies().isEmpty() );
56  
57          getNetworkProxyService().addNetworkProxy( getNetworkProxy( "foo" ) );
58  
59          assertNotNull( getNetworkProxyService().getNetworkProxies() );
60          assertFalse( getNetworkProxyService().getNetworkProxies().isEmpty() );
61          assertEquals( 1, getNetworkProxyService().getNetworkProxies().size() );
62  
63          NetworkProxy networkProxy = getNetworkProxy( "foo" );
64          networkProxy.setHost( "http://toto.com" );
65          networkProxy.setPassword( "newpasswd" );
66          networkProxy.setUsername( "newusername" );
67          networkProxy.setPort( 9191 );
68  
69          getNetworkProxyService().updateNetworkProxy( networkProxy );
70  
71          assertEquals( networkProxy.getHost(), getNetworkProxyService().getNetworkProxy( "foo" ).getHost() );
72          assertEquals( networkProxy.getPassword(), getNetworkProxyService().getNetworkProxy( "foo" ).getPassword() );
73          assertEquals( networkProxy.getUsername(), getNetworkProxyService().getNetworkProxy( "foo" ).getUsername() );
74          assertEquals( networkProxy.getPort(), getNetworkProxyService().getNetworkProxy( "foo" ).getPort() );
75  
76          getNetworkProxyService().deleteNetworkProxy( "foo" );
77  
78          assertNotNull( getNetworkProxyService().getNetworkProxies() );
79          assertTrue( getNetworkProxyService().getNetworkProxies().isEmpty() );
80  
81      }
82  
83      NetworkProxy getNetworkProxy( String id )
84      {
85  
86          NetworkProxy networkProxy = new NetworkProxy();
87          networkProxy.setId( id );
88          networkProxy.setHost( "http://foo.com" );
89          networkProxy.setPassword( "passwd" );
90          networkProxy.setUsername( "username" );
91          networkProxy.setPort( 9090 );
92          return networkProxy;
93      }
94  }