Mercurial > hg > release > icedtea-web-1.5
changeset 696:0e170a31770d
Fixed regressed unittest and "cause", Fixed compilation under jdk6, Silenced unittests
author | Jiri Vanek <jvanek@redhat.com> |
---|---|
date | Fri, 26 Apr 2013 11:29:04 +0200 |
parents | 8515c529e29c |
children | 8fc56ffa5be0 |
files | ChangeLog netx/net/sourceforge/jnlp/NullJnlpFileException.java netx/net/sourceforge/jnlp/SecurityDesc.java netx/net/sourceforge/jnlp/util/JarFile.java netx/net/sourceforge/jnlp/util/StreamUtils.java tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java tests/netx/unit/net/sourceforge/jnlp/SecurityDescTest.java tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java tests/netx/unit/sun/applet/PluginAppletViewerTest.java tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFile.java |
diffstat | 11 files changed, 286 insertions(+), 139 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog Thu Apr 25 17:05:31 2013 -0400 +++ b/ChangeLog Fri Apr 26 11:29:04 2013 +0200 @@ -1,3 +1,35 @@ +2013-04-26 Jiri Vanek <jvanek@redhat.com> + + Silenced unittests + * tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java: and + * tests/netx/unit/sun/applet/PluginAppletViewerTest.java: + System.out.println replaced by ServerAccess.logOutputReprint + +2013-04-26 Jiri Vanek <jvanek@redhat.com> + + Fixed compilation under jdk6 + * netx/net/sourceforge/jnlp/util/JarFile.java: + is now implementing Closeable + +2013-04-26 Jiri Vanek <jvanek@redhat.com> + + Fixed regressed unittest and "cause" + * /netx/net/sourceforge/jnlp/NullJnlpFileException.java: + fixed header + * netx/net/sourceforge/jnlp/SecurityDesc.java: (SecurityDesc) is now + throwing NullJnlpFileException in case of null jnlp file. + * tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java: is now using + correct DummyJnlpFile + * tests/netx/unit/net/sourceforge/jnlp/SecurityDescTest.java: new testfile. + (testNotNullJnlpFile) (testNullJnlpFile) testing the behavior for null + jnlp file and for existing jnlpfile. + * tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java: + (DummyJnlpFile) extracted to test-extensions and have removed incorrect have security + (testNullFileSecurityDescApplet) and (testNullFileSecurityDesc) is now expecting + NullJnlpFileException instead of results + * tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFile.java: new + reusable dummy jnlp file + 2013-04-25 Adam Domurad <adomurad@redhat.com> Add accidentally not included files from "Tests & test extensions for
--- a/netx/net/sourceforge/jnlp/NullJnlpFileException.java Thu Apr 25 17:05:31 2013 -0400 +++ b/netx/net/sourceforge/jnlp/NullJnlpFileException.java Fri Apr 26 11:29:04 2013 +0200 @@ -1,14 +1,42 @@ package net.sourceforge.jnlp; -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. +/* +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. */ -/** - * - * @author jvanek - */ public class NullJnlpFileException extends NullPointerException { public NullJnlpFileException() {
--- a/netx/net/sourceforge/jnlp/SecurityDesc.java Thu Apr 25 17:05:31 2013 -0400 +++ b/netx/net/sourceforge/jnlp/SecurityDesc.java Fri Apr 26 11:29:04 2013 +0200 @@ -149,6 +149,9 @@ * @param downloadHost the download host (can always connect to) */ public SecurityDesc(JNLPFile file, Object type, String downloadHost) { + if (file == null) { + throw new NullJnlpFileException(); + } this.file = file; this.type = type; this.downloadHost = downloadHost;
--- a/netx/net/sourceforge/jnlp/util/JarFile.java Thu Apr 25 17:05:31 2013 -0400 +++ b/netx/net/sourceforge/jnlp/util/JarFile.java Fri Apr 26 11:29:04 2013 +0200 @@ -36,14 +36,16 @@ exception statement from your version. */ package net.sourceforge.jnlp.util; +import java.io.Closeable; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; -import java.util.zip.ZipFile; import net.sourceforge.jnlp.runtime.JNLPRuntime; -public class JarFile extends java.util.jar.JarFile { +//in jdk6 java.util.jar.JarFile is not Closeable - fixing +//overwritening class can add duplicate occurence of interface so this should be perfectly safe +public class JarFile extends java.util.jar.JarFile implements Closeable{ public JarFile(String name) throws IOException { super(name);
--- a/netx/net/sourceforge/jnlp/util/StreamUtils.java Thu Apr 25 17:05:31 2013 -0400 +++ b/netx/net/sourceforge/jnlp/util/StreamUtils.java Fri Apr 26 11:29:04 2013 +0200 @@ -73,8 +73,8 @@ } } } - - + + public static String readStreamAsString(InputStream stream) throws IOException { InputStreamReader is = new InputStreamReader(stream); StringBuilder sb = new StringBuilder();
--- a/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java Thu Apr 25 17:05:31 2013 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/ParserBasic.java Fri Apr 26 11:29:04 2013 +0200 @@ -40,6 +40,8 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.List; +import net.sourceforge.jnlp.runtime.CodeBaseClassLoaderTest; +import net.sourceforge.jnlp.mock.DummyJNLPFile; import org.junit.After; import org.junit.Assert; @@ -61,7 +63,7 @@ } InputStream jnlpStream = cl.getResourceAsStream("net/sourceforge/jnlp/basic.jnlp"); root = Parser.getRootNode(jnlpStream); - parser = new Parser(null, null, root, false, false); + parser = new Parser(new DummyJNLPFile(), null, root, false, false); } @Test
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/unit/net/sourceforge/jnlp/SecurityDescTest.java Fri Apr 26 11:29:04 2013 +0200 @@ -0,0 +1,70 @@ +/* +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; + +import net.sourceforge.jnlp.mock.DummyJNLPFile; +import org.junit.Assert; +import org.junit.Test; + +public class SecurityDescTest { + + @Test + public void testNotNullJnlpFile() { + Throwable t = null; + try { + SecurityDesc securityDesc = new SecurityDesc(new DummyJNLPFile(), SecurityDesc.SANDBOX_PERMISSIONS, "hey!"); + } catch (Exception ex) { + t = ex; + } + Assert.assertNull("securityDesc should not throw exception", t); + + + } + + @Test + public void testNullJnlpFile() { + Exception ex = null; + try { + SecurityDesc securityDesc = new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, "hey!"); + } catch (Exception eex) { + ex = eex; + } + Assert.assertNotNull("Exception should not be null", ex); + Assert.assertTrue("Exception should be " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); + + } +}
--- a/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java Thu Apr 25 17:05:31 2013 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/runtime/CodeBaseClassLoaderTest.java Fri Apr 26 11:29:04 2013 +0200 @@ -1,41 +1,42 @@ /* CodeBaseClassLoaderTest.java -Copyright (C) 2012 Red Hat, Inc. + Copyright (C) 2012 Red Hat, Inc. -This file is part of IcedTea. + 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 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. + 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. + 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. + 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. + 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.runtime; +import net.sourceforge.jnlp.mock.DummyJNLPFile; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -47,6 +48,7 @@ import net.sourceforge.jnlp.NullJnlpFileException; import net.sourceforge.jnlp.ResourcesDesc; import net.sourceforge.jnlp.SecurityDesc; +import net.sourceforge.jnlp.SecurityDescTest; import net.sourceforge.jnlp.ServerAccess; import net.sourceforge.jnlp.runtime.JNLPClassLoader.CodeBaseClassLoader; import net.sourceforge.jnlp.annotations.Bug; @@ -58,45 +60,6 @@ public class CodeBaseClassLoaderTest { - private static final URL JAR_URL; - private static final URL CODEBASE_URL; - - static { - try { - JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar"); - CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/"); - } catch (Exception ex) { - throw new RuntimeException(ex); - } - } - - private class DummyJNLPFile extends JNLPFile { - - final boolean haveSecurity; - - public DummyJNLPFile(boolean haveSecurity) { - this.haveSecurity = haveSecurity; - } - - @Override - public ResourcesDesc getResources() { - return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]); - } - - @Override - public URL getCodeBase() { - return CODEBASE_URL; - } - - @Override - public SecurityDesc getSecurity() { - if (haveSecurity) { - return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null); - } else { - return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); - } - } - }; private static final String isWSA = "isWebstartApplication"; static void setStaticField(Field field, Object newValue) throws Exception { @@ -159,10 +122,10 @@ } public void testResourceCaching(String r, boolean shouldExists) throws Exception { - JNLPFile dummyJnlpFile = new DummyJNLPFile(true); + JNLPFile dummyJnlpFile = new DummyJNLPFile(); JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); - CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{JAR_URL, CODEBASE_URL}, parent); + CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{DummyJNLPFile.JAR_URL, DummyJNLPFile.CODEBASE_URL}, parent); int level = 10; if (shouldExists) { @@ -228,19 +191,18 @@ } public void testParentClassLoaderIsAskedForClasses() throws Exception { - JNLPFile dummyJnlpFile = new DummyJNLPFile(true); + JNLPFile dummyJnlpFile = new DummyJNLPFile(); final boolean[] parentWasInvoked = new boolean[1]; JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null) { - @Override protected Class<?> findClass(String name) throws ClassNotFoundException { parentWasInvoked[0] = true; throw new ClassNotFoundException(name); } }; - CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{JAR_URL, CODEBASE_URL}, parent); + CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{DummyJNLPFile.JAR_URL, DummyJNLPFile.CODEBASE_URL}, parent); try { classLoader.findClass("foo"); assertFalse("should not happen", true); @@ -252,68 +214,38 @@ @Test public void testNullFileSecurityDescApplication() throws Exception { setWSA(); - testNullFileSecurityDesc(); + Exception ex = null; + try { + testNullFileSecurityDesc(); + } catch (Exception exx) { + ex = exx; + } + Assert.assertTrue("was expected exception", ex != null); + Assert.assertTrue("was expected " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); } @Test @Remote public void testNullFileSecurityDescApplet() throws Exception { setApplet(); - testNullFileSecurityDesc(); + Exception ex = null; + try { + testNullFileSecurityDesc(); + } catch (Exception exx) { + ex = exx; + } + Assert.assertTrue("was expected exception", ex != null); + Assert.assertTrue("was expected " + NullJnlpFileException.class.getName(), ex instanceof NullJnlpFileException); } public void testNullFileSecurityDesc() throws Exception { - JNLPFile dummyJnlpFile = new DummyJNLPFile(false); - + JNLPFile dummyJnlpFile = new DummyJNLPFile() { + @Override + public SecurityDesc getSecurity() { + return new SecurityDesc(null, SecurityDesc.SANDBOX_PERMISSIONS, null); + } + }; JNLPClassLoader parent = new JNLPClassLoader(dummyJnlpFile, null); - CodeBaseClassLoader classLoader = new CodeBaseClassLoader(new URL[]{JAR_URL, CODEBASE_URL}, parent); - - Exception ex = null; - try { - classLoader.findClass("foo"); - } catch (Exception exx) { - ex = exx; - ServerAccess.logException(ex); - } - Assert.assertNotNull(ex); - Assert.assertTrue(ex instanceof ClassNotFoundException); - - //search dor resources is not relvant to null jnlp file for applets - ex = null; - URL res = null; - try { - //not cached - res = classLoader.findResource("net/sourceforge/jnlp/about/resources/notes.html"); - } catch (Exception exx) { - ex = exx; - ServerAccess.logException(ex); - } - if (JNLPRuntime.isWebstartApplication()) { - Assert.assertNull(res); - Assert.assertNotNull(ex); - Assert.assertTrue(ex instanceof NullJnlpFileException); - } else { - Assert.assertNull(ex); - Assert.assertNotNull(res); - } - - ex = null; - res = null; - try { - //now cached - res = classLoader.findResource("net/sourceforge/jnlp/about/resources/notes.html"); - } catch (Exception exx) { - ex = exx; - ServerAccess.logException(ex); - } - if (JNLPRuntime.isWebstartApplication()) { - Assert.assertNotNull(ex); - Assert.assertTrue(ex instanceof NullJnlpFileException); - Assert.assertNull(res); - } else { - Assert.assertNull(ex); - Assert.assertNotNull(res); - } } }
--- a/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java Thu Apr 25 17:05:31 2013 -0400 +++ b/tests/netx/unit/net/sourceforge/jnlp/security/appletextendedsecurity/impl/UnsignedAppletActionStorageImplTest.java Fri Apr 26 11:29:04 2013 +0200 @@ -81,7 +81,7 @@ public void wildcards1() { UnsignedAppletActionStorageImpl i1 = new UnsignedAppletActionStorageImpl(f3); UnsignedAppletActionEntry r1 = i1.getMatchingItem("http://www.walter-fendt.de/ph14e/inclplane.htm", "http://www.walter-fendt.de/ph14_jar/", Arrays.asList(new String[]{"Ph14English.jar","SchiefeEbene.jar"})); - System.out.println(r1.toString()); + ServerAccess.logOutputReprint(r1.toString()); } @Test public void allMatchingDocAndCode() {
--- a/tests/netx/unit/sun/applet/PluginAppletViewerTest.java Thu Apr 25 17:05:31 2013 -0400 +++ b/tests/netx/unit/sun/applet/PluginAppletViewerTest.java Fri Apr 26 11:29:04 2013 +0200 @@ -5,6 +5,7 @@ import java.util.concurrent.Callable; import net.sourceforge.jnlp.AsyncCall; +import net.sourceforge.jnlp.ServerAccess; import org.junit.After; import org.junit.Before; @@ -173,8 +174,8 @@ * reference number */ private static int parseAndCheckJSMessage(String message, int messageLength, - String messageType, int contextObjectID) { - System.out.println(message); + String messageType, int contextObjectID) { + ServerAccess.logOutputReprint(message); String[] parts = message.split(" "); assertEquals(messageLength, parts.length);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-extensions/net/sourceforge/jnlp/mock/DummyJNLPFile.java Fri Apr 26 11:29:04 2013 +0200 @@ -0,0 +1,77 @@ +/* +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.mock; + +import java.net.URL; +import java.util.Locale; +import net.sourceforge.jnlp.JNLPFile; +import net.sourceforge.jnlp.ResourcesDesc; +import net.sourceforge.jnlp.SecurityDesc; + + +public class DummyJNLPFile extends JNLPFile { + + + public static final URL JAR_URL; + public static final URL CODEBASE_URL; + + static { + try { + JAR_URL = new URL("http://icedtea.classpath.org/netx/about.jar"); + CODEBASE_URL = new URL("http://icedtea.classpath.org/netx/"); + } catch (Exception ex) { + throw new RuntimeException(ex); + } + } + + + @Override + public ResourcesDesc getResources() { + return new ResourcesDesc(null, new Locale[0], new String[0], new String[0]); + } + + @Override + public URL getCodeBase() { + return CODEBASE_URL; + } + + @Override + public SecurityDesc getSecurity() { + return new SecurityDesc(this, SecurityDesc.SANDBOX_PERMISSIONS, null); + } + +}