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.ProxyConnector;
22  import org.apache.archiva.admin.model.beans.ProxyConnectorRule;
23  import org.apache.archiva.admin.model.beans.ProxyConnectorRuleType;
24  import org.apache.archiva.rest.api.services.ProxyConnectorRuleService;
25  import org.junit.Test;
26  
27  import java.util.Arrays;
28  
29  /**
30   * @author Olivier Lamy
31   */
32  public class ProxyConnectorRuleServiceTest
33      extends AbstractArchivaRestTest
34  {
35  
36      @Test
37      public void addProxyConnectorRule()
38          throws Exception
39      {
40          ProxyConnector proxyConnector = new ProxyConnector();
41          proxyConnector.setSourceRepoId( "snapshots" );
42          proxyConnector.setTargetRepoId( "central" );
43  
44          ProxyConnectorRuleService service = getProxyConnectorRuleService( authorizationHeader );
45  
46          ProxyConnectorRule rule = null;
47          try
48          {
49  
50              int size = service.getProxyConnectorRules().size();
51              assertEquals( 0, size );
52  
53              getProxyConnectorService().addProxyConnector( proxyConnector );
54  
55              rule = new ProxyConnectorRule( "org/apache/maven", ProxyConnectorRuleType.BLACK_LIST,
56                                             Arrays.asList( proxyConnector ) );
57  
58              service.addProxyConnectorRule( rule );
59              assertEquals( size + 1, service.getProxyConnectorRules().size() );
60  
61              rule = service.getProxyConnectorRules().get( 0 );
62  
63              assertEquals( "org/apache/maven", rule.getPattern() );
64              assertEquals( 1, rule.getProxyConnectors().size() );
65              assertEquals( "snapshots", rule.getProxyConnectors().get( 0 ).getSourceRepoId() );
66              assertEquals( "central", rule.getProxyConnectors().get( 0 ).getTargetRepoId() );
67              assertEquals( ProxyConnectorRuleType.BLACK_LIST, rule.getProxyConnectorRuleType() );
68          }
69          finally
70          {
71              service.deleteProxyConnectorRule( rule );
72              getProxyConnectorService().deleteProxyConnector( proxyConnector );
73          }
74      }
75  }
76