001package org.apache.maven.wagon.proxy; 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 junit.framework.TestCase; 023 024/** 025 * @author <a href="mailto:lafeuil@gmail.com">Thomas Champagne</a> 026 */ 027public class ProxyInfoUtilsTest 028 extends TestCase 029{ 030 public ProxyInfoUtilsTest( final String name ) 031 { 032 super( name ); 033 } 034 035 public void setUp() 036 throws Exception 037 { 038 super.setUp(); 039 } 040 041 public void tearDown() 042 throws Exception 043 { 044 super.tearDown(); 045 } 046 047 public void testValidateNonProxyHostsWithNullProxy() 048 { 049 assertFalse( "www.ibiblio.org", ProxyUtils.validateNonProxyHosts( null, "maven.apache.org" ) ); 050 } 051 052 public void testValidateNonProxyHostsWithUniqueHost() 053 054 { 055 final ProxyInfo proxyInfo = new ProxyInfo(); 056 proxyInfo.setUserName( "username" ); 057 proxyInfo.setPassword( "password" ); 058 proxyInfo.setHost( "http://www.ibiblio.org" ); 059 proxyInfo.setPort( 0 ); 060 proxyInfo.setType( "SOCKSv4" ); 061 proxyInfo.setNonProxyHosts( "*.apache.org" ); 062 063 assertTrue( "maven.apache.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) ); 064 065 assertFalse( "www.ibiblio.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "www.ibiblio.org" ) ); 066 067 assertFalse( "null", ProxyUtils.validateNonProxyHosts( proxyInfo, null ) ); 068 069 proxyInfo.setNonProxyHosts( null ); 070 assertFalse( "NonProxyHosts = null", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) ); 071 072 proxyInfo.setNonProxyHosts( "" ); 073 assertFalse( "NonProxyHosts = \"\"", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) ); 074 } 075 076 public void testValidateNonProxyHostsWithMultipleHost() 077 078 { 079 final ProxyInfo proxyInfo = new ProxyInfo(); 080 proxyInfo.setUserName( "username" ); 081 proxyInfo.setPassword( "password" ); 082 proxyInfo.setHost( "http://www.ibiblio.org" ); 083 proxyInfo.setPort( 0 ); 084 proxyInfo.setType( "SOCKSv4" ); 085 proxyInfo.setNonProxyHosts( "*.apache.org|*.codehaus.org" ); 086 087 assertTrue( "maven.apache.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "maven.apache.org" ) ); 088 assertTrue( "wiki.codehaus.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "wiki.codehaus.org" ) ); 089 090 assertFalse( "www.ibiblio.org", ProxyUtils.validateNonProxyHosts( proxyInfo, "www.ibiblio.org" ) ); 091 } 092}