001package org.eclipse.aether.util.repository; 002 003/* 004 * Licensed to the Apache Software Foundation (ASF) under one 005 * or more contributor license agreements. See the NOTICE file 006 * distributed with this work for additional information 007 * regarding copyright ownership. The ASF licenses this file 008 * to you under the Apache License, Version 2.0 (the 009 * "License"); you may not use this file except in compliance 010 * with the License. You may obtain a copy of the License at 011 * 012 * http://www.apache.org/licenses/LICENSE-2.0 013 * 014 * Unless required by applicable law or agreed to in writing, 015 * software distributed under the License is distributed on an 016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 017 * KIND, either express or implied. See the License for the 018 * specific language governing permissions and limitations 019 * under the License. 020 */ 021 022import static org.junit.Assert.*; 023 024import org.eclipse.aether.util.repository.DefaultProxySelector; 025import org.junit.Test; 026 027/** 028 */ 029public class DefaultProxySelectorTest 030{ 031 032 private boolean isNonProxyHost( String host, String nonProxyHosts ) 033 { 034 return new DefaultProxySelector.NonProxyHosts( nonProxyHosts ).isNonProxyHost( host ); 035 } 036 037 @Test 038 public void testIsNonProxyHost_Blank() 039 { 040 assertFalse( isNonProxyHost( "www.eclipse.org", null ) ); 041 assertFalse( isNonProxyHost( "www.eclipse.org", "" ) ); 042 } 043 044 @Test 045 public void testIsNonProxyHost_Wildcard() 046 { 047 assertTrue( isNonProxyHost( "www.eclipse.org", "*" ) ); 048 assertTrue( isNonProxyHost( "www.eclipse.org", "*.org" ) ); 049 assertFalse( isNonProxyHost( "www.eclipse.org", "*.com" ) ); 050 assertTrue( isNonProxyHost( "www.eclipse.org", "www.*" ) ); 051 assertTrue( isNonProxyHost( "www.eclipse.org", "www.*.org" ) ); 052 } 053 054 @Test 055 public void testIsNonProxyHost_Multiple() 056 { 057 assertTrue( isNonProxyHost( "eclipse.org", "eclipse.org|host2" ) ); 058 assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org" ) ); 059 assertTrue( isNonProxyHost( "eclipse.org", "host1|eclipse.org|host2" ) ); 060 } 061 062 @Test 063 public void testIsNonProxyHost_Misc() 064 { 065 assertFalse( isNonProxyHost( "www.eclipse.org", "www.eclipse.com" ) ); 066 assertFalse( isNonProxyHost( "www.eclipse.org", "eclipse.org" ) ); 067 } 068 069 @Test 070 public void testIsNonProxyHost_CaseInsensitivity() 071 { 072 assertTrue( isNonProxyHost( "www.eclipse.org", "www.ECLIPSE.org" ) ); 073 assertTrue( isNonProxyHost( "www.ECLIPSE.org", "www.eclipse.org" ) ); 074 } 075 076}