View Javadoc
1   package org.eclipse.aether.util.repository;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   * 
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   * 
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import static org.junit.Assert.*;
23  
24  import org.eclipse.aether.util.repository.DefaultProxySelector;
25  import org.junit.Test;
26  
27  /**
28   */
29  public class DefaultProxySelectorTest
30  {
31  
32      private boolean isNonProxyHost( String host, String nonProxyHosts )
33      {
34          return new DefaultProxySelector.NonProxyHosts( nonProxyHosts ).isNonProxyHost( host );
35      }
36  
37      @Test
38      public void testIsNonProxyHost_Blank()
39      {
40          assertFalse( isNonProxyHost( "www.eclipse.org", null ) );
41          assertFalse( isNonProxyHost( "www.eclipse.org", "" ) );
42      }
43  
44      @Test
45      public void testIsNonProxyHost_Wildcard()
46      {
47          assertTrue( isNonProxyHost( "www.eclipse.org", "*" ) );
48          assertTrue( isNonProxyHost( "www.eclipse.org", "*.org" ) );
49          assertFalse( isNonProxyHost( "www.eclipse.org", "*.com" ) );
50          assertTrue( isNonProxyHost( "www.eclipse.org", "www.*" ) );
51          assertTrue( isNonProxyHost( "www.eclipse.org", "www.*.org" ) );
52      }
53  
54      @Test
55      public void testIsNonProxyHost_Multiple()
56      {
57          assertTrue( isNonProxyHost( "eclipse.org", "eclipse.org|host2" ) );
58          assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org" ) );
59          assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org|host2" ) );
60      }
61  
62      @Test
63      public void testIsNonProxyHost_Misc()
64      {
65          assertFalse( isNonProxyHost( "www.eclipse.org", "www.eclipse.com" ) );
66          assertFalse( isNonProxyHost( "www.eclipse.org", "eclipse.org" ) );
67      }
68  
69      @Test
70      public void testIsNonProxyHost_CaseInsensitivity()
71      {
72          assertTrue( isNonProxyHost( "www.eclipse.org", "www.ECLIPSE.org" ) );
73          assertTrue( isNonProxyHost( "www.ECLIPSE.org", "www.eclipse.org" ) );
74      }
75  
76  }