001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.connector;
038:
039: import java.io.File;
040: import java.io.IOException;
041: import java.net.InetSocketAddress;
042: import java.net.MalformedURLException;
043: import java.net.Proxy;
044: import java.net.URL;
045: import java.net.URLConnection;
046: import java.util.HashSet;
047: import java.util.Set;
048: import java.util.logging.FileHandler;
049: import org.MyTestCase;
050: import org.netbeans.installer.downloader.DownloadManager;
051: import org.netbeans.installer.downloader.connector.MyProxy;
052: import org.netbeans.installer.downloader.connector.MyProxyType;
053: import org.netbeans.installer.downloader.connector.URLConnector;
054: import org.util.*;
055:
056: /**
057: *
058: * @author Danila_Dugurov
059: */
060: public class ConnectionConfiguratorTest extends MyTestCase {
061: static {
062: System.setProperty("http.proxyHost", "www.potstava.danilahttp");
063: System.setProperty("http.proxyPort", "1234");
064: System
065: .setProperty("socksProxyHost",
066: "www.potstava.danilasocks");
067: System.setProperty("socksProxyPort", "1234");
068: System.setProperty("ftp.proxyHost", "www.potstava.danilaftp");
069: System.setProperty("ftp.proxyPort", "1234");
070: System.setProperty("deployment.proxy.http.host",
071: "www.miracle.com");
072: System.setProperty("deployment.proxy.http.port", "6060");
073: System.setProperty("deployment.proxy.bypass.list",
074: "sun.com,www.my.ru , , w3c.go.go,, 12.34.65.2 ");
075: }
076: Proxy httpPro;
077: Proxy ftpPro;
078: Proxy socksPro;
079: Proxy deploymentProxy;
080:
081: public void setUp() throws Exception {
082: super .setUp();
083: httpPro = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
084: "www.potstava.danilahttp", 1234));
085: ftpPro = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(
086: "www.potstava.danilaftp", 1234));
087: socksPro = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(
088: "www.potstava.danilasocks", 1234));
089: deploymentProxy = new Proxy(Proxy.Type.HTTP,
090: new InetSocketAddress("www.miracle.com", 6060));
091: }
092:
093: public void testSystemProxyCatched() {
094: URLConnector connector = new URLConnector(MyTestCase.testWD);
095: assertEquals(deploymentProxy, connector
096: .getProxy(MyProxyType.HTTP));
097: assertEquals(ftpPro, connector.getProxy(MyProxyType.FTP));
098: assertEquals(socksPro, connector.getProxy(MyProxyType.SOCKS));
099: }
100:
101: public void testByPassCatchedAndMyAdd() {
102: URLConnector connector = new URLConnector(MyTestCase.testWD);
103: final Set<String> expected = new HashSet<String>();
104: expected.add("sun.com");
105: expected.add("www.my.ru");
106: expected.add("w3c.go.go");
107: expected.add("12.34.65.2");
108: final Set<String> list = new HashSet<String>();
109: for (String str : connector.getByPassHosts()) {
110: list.add(str);
111: }
112: assertEquals(expected, list);
113: connector.addByPassHost("myNew.one");
114: list.clear();
115: for (String str : connector.getByPassHosts()) {
116: list.add(str);
117: }
118: expected.add("myNew.one");
119: assertEquals(expected, list);
120: }
121:
122: public void testClearAndAddNewByPass() {
123: URLConnector connector = new URLConnector(MyTestCase.testWD);
124: assertTrue(connector.getByPassHosts().length > 0);
125: connector.clearByPassList();
126: assertTrue(connector.getByPassHosts().length == 0);
127: connector.addByPassHost("test.one");
128: assertEquals("test.one", connector.getByPassHosts()[0]);
129: connector.addByPassHost("test.two");
130: assertTrue(connector.getByPassHosts().length == 2);
131: }
132:
133: public void testMyOwnProxyAdd() {
134: URLConnector connector = new URLConnector(MyTestCase.testWD);
135: MyProxy http = new MyProxy(
136: new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
137: "www.mpotstava.danilahttp", 1234)));
138: MyProxy ftp = new MyProxy(
139: new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(
140: "www.mpotstava.danilaftp", 1234)),
141: MyProxyType.FTP);
142: MyProxy socks = new MyProxy(
143: new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(
144: "www.mpotstava.danilasocks", 1234)));
145: connector.addProxy(http);
146: connector.addProxy(ftp);
147: connector.addProxy(socks);
148: assertEquals(http.getProxy(), connector
149: .getProxy(MyProxyType.HTTP));
150: assertEquals(ftp.getProxy(), connector
151: .getProxy(MyProxyType.FTP));
152: assertEquals(socks.getProxy(), connector
153: .getProxy(MyProxyType.SOCKS));
154: }
155:
156: public void testConnectorPropertiesSetGet() {
157: URLConnector connector = new URLConnector(MyTestCase.testWD);
158: connector.setConnectTimeout(1000);
159: assertEquals(1000, connector.getConnectTimeout());
160: connector.setReadTimeout(2000);
161: assertEquals(2000, connector.getReadTimeout());
162: connector.setUseProxy(false);
163: assertEquals(false, connector.getUseProxy());
164: }
165: }
|