aboutsummaryrefslogtreecommitdiffstats
path: root/tests/netx/unit/net
diff options
context:
space:
mode:
authorJiri Vanek <[email protected]>2013-05-02 16:00:17 +0200
committerJiri Vanek <[email protected]>2013-05-02 16:00:17 +0200
commitc01de86b76ad014e30534ba879478c579e748fa9 (patch)
treeeb83e7fa79f2059ef740ad9243989ad3c1bb5f87 /tests/netx/unit/net
parent5c3d81c1620b814a3883909f4a37d71e9742a602 (diff)
Fix for portalbank.no (trying get after failed head requests) and tests
Diffstat (limited to 'tests/netx/unit/net')
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/VersionTest.java98
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/cache/ResourceTrackerTest.java320
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/util/HttpUtilsTest.java248
-rw-r--r--tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java37
4 files changed, 663 insertions, 40 deletions
diff --git a/tests/netx/unit/net/sourceforge/jnlp/VersionTest.java b/tests/netx/unit/net/sourceforge/jnlp/VersionTest.java
new file mode 100644
index 0000000..efe38ea
--- /dev/null
+++ b/tests/netx/unit/net/sourceforge/jnlp/VersionTest.java
@@ -0,0 +1,98 @@
+/*
+ Copyright (C) 2011 Red Hat, Inc.
+
+ This file is part of IcedTea.
+
+ IcedTea is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 2.
+
+ IcedTea is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with IcedTea; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version.
+ */
+package net.sourceforge.jnlp;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+public class VersionTest {
+
+ private static boolean[] results = {true,
+ true,
+ false,
+ true,
+ false,
+ true,
+ false,
+ true,
+ false,
+ false,
+ false,
+ false,
+ true,
+ true,
+ true,
+ true,
+ true,
+ true,
+ false,
+ true};
+ private static Version jvms[] = {
+ new Version("1.1* 1.3*"),
+ new Version("1.2+"),};
+ private static Version versions[] = {
+ new Version("1.1"),
+ new Version("1.1.8"),
+ new Version("1.2"),
+ new Version("1.3"),
+ new Version("2.0"),
+ new Version("1.3.1"),
+ new Version("1.2.1"),
+ new Version("1.3.1-beta"),
+ new Version("1.1 1.2"),
+ new Version("1.2 1.3"),};
+
+ @Test
+ public void testMatches() {
+
+ int i = 0;
+ for (int j = 0; j < jvms.length; j++) {
+ for (int v = 0; v < versions.length; v++) {
+ i++;
+ String debugOutput = i + " " + jvms[j].toString() + " ";
+ if (!jvms[j].matches(versions[v])) {
+ debugOutput += "!";
+ }
+ debugOutput += "matches " + versions[v].toString();
+ ServerAccess.logOutputReprint(debugOutput);
+ Assert.assertEquals(results[i - 1], jvms[j].matches(versions[v]));
+ }
+ }
+
+
+ }
+}
diff --git a/tests/netx/unit/net/sourceforge/jnlp/cache/ResourceTrackerTest.java b/tests/netx/unit/net/sourceforge/jnlp/cache/ResourceTrackerTest.java
index 29f372b..0b19668 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/cache/ResourceTrackerTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/cache/ResourceTrackerTest.java
@@ -1,54 +1,70 @@
/* ResourceTrackerTest.java
-Copyright (C) 2012 Red Hat, Inc.
-
-This file is part of IcedTea.
-
-IcedTea is free software; you can redistribute it and/or
-modify it under the terms of the GNU General Public License as published by
-the Free Software Foundation, version 2.
-
-IcedTea is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with IcedTea; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version.
+ Copyright (C) 2012 Red Hat, Inc.
+
+ This file is part of IcedTea.
+
+ IcedTea is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, version 2.
+
+ IcedTea is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with IcedTea; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version.
*/
package net.sourceforge.jnlp.cache;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
-
+import java.util.HashMap;
+import net.sourceforge.jnlp.ServerAccess;
+import net.sourceforge.jnlp.ServerLauncher;
+import net.sourceforge.jnlp.Version;
+import net.sourceforge.jnlp.runtime.JNLPRuntime;
import net.sourceforge.jnlp.util.UrlUtils;
-
+import org.junit.AfterClass;
import org.junit.Assert;
+import org.junit.BeforeClass;
import org.junit.Test;
-/** Test various corner cases of the parser */
public class ResourceTrackerTest {
+ public static ServerLauncher testServer;
+ public static ServerLauncher testServerWithBrokenHead;
+ private static PrintStream backedUpStream;
+ private static ByteArrayOutputStream currentErrorStream;
+ private static final String nameStub1 = "itw-server";
+ private static final String nameStub2 = "test-file";
+
@Test
public void testNormalizeUrl() throws Exception {
URL[] u = getUrls();
@@ -58,13 +74,12 @@ public class ResourceTrackerTest {
Assert.assertNull("first url should be null", u[0]);
Assert.assertNull("first normalized url should be null", n[0]);
for (int i = 1; i < CHANGE_BORDER; i++) {
- Assert.assertTrue("url " + i + " must be equals too normlaized url " + i, u[i].equals(n[i]));
+ Assert.assertTrue("url " + i + " must be equals too normalized url " + i, u[i].equals(n[i]));
}
for (int i = CHANGE_BORDER; i < n.length; i++) {
- Assert.assertFalse("url " + i + " must be normalized (and so not equals) too normlaized url " + i, u[i].equals(n[i]));
+ Assert.assertFalse("url " + i + " must be normalized (and so not equals) too normalized url " + i, u[i].equals(n[i]));
}
}
-
public static final int CHANGE_BORDER = 6;
public static URL[] getUrls() throws MalformedURLException {
@@ -97,4 +112,229 @@ public class ResourceTrackerTest {
return n;
}
+
+ @BeforeClass
+ public static void redirectErr() {
+ if (backedUpStream == null) {
+ backedUpStream = System.err;
+ }
+ currentErrorStream = new ByteArrayOutputStream();
+ System.setErr(new PrintStream(currentErrorStream));
+
+ }
+
+ @AfterClass
+ public static void redirectErrBack() throws UnsupportedEncodingException {
+ ServerAccess.logErrorReprint(currentErrorStream.toString("utf-8"));
+ System.setErr(backedUpStream);
+
+ }
+
+ @BeforeClass
+ public static void onDebug() {
+ JNLPRuntime.setDebug(true);
+ }
+
+ @AfterClass
+ public static void offDebug() {
+ JNLPRuntime.setDebug(false);
+ }
+
+ @BeforeClass
+ public static void startServer() throws IOException {
+ testServer = ServerAccess.getIndependentInstance(System.getProperty("java.io.tmpdir"), ServerAccess.findFreePort());
+ }
+
+ @BeforeClass
+ public static void startServer2() throws IOException {
+ testServerWithBrokenHead = ServerAccess.getIndependentInstance(System.getProperty("java.io.tmpdir"), ServerAccess.findFreePort());
+ testServerWithBrokenHead.setSupportingHeadRequest(false);
+ }
+
+ @AfterClass
+ public static void stopServer() {
+ testServer.stop();
+ }
+
+ @AfterClass
+ public static void stopServer2() {
+ testServerWithBrokenHead.stop();
+ }
+
+ @Test
+ public void getUrlResponseCodeTestWorkingHeadRequest() throws IOException {
+ redirectErr();
+ try {
+ File f = File.createTempFile(nameStub1, nameStub2);
+ int i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "HEAD");
+ Assert.assertEquals(HttpURLConnection.HTTP_OK, i);
+ f.delete();
+ i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "HEAD");
+ Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, i);
+ } finally {
+ redirectErrBack();
+ }
+ }
+
+ @Test
+ public void getUrlResponseCodeTestNotWorkingHeadRequest() throws IOException {
+ redirectErr();
+ try {
+ File f = File.createTempFile(nameStub1, nameStub2);
+ int i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "HEAD");
+ Assert.assertEquals(HttpURLConnection.HTTP_NOT_IMPLEMENTED, i);
+ f.delete();
+ i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "HEAD");
+ Assert.assertEquals(HttpURLConnection.HTTP_NOT_IMPLEMENTED, i);
+ } finally {
+ redirectErrBack();
+ }
+ }
+
+ @Test
+ public void getUrlResponseCodeTestGetRequestOnNotWorkingHeadRequest() throws IOException {
+ redirectErr();
+ try {
+ File f = File.createTempFile(nameStub1, nameStub2);
+ int i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "GET");
+ Assert.assertEquals(HttpURLConnection.HTTP_OK, i);
+ f.delete();
+ i = ResourceTracker.getUrlResponseCode(testServerWithBrokenHead.getUrl(f.getName()), new HashMap<String, String>(), "GET");
+ Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, i);
+ } finally {
+ redirectErrBack();
+ }
+ }
+
+ @Test
+ public void getUrlResponseCodeTestGetRequest() throws IOException {
+ redirectErr();
+ try {
+ File f = File.createTempFile(nameStub1, nameStub2);
+ int i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "GET");
+ Assert.assertEquals(HttpURLConnection.HTTP_OK, i);
+ f.delete();
+ i = ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "GET");
+ Assert.assertEquals(HttpURLConnection.HTTP_NOT_FOUND, i);
+ } finally {
+ redirectErrBack();
+ }
+ }
+
+ @Test
+ public void getUrlResponseCodeTestWrongRequest() throws IOException {
+ redirectErr();
+ try {
+ File f = File.createTempFile(nameStub1, nameStub2);
+ Exception exception = null;
+ try {
+ ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "SomethingWrong");
+ } catch (Exception ex) {
+ exception = ex;
+ }
+ Assert.assertNotNull(exception);
+ exception = null;
+ f.delete();
+ try {
+ ResourceTracker.getUrlResponseCode(testServer.getUrl(f.getName()), new HashMap<String, String>(), "SomethingWrong");
+ } catch (Exception ex) {
+ exception = ex;
+ }
+ Assert.assertNotNull(exception);;
+ } finally {
+ redirectErrBack();
+ }
+
+ }
+
+ @Test
+ public void findBestUrltest() throws IOException {
+ redirectErr();
+ try {
+ File fileForServerWithHeader = File.createTempFile(nameStub1, nameStub2);
+ File versionedFileForServerWithHeader = new File(fileForServerWithHeader.getParentFile(), fileForServerWithHeader.getName() + "-2.0");
+ versionedFileForServerWithHeader.createNewFile();
+
+ File fileForServerWithoutHeader = File.createTempFile(nameStub1, nameStub2);
+ File versionedFileForServerWithoutHeader = new File(fileForServerWithoutHeader.getParentFile(), fileForServerWithoutHeader.getName() + "-2.0");
+ versionedFileForServerWithoutHeader.createNewFile();
+
+ ResourceTracker rt = new ResourceTracker();
+ Resource r1 = Resource.getResource(testServer.getUrl(fileForServerWithHeader.getName()), null, UpdatePolicy.NEVER);
+ Resource r2 = Resource.getResource(testServerWithBrokenHead.getUrl(fileForServerWithoutHeader.getName()), null, UpdatePolicy.NEVER);
+ Resource r3 = Resource.getResource(testServer.getUrl(versionedFileForServerWithHeader.getName()), new Version("1.0"), UpdatePolicy.NEVER);
+ Resource r4 = Resource.getResource(testServerWithBrokenHead.getUrl(versionedFileForServerWithoutHeader.getName()), new Version("1.0"), UpdatePolicy.NEVER);
+ assertOnServerWithHeader(rt.findBestUrl(r1));
+ assertVersionedOneOnServerWithHeader(rt.findBestUrl(r3));
+ assertOnServerWithoutHeader(rt.findBestUrl(r2));
+ assertVersionedOneOnServerWithoutHeader(rt.findBestUrl(r4));
+
+ fileForServerWithHeader.delete();
+ Assert.assertNull(rt.findBestUrl(r1));
+ assertVersionedOneOnServerWithHeader(rt.findBestUrl(r3));
+ assertOnServerWithoutHeader(rt.findBestUrl(r2));
+ assertVersionedOneOnServerWithoutHeader(rt.findBestUrl(r4));
+
+ versionedFileForServerWithHeader.delete();
+ Assert.assertNull(rt.findBestUrl(r1));
+ Assert.assertNull(rt.findBestUrl(r3));
+ assertOnServerWithoutHeader(rt.findBestUrl(r2));
+ assertVersionedOneOnServerWithoutHeader(rt.findBestUrl(r4));
+
+ versionedFileForServerWithoutHeader.delete();
+ Assert.assertNull(rt.findBestUrl(r1));
+ Assert.assertNull(rt.findBestUrl(r3));
+ assertOnServerWithoutHeader(rt.findBestUrl(r2));
+ Assert.assertNull(rt.findBestUrl(r4));
+
+
+ fileForServerWithoutHeader.delete();
+ Assert.assertNull(rt.findBestUrl(r1));
+ Assert.assertNull(rt.findBestUrl(r3));
+ Assert.assertNull(rt.findBestUrl(r2));
+ Assert.assertNull(rt.findBestUrl(r4));
+ } finally {
+ redirectErrBack();
+ }
+
+ }
+
+ private void assertOnServerWithHeader(URL u) {
+ assertCommonComponentsOfUrl(u);
+ assertPort(u, testServer.getPort());
+ }
+
+ private void assertVersionedOneOnServerWithHeader(URL u) {
+ assertCommonComponentsOfUrl(u);
+ assertPort(u, testServer.getPort());
+ assertVersion(u);
+ }
+
+ private void assertOnServerWithoutHeader(URL u) {
+ assertCommonComponentsOfUrl(u);
+ assertPort(u, testServerWithBrokenHead.getPort());
+ }
+
+ private void assertVersionedOneOnServerWithoutHeader(URL u) {
+ assertCommonComponentsOfUrl(u);
+ assertPort(u, testServerWithBrokenHead.getPort());
+ assertVersion(u);
+ }
+
+ private void assertCommonComponentsOfUrl(URL u) {
+ Assert.assertTrue(u.getProtocol().equals("http"));
+ Assert.assertTrue(u.getHost().equals("localhost"));
+ Assert.assertTrue(u.getPath().contains(nameStub1));
+ Assert.assertTrue(u.getPath().contains(nameStub2));
+ ServerAccess.logOutputReprint(u.toExternalForm());
+ }
+
+ private void assertPort(URL u, int port) {
+ Assert.assertTrue(u.getPort() == port);
+ }
+
+ private void assertVersion(URL u) {
+ Assert.assertTrue(u.getPath().contains("-2.0"));
+ Assert.assertTrue(u.getQuery().contains("version-id=1.0"));
+ }
}
diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/HttpUtilsTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/HttpUtilsTest.java
new file mode 100644
index 0000000..08a6060
--- /dev/null
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/HttpUtilsTest.java
@@ -0,0 +1,248 @@
+/*
+ Copyright (C) 2012 Red Hat, Inc.
+
+ This file is part of IcedTea.
+
+ IcedTea is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ IcedTea is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with IcedTea; see the file COPYING. If not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301 USA.
+
+ Linking this library statically or dynamically with other modules is
+ making a combined work based on this library. Thus, the terms and
+ conditions of the GNU General Public License cover the whole
+ combination.
+
+ As a special exception, the copyright holders of this library give you
+ permission to link this library with independent modules to produce an
+ executable, regardless of the license terms of these independent
+ modules, and to copy and distribute the resulting executable under
+ terms of your choice, provided that you also meet, for each linked
+ independent module, the terms and conditions of the license of that
+ module. An independent module is a module which is not derived from
+ or based on this library. If you modify this library, you may extend
+ this exception to your version of the library, but you are not
+ obligated to do so. If you do not wish to do so, delete this
+ exception statement from your version. */
+package net.sourceforge.jnlp.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+import java.io.UnsupportedEncodingException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import net.sourceforge.jnlp.ServerAccess;
+import net.sourceforge.jnlp.ServerLauncher;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class HttpUtilsTest {
+
+ private static PrintStream backedUpStream;
+ private static ByteArrayOutputStream nwErrorStream;
+
+ public static void redirectErr() {
+ if (backedUpStream == null) {
+ backedUpStream = System.err;
+ }
+ nwErrorStream = new ByteArrayOutputStream();
+ System.setErr(new PrintStream(nwErrorStream));
+
+ }
+
+
+ public static void redirectErrBack() throws UnsupportedEncodingException {
+ ServerAccess.logErrorReprint(nwErrorStream.toString("utf-8"));
+ System.setErr(backedUpStream);
+
+ }
+
+ @Test
+ public void consumeAndCloseConnectionSilentlyTest() throws IOException {
+ redirectErr();
+ try{
+ Exception exception = null;
+ try {
+ HttpUtils.consumeAndCloseConnectionSilently(new HttpURLConnection(null) {
+ @Override
+ public void disconnect() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean usingProxy() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void connect() throws IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ });
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ exception = ex;
+ }
+ Assert.assertNull("no exception expected - was" + exception, exception);
+
+
+
+ try {
+ HttpUtils.consumeAndCloseConnectionSilently(new HttpURLConnection(new URL("http://localhost/blahblah")) {
+ @Override
+ public void disconnect() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean usingProxy() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void connect() throws IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ });
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ exception = ex;
+ }
+ Assert.assertNull("no exception expected - was" + exception, exception);
+
+ ServerLauncher serverLauncher =ServerAccess.getIndependentInstance(System.getProperty("user.dir"), ServerAccess.findFreePort());
+ try{
+ try {
+ HttpUtils.consumeAndCloseConnectionSilently(new HttpURLConnection(serverLauncher.getUrl("definitelyNotExisitnfFileInHappyMemoryOfAdam")) { //:)
+ @Override
+ public void disconnect() {
+
+ }
+
+ @Override
+ public boolean usingProxy() {
+ return false;
+ }
+
+ @Override
+ public void connect() throws IOException {
+
+ }
+ });
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ exception = ex;
+ }
+ Assert.assertNull("no exception expected - was" + exception, exception);
+ }finally{
+ try{
+ serverLauncher.stop();
+ }catch(Exception ex){
+ ServerAccess.logException(ex);
+ }
+ }
+ }finally{
+ redirectErrBack();
+ }
+ }
+
+ @Test
+ public void consumeAndCloseConnectionTest() throws IOException {
+ redirectErr();
+ try{
+ Exception exception = null;
+ try {
+ HttpUtils.consumeAndCloseConnection(new HttpURLConnection(null) {
+ @Override
+ public void disconnect() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean usingProxy() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void connect() throws IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ });
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ exception = ex;
+ }
+ Assert.assertNotNull("exception expected - wasnt" + exception, exception);
+
+
+
+ try {
+ HttpUtils.consumeAndCloseConnection(new HttpURLConnection(new URL("http://localhost/blahblah")) {
+ @Override
+ public void disconnect() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public boolean usingProxy() {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+
+ @Override
+ public void connect() throws IOException {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ });
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ exception = ex;
+ }
+ Assert.assertNotNull("exception expected - wasnt" + exception, exception);
+
+ ServerLauncher s =ServerAccess.getIndependentInstance(System.getProperty("user.dir"), ServerAccess.findFreePort());
+ try{
+ try {
+ HttpUtils.consumeAndCloseConnection(new HttpURLConnection(s.getUrl("blahblahblah")) {
+ @Override
+ public void disconnect() {
+
+ }
+
+ @Override
+ public boolean usingProxy() {
+ return false;
+ }
+
+ @Override
+ public void connect() throws IOException {
+
+ }
+ });
+ } catch (Exception ex) {
+ ServerAccess.logException(ex);
+ exception = ex;
+ }
+ Assert.assertNotNull(" exception expected - wasnt" + exception, exception);
+ }finally{
+ try{
+ s.stop();
+ }catch(Exception ex){
+ ServerAccess.logException(ex);
+ }
+ }
+ }finally{
+ redirectErrBack();
+ }
+ }
+}
diff --git a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
index 251dfb2..b6cf760 100644
--- a/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
+++ b/tests/netx/unit/net/sourceforge/jnlp/util/UrlUtilsTest.java
@@ -1,3 +1,40 @@
+/*
+ Copyright (C) 2012 Red Hat, Inc.
+
+This file is part of IcedTea.
+
+IcedTea is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+IcedTea is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with IcedTea; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
package net.sourceforge.jnlp.util;
import static org.junit.Assert.assertEquals;