diff -r 7ae04e8d830a Makefile.am --- a/Makefile.am Thu Jun 16 16:23:26 2011 +0200 +++ b/Makefile.am Thu Jun 16 20:52:18 2011 +0200 @@ -17,6 +17,12 @@ JUNIT_RUNNER_DIR=$(TESTS_DIR)/junit-runner JUNIT_RUNNER_SRCDIR=$(TESTS_SRCDIR)/junit-runner +JNLP_TESTS_ENGINE_SRCDIR=$(TESTS_SRCDIR)/netx/jnlp_testsengine +JNLP_TESTS_SRCDIR=$(TESTS_SRCDIR)/jnlp_tests +JNLP_TESTS_ENGINE_DIR=$(TESTS_DIR)/netx/jnlp_testsengine +JNLP_TESTS_SERVER_DEPLOYDIR=$(TESTS_DIR)/jnlp_test_server +JNLP_TESTS_DIR=$(TESTS_DIR)/jnlp_tests + JUNIT_RUNNER_JAR=$(abs_top_builddir)/junit-runner.jar # Build directories @@ -449,6 +455,69 @@ @junit-runner-source-files.txt && \ $(BOOT_DIR)/bin/jar cf $@ -C $(JUNIT_RUNNER_DIR) . +junit-jnlp-dist-dirs.txt: + mkdir -p $(JNLP_TESTS_SERVER_DEPLOYDIR) + mkdir -p $(JNLP_TESTS_DIR) + mkdir -p $(JNLP_TESTS_ENGINE_DIR) + cd $(JNLP_TESTS_SRCDIR)/simple/ ; \ + find . -maxdepth 1 -mindepth 1 | sed "s/.\/*//" > $(abs_top_builddir)/$@ + +stamps/netx-dist-tests-prepare-reproducers.stamp: junit-jnlp-dist-dirs.txt + simpleReproducers=(`cat $(abs_top_builddir)/junit-jnlp-dist-dirs.txt `); \ + for dir in "$${simpleReproducers[@]}" ; do \ + mkdir -p $(JNLP_TESTS_DIR)/$$dir ; \ + $(BOOT_DIR)/bin/javac -d $(JNLP_TESTS_DIR)/$$dir/ $(JNLP_TESTS_SRCDIR)/simple/$$dir/srcs/* ; \ + d=`pwd` ; \ + cd $(JNLP_TESTS_DIR)/$$dir/ ; \ + $(BOOT_DIR)/bin/jar cf $(JNLP_TESTS_SERVER_DEPLOYDIR)/$$dir.jar * ; \ + cd $$d ; \ + cp -R $(JNLP_TESTS_SRCDIR)/simple/$$dir/resources/* $(JNLP_TESTS_SERVER_DEPLOYDIR)/ ; \ + done ; \ + mkdir -p stamps && \ + touch $@ + +netx-dist-tests-source-files.txt: + find $(JNLP_TESTS_ENGINE_SRCDIR) -name '*.java' | sort > $@ + +stamps/netx-dist-tests-compile.stamp: stamps/netx.stamp \ + junit-jnlp-dist-dirs.txt netx-dist-tests-source-files.txt + $(BOOT_DIR)/bin/javac $(IT_JAVACFLAGS) \ + -d $(JNLP_TESTS_ENGINE_DIR) \ + -classpath $(JUNIT_JAR):$(NETX_DIR)/lib/classes.jar \ + @netx-dist-tests-source-files.txt && \ + mkdir -p stamps && \ + touch $@ + +stamps/netx-dist-tests-compile-testcases.stamp: stamps/netx.stamp junit-jnlp-dist-dirs.txt\ + netx-dist-tests-source-files.txt stamps/netx-dist-tests-compile.stamp + simpleReproducers=(`cat $(abs_top_builddir)/junit-jnlp-dist-dirs.txt `); \ + for dir in "$${simpleReproducers[@]}" ; do \ + $(BOOT_DIR)/bin/javac $(IT_JAVACFLAGS) \ + -d $(JNLP_TESTS_ENGINE_DIR) \ + -classpath $(JUNIT_JAR):$(NETX_DIR)/lib/classes.jar:$(JNLP_TESTS_ENGINE_DIR) \ + $(JNLP_TESTS_SRCDIR)/simple/$$dir/testcases/* ; \ + done ; \ + mkdir -p stamps && \ + touch $@ + +run-netx-dist-tests: all-local stamps/netx.stamp junit-jnlp-dist-dirs.txt stamps/netx-dist-tests-prepare-reproducers.stamp \ + stamps/netx-dist-tests-compile.stamp stamps/netx-dist-tests-compile-testcases.stamp $(JUNIT_RUNNER_JAR) + cd $(JNLP_TESTS_ENGINE_DIR) ; \ + class_names= ; \ + for test in `find -type f` ; do \ + class_name=`echo $$test | sed -e 's|\.class$$||' -e 's|^\./||'` ; \ + class_name=`echo $$class_name | sed -e 's|/|.|g' ` ; \ + class_names="$$class_names $$class_name" ; \ + done ; \ + echo $$class_names ; \ + CLASSPATH=$(NETX_DIR)/lib/classes.jar:$(JUNIT_JAR):$(JUNIT_RUNNER_JAR):. \ + $(BOOT_DIR)/bin/java -Dtest.server.dir=$(JNLP_TESTS_SERVER_DEPLOYDIR) -Djavaws.build.bin=$(DESTDIR)$(bindir)/javaws \ + -Xbootclasspath:$(RUNTIME) CommandLine $$class_names \ + > stdout.log 2> stderr.log ; \ + cat stdout.log ; \ + cat stderr.log >&2 + -xsltproc $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(JNLP_TESTS_ENGINE_DIR)/tests-output.xml > $(TESTS_DIR)/index_reproducers.html + netx-unit-tests-source-files.txt: find $(NETX_UNIT_TEST_SRCDIR) -name '*.java' | sort > $@ @@ -483,9 +552,9 @@ > stdout.log 2> stderr.log ; \ cat stdout.log ; \ cat stderr.log >&2 - -xsltproc $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(TESTS_DIR)/netx/unit/tests-output.xml > $(TESTS_DIR)/index_unit.html + -xsltproc $(TESTS_SRCDIR)/$(REPORT_STYLES_DIRNAME)/jreport.xsl $(NETX_UNIT_TEST_DIR)/tests-output.xml > $(TESTS_DIR)/index_unit.html -clean-netx-tests: clean-netx-unit-tests clean-junit-runner +clean-netx-tests: clean-netx-unit-tests clean-junit-runner clean-netx-dist-tests if [ -e $(TESTS_DIR)/netx ]; then \ rmdir $(TESTS_DIR)/netx ; \ fi @@ -504,6 +573,16 @@ rm -rf $(TESTS_DIR)/$(REPORT_STYLES_DIRNAME)/ rm -f $(TESTS_DIR)/index*.html +clean-netx-dist-tests: + rm -f netx-dist-tests-source-files.txt + rm -rf $(JNLP_TESTS_DIR) + rm -rf $(JNLP_TESTS_SERVER_DEPLOYDIR) + rm -rf $(JNLP_TESTS_ENGINE_DIR) + rm -f stamps/netx-dist-tests-compile.stamp + rm -f stamps/netx-dist-tests-prepare-reproducers.stamp + rm -f stamps/netx-dist-tests-compile-testcases.stamp + rm -f junit-jnlp-dist-dirs.txt + # plugin tests if ENABLE_PLUGIN diff -r 7ae04e8d830a tests/jnlp_tests/README --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/README Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,1 @@ +Each file in directory simple must follows naming convention and is compiled/jared automatically into server's working directory and content of resources likewise. The name of jnlp is independent, and there can be even more jnlps for each future jar. Files in advanced directory have to care about themselves, but even those can have some parts inside simple directory, so some parts of them are processed automatically. There are three reproducers – simpletest1, simpletest2 and deadlocktest, which tests test’s suite itself and serve as examples of behaviour. diff -r 7ae04e8d830a tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest.jnlp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/deadlocktest/resources/deadlocktest.jnlp Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,53 @@ + + + + + simpletest1 + NetX + + simpletest1 + + + + + + + + + diff -r 7ae04e8d830a tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/deadlocktest/srcs/DeadlockTest.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,51 @@ +/* DeadlockTest.java +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. + */ + +public class DeadlockTest{ + + public static void main(String[] args) throws Exception{ + long startTime=System.nanoTime()/1000000l; +while(true){ +long now=System.nanoTime()/1000000l; +Thread.sleep(10); +if (now-startTime>30000){ + System.out.println("This process is hanging more then 30s. Should be killed"); + System.exit(5); +} +} + } +} diff -r 7ae04e8d830a tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/deadlocktest/testcases/DeadLockTestTest.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,79 @@ +/* DeadLockTestTest.java +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. + */ + +import java.util.ArrayList; +import java.util.List; +import net.sourceforge.jnlp.ServerAccess; +import org.junit.Assert; + +import org.junit.Test; + +public class DeadLockTestTest { + + private static ServerAccess server = new ServerAccess(); + + + + @Test + public void testDeadLockTestTerminated() throws Exception { + System.out.println("connecting deadlocktest request"); + ServerAccess.ProcessResult pr=server.executeJavawsHeadless(null,"/deadlocktest.jnlp"); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + Assert.assertFalse(pr.stdout.contains("This process is hanging more then 30s. Should be killed")); +// Assert.assertTrue(pr.stderr.contains("xception"));, exception is thrown by engine,not by application + Assert.assertTrue(pr.wasTerminated); + Assert.assertEquals(null, pr.returnValue);//killed process have no value + } + + + + + } + + + + + + + + + + + + + diff -r 7ae04e8d830a tests/jnlp_tests/simple/simpletest1/resources/simpletest1.jnlp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/simpletest1/resources/simpletest1.jnlp Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,53 @@ + + + + + simpletest1 + NetX + + simpletest1 + + + + + + + + + diff -r 7ae04e8d830a tests/jnlp_tests/simple/simpletest1/srcs/SimpleTest1.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/simpletest1/srcs/SimpleTest1.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,43 @@ +/* SimpleTest1.java +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. + */ + +public class SimpleTest1{ + + public static void main(String[] args){ + System.out.println("Good simple javaws exapmle"); + } +} diff -r 7ae04e8d830a tests/jnlp_tests/simple/simpletest1/testcases/SimpleTest1Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/simpletest1/testcases/SimpleTest1Test.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,79 @@ +/* SimpleTest1Test.java +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. + */ + + +import net.sourceforge.jnlp.ServerAccess; +import org.junit.Assert; + +import org.junit.Test; + +public class SimpleTest1Test { + + private static ServerAccess server = new ServerAccess(); + + + + @Test + public void testSimpletest1lunchOk() throws Exception { + System.out.println("connecting simpletest1 request"); + ServerAccess.ProcessResult pr=server.executeJavawsHeadless(null,"/simpletest1.jnlp"); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + Assert.assertTrue(pr.stdout.contains("Good simple javaws exapmle")); + Assert.assertFalse(pr.stderr.contains("xception")); + Assert.assertFalse(pr.wasTerminated); + Assert.assertEquals((Integer)0, pr.returnValue); + } + + + + + + } + + + + + + + + + + + + + diff -r 7ae04e8d830a tests/jnlp_tests/simple/simpletest2/resources/simpletest2.jnlp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/simpletest2/resources/simpletest2.jnlp Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,53 @@ + + + + + simpletest2 + NetX + + simpletest2 + + + + + + + + + diff -r 7ae04e8d830a tests/jnlp_tests/simple/simpletest2/srcs/SimpleTest2.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/simpletest2/srcs/SimpleTest2.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,44 @@ +/* SimpleTest2.java +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. + */ + +public class SimpleTest2{ + + public static void main(String[] args){ +throw new RuntimeException("Correct exception"); + + } +} diff -r 7ae04e8d830a tests/jnlp_tests/simple/simpletest2/testcases/SimpleTest2Test.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/jnlp_tests/simple/simpletest2/testcases/SimpleTest2Test.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,76 @@ +/* SimpleTest2Test.java +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. + */ + +import net.sourceforge.jnlp.ServerAccess; +import org.junit.Assert; + +import org.junit.Test; + +public class SimpleTest2Test { + + private static ServerAccess server = new ServerAccess(); + + + @Test + public void testSimpletest2lunchException() throws Exception { + System.out.println("connecting simpletest2 request"); + ServerAccess.ProcessResult pr=server.executeJavawsHeadless(null,"/simpletest2.jnlp"); + System.out.println(pr.stdout); + System.err.println(pr.stderr); + Assert.assertTrue(pr.stdout.trim().length() < 1); + Assert.assertTrue(pr.stderr.contains("Correct exception")); + Assert.assertTrue(pr.stderr.contains("Exception")); + Assert.assertFalse(pr.wasTerminated); + //Assert.assertFalse(0==pr.returnValue);exception and still returned 0? + } + + + + } + + + + + + + + + + + + + diff -r 7ae04e8d830a tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ResourcesTest.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,96 @@ +/* ParserMalformedXml.java +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 java.io.File; +import java.io.FileFilter; +import org.junit.Assert; + +import org.junit.Test; + +public class ResourcesTest { + + private static ServerAccess server = new ServerAccess(); + + @Test + public void testResourcesExists() throws Exception { + File[] simpleContent = server.getDir().listFiles(new FileFilter() { + + public boolean accept(File file) { + if (!file.isDirectory()) { + return true; + } else { + return false; + } + } + }); + Assert.assertNotNull(simpleContent); + Assert.assertTrue(simpleContent.length > 5); + + for (int i = 0; i < simpleContent.length; i++) { + File file = simpleContent[i]; + System.err.println(file.getName()); + if (file.getName().toLowerCase().endsWith(".jnlp")) { + String c = server.getResourceAsString("/" + file.getName()); + Assert.assertTrue(c.contains("<")); + Assert.assertTrue(c.contains(">")); + Assert.assertTrue(c.contains("jnlp")); + Assert.assertTrue(c.contains("resources")); + Assert.assertTrue(c.replaceAll("\\s*", "").contains("")); + + } else { + byte[] c = server.getResourceAsBytes("/" + file.getName()).toByteArray(); + Assert.assertEquals(c.length, file.length()); + } + + } + + } +} + + + + + + + + + + + + + diff -r 7ae04e8d830a tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/netx/jnlp_testsengine/net/sourceforge/jnlp/ServerAccess.java Thu Jun 16 20:52:18 2011 +0200 @@ -0,0 +1,607 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ +package net.sourceforge.jnlp; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.net.HttpURLConnection; +import java.net.ServerSocket; +import java.net.Socket; +import java.net.URL; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.StringTokenizer; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * @author jvanek + */ +public class ServerAccess { + + private static ServerLuncher server; + private static final String version = "2"; + public static int READ_TIMEOUT = 1000; + public static String SERVER_NAME = "localhost"; + public static long PROCESS_TIMEOUT = 10 * 1000;//ms + private static Set terminated = new HashSet(); + + public static void main(String[] args) throws IOException { + int i = findFreePort(); + System.out.println(i); + + } + + public static int findFreePort() + throws IOException { + ServerSocket findPortTestingSocket = new ServerSocket(0); + int port = findPortTestingSocket.getLocalPort(); + findPortTestingSocket.close(); + return port; + } + + public ServerAccess() { + + getInstance(); + + + } + + public static ServerLuncher getInstance() { + if (server == null) { + server = getIndependentInstance(); + } + return server; + } + + //usefull for testing application loading from different url then his + public static ServerLuncher getIndependentInstance() { + + String dir = (System.getProperty("test.server.dir")); + if (dir == null || dir.trim().length() == 0 || !new File(dir).exists() || !new File(dir).isDirectory()) { + throw new RuntimeException("test.server.dir property must be set to valid directory!"); + } + try { + int port = findFreePort(); + ServerLuncher lServerLuncher = new ServerLuncher(port, new File(dir)); + new Thread(lServerLuncher).start(); + return lServerLuncher; + } catch (Exception ex) { + throw new RuntimeException(ex); + } + + } + + public String getJavawsLocation() { + return System.getProperty("javaws.build.bin"); + } + + public File getJavawsFile() { + return new File(System.getProperty("javaws.build.bin")); + } + + @Test + public void ensureJavaws() throws Exception { + String javawsValue = getJavawsLocation(); + Assert.assertNotNull(javawsValue); + Assert.assertTrue(javawsValue.trim().length() > 2); + File javawsFile = getJavawsFile(); + Assert.assertTrue(javawsFile.exists()); + Assert.assertFalse(javawsFile.isDirectory()); + + + } + + @Test + public void ensureServer() throws Exception { + + Assert.assertNotNull(server.getPort()); + Assert.assertNotNull(server.getDir()); + Assert.assertTrue(server.getPort() > 999); + Assert.assertTrue(server.getDir().toString().trim().length() > 2); + + Assert.assertTrue(server.getDir().exists()); + Assert.assertTrue(server.getDir().isDirectory()); + + File portFile = new File(server.getDir(), "server.port"); + File dirFile = new File(server.getDir(), "server.dir"); + + saveFile(server.getDir().getAbsolutePath(), dirFile); + saveFile(server.getPort().toString(), portFile); + saveFile(server.getPort().toString(), portFile); + + Assert.assertTrue(portFile.exists()); + Assert.assertTrue(dirFile.exists()); + Assert.assertTrue(server.getDir().listFiles().length > 1); + + String portFileContent = getContentOfStream(new FileInputStream(portFile)); + String dirFileContent = getContentOfStream(new FileInputStream(dirFile)); + + + + URL portUrl = new URL("http", "localhost", server.getPort(), "/server.port"); + URL dirUrl = new URL("http", "localhost", server.getPort(), "/server.dir"); + + + String portUrlContent = getContentOfStream(portUrl.openConnection().getInputStream()); + String dirUrlContent = getContentOfStream(dirUrl.openConnection().getInputStream()); + + + Assert.assertEquals(portUrlContent.trim(), portFileContent.trim()); + Assert.assertEquals(dirUrlContent.trim(), dirFileContent.trim()); + Assert.assertEquals(new File(dirUrlContent.trim()), server.getDir()); + Assert.assertEquals(new Integer(portUrlContent.trim()), server.getPort()); + + + + + } + + public int getPort() { + if (server == null) { + getInstance(); + } + //if (!server.isRunning()) throw new RuntimeException("Server mysteriously died"); + return server.getPort(); + + } + + public File getDir() { + if (server == null) { + getInstance(); + } + // if (!server.isRunning()) throw new RuntimeException("Server mysteriously died"); + return server.getDir(); + + } + + public boolean isRunning() { + if (server == null) { + getInstance(); + } + //if (!server.isRunning()) throw new RuntimeException("Server mysteriously died"); + return server.isRunning(); + + } + + public ByteArrayOutputStream getResourceAsBytes(String resource) throws IOException { + URL u = new URL("http", SERVER_NAME, getPort(), resource); + return getResourceAsBytes(u); + + } + + public String getResourceAsString(String resource) throws IOException { + URL u = new URL("http", SERVER_NAME, getPort(), resource); + return getResourceAsString(u); + + } + + public static ByteArrayOutputStream getBytesFromStream(InputStream is) throws IOException { + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + int nRead; + byte[] data = new byte[16384]; + while ((nRead = is.read(data, 0, data.length)) != -1) { + buffer.write(data, 0, nRead); + } + buffer.flush(); + return buffer; + } + + public static String getContentOfStream(InputStream is) throws IOException { + try { + BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); + StringBuilder sb = new StringBuilder(); + while (true) { + String s = br.readLine(); + if (s == null) { + break; + } + sb.append(s).append("\n"); + + } + return sb.toString(); + } finally { + is.close(); + } + + } + + public static ByteArrayOutputStream getResourceAsBytes(URL u) throws IOException { + HttpURLConnection connection = (HttpURLConnection) u.openConnection(); + connection = (HttpURLConnection) u.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(true); + connection.setReadTimeout(READ_TIMEOUT); + connection.connect(); + return getBytesFromStream(connection.getInputStream()); + + } + + public static String getResourceAsString(URL u) throws IOException { + HttpURLConnection connection = (HttpURLConnection) u.openConnection(); + connection = (HttpURLConnection) u.openConnection(); + connection.setRequestMethod("GET"); + connection.setDoOutput(true); + connection.setReadTimeout(READ_TIMEOUT); + connection.connect(); + return getContentOfStream(connection.getInputStream()); + } + + private static void saveFile(String content, File f) throws IOException { + Writer output = new BufferedWriter(new FileWriter(f)); + output.write(content); + output.flush(); + output.close(); + } + + public ProcessResult executeJavawsHeadless(List otherargs, String resource) throws Exception { + if (otherargs == null) { + otherargs = new ArrayList(1); + } + List headlesList = new ArrayList(otherargs); + headlesList.add("-headless"); + return executeJavaws(headlesList, resource); + } + + public ProcessResult executeJavaws(List otherargs, String resource) throws Exception { + return executeProcessUponURL(getJavawsLocation(), otherargs, new URL("http", SERVER_NAME, getPort(), resource)); + } + + private static ProcessResult executeProcessUponURL(String toBeExecuted, List otherargs, URL u) throws Exception { + Assert.assertNotNull(u); + Assert.assertNotNull(toBeExecuted); + Assert.assertTrue(toBeExecuted.trim().length() > 1); + if (otherargs == null) { + otherargs = new ArrayList(1); + } + List urledArgs = new ArrayList(otherargs); + urledArgs.add(0, toBeExecuted); + urledArgs.add(u.toString()); + return executeProcess(urledArgs); + } + + private static class ThreadedProcess extends Thread { + + Process p = null; + List args; + Integer exitCode; + Boolean running; + + public Boolean isRunning() { + return running; + } + + public Integer getExitCode() { + return exitCode; + } + + public ThreadedProcess(List args) { + + this.args = args; + } + + public Process getP() { + return p; + } + + @Override + public void run() { + try { + running = true; + Runtime r = Runtime.getRuntime(); + p = r.exec(args.toArray(new String[0])); + exitCode = p.waitFor(); + } catch (Exception ex) { + if (ex instanceof InterruptedException) { + terminated.add(this); + } else { + throw new RuntimeException(ex); + } + } finally { + running = false; + } + } + } + + public static ProcessResult executeProcess(final List args) throws Exception { + + ThreadedProcess t = new ThreadedProcess(args); + ProcessAssasin pa = new ProcessAssasin(t, PROCESS_TIMEOUT); + pa.start(); + t.start(); + while (t.getP() == null) { + Thread.sleep(100); + } + ContentReader crs = new ContentReader(t.getP().getInputStream()); + ContentReader cre = new ContentReader(t.getP().getErrorStream()); + + OutputStream out = t.getP().getOutputStream(); + if (out != null) { + out.close(); + } + + new Thread(crs).start(); + new Thread(cre).start(); + while (t.isRunning()) { + Thread.sleep(100); + } + pa.setCanRun(false); + // System.out.println(t.getP().exitValue()); when process is killed, this throws exception + + return new ProcessResult(crs.getContent(), cre.getContent(), t.getP(), pa.wasTerminated(), t.getExitCode()); + } + + static class ServerLuncher implements Runnable { + + private boolean running; + private final Integer port; + private final File dir; + + public ServerLuncher(Integer portt, File dirr) { + port = portt; + dir = dirr; + System.err.println("port: " + port); + System.err.println("dir: " + dir); + } + + public boolean isRunning() { + return running; + } + + public Integer getPort() { + return port; + } + + public File getDir() { + return dir; + } + + public ServerLuncher(File dir) { + this(8181, dir); + } + + public ServerLuncher(Integer port) { + + this(port, new File(System.getProperty("user.dir"))); + } + + public ServerLuncher() { + this(8181, new File(System.getProperty("user.dir"))); + + } + + public void run() { + running = true; + try { + ServerSocket s = new ServerSocket( + port); + while (running) { + new TinyHttpdImpl(s.accept(), dir, port); + } + } catch (Exception e) { + e.printStackTrace(); + } finally { + running = false; + } + + } + + class TinyHttpdImpl extends Thread { + + Socket c; + private final File dir; + private final int port; + private boolean canRun = true; + + public void setCanRun(boolean canRun) { + this.canRun = canRun; + } + + public TinyHttpdImpl(Socket s, File f, int port) { + c = s; + this.dir = f; + this.port = port; + start(); + } + + public int getPort() { + return port; + } + + @Override + public void run() { + try { + BufferedReader i = new BufferedReader(new InputStreamReader(c.getInputStream())); + DataOutputStream o = new DataOutputStream(c.getOutputStream()); + try { + while (canRun) { + String s = i.readLine(); + if (s.length() < 1) { + break; + } + if (s.startsWith("GET")) { + StringTokenizer t = new StringTokenizer(s, " "); + t.nextToken(); + String p = t.nextToken(); + p = (".".concat(((p.endsWith("/")) ? p.concat( + "index.html") : p))).replace('/', File.separatorChar); + File pp = new File(dir, p); + int l = (int) pp.length(); + byte[] b = new byte[l]; + FileInputStream f = new FileInputStream(pp); + f.read(b); + o.writeBytes("HTTP/1.0 200 OK\nConten" + + "t-Length:" + l + "\n\n"); + o.write(b, 0, l); + } + } + } catch (Exception e) { + o.writeBytes("HTTP/1.0 404 ERROR\n\n\n"); + e.printStackTrace(); + } + o.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + private static class ProcessAssasin extends Thread { + + long timeout; + private final ThreadedProcess p; + //false == is disabled:( + private boolean canRun = true; + private boolean wasTerminated = false; + + /** + * + * @param p + * @param timeout - time to die in milis + */ + public ProcessAssasin(ThreadedProcess p, long timeout) { + this.p = (p); + this.timeout = timeout; + + + } + + public void setCanRun(boolean canRun) { + this.canRun = canRun; + } + + public boolean isCanRun() { + return canRun; + } + + public boolean wasTerminated() { + return wasTerminated; + } + + @Override + public void run() { + + long startTime = System.nanoTime() / 1000000l; + while (canRun) { + try { + + long time = System.nanoTime() / 1000000l; + //System.out.println(time - startTime); + //System.out.println((time - startTime) > timeout); + if ((time - startTime) > timeout) { + System.err.println("Timeouted " + p.toString() + " .. killing"); + System.err.flush(); + wasTerminated = true; + p.interrupt(); + while (!terminated.contains(p)) { + Thread.sleep(100); + } + System.err.println("Timeouted " + p.toString() + " .. killed"); + System.err.flush(); + break; + + + } + } catch (Exception ex) { + ex.printStackTrace(); + } + } + } + } + + public static class ProcessResult { + + public final String stdout; + public final String stderr; + public final Process process; + public final Integer returnValue; + public final boolean wasTerminated; + + public ProcessResult(String stdout, String stderr, Process process, boolean wasTerminated, Integer r) { + this.stdout = stdout; + this.stderr = stderr; + this.process = process; + this.wasTerminated = wasTerminated; + this.returnValue = r; + } + } + + private static class ContentReader implements Runnable { + + StringBuilder sb = new StringBuilder(); + private final InputStream is; + private boolean done; + + public String getContent() { + return sb.toString(); + } + + public ContentReader(InputStream is) throws IOException { + this.is = is; + } + + /** + * Blocks until the copy is complete, or until the thread is interrupted + */ + //???????????????????? + public synchronized void waitUntilDone() throws InterruptedException { + boolean interrupted = false; + + // poll interrupted flag, while waiting for copy to complete + while (!(interrupted = Thread.interrupted()) && !done) { + wait(1000); + } + + if (interrupted) { + System.out.println("Stream copier: throwing InterruptedException"); + //throw new InterruptedException(); + } + } + + @Override + public void run() { + try { + Reader br = new InputStreamReader(is, "UTF-8"); + + while (true) { + int s = br.read(); + if (s < 0) { + break; + } + + sb.append(((char) s)); + + } + //do not want to bother output with terminations + } catch (Exception ex) { + //ex.printStackTrace(); + } finally { + try { + is.close(); + } catch (Exception ex) { + // ex.printStackTrace(); + } finally { + done = true; + } + } + + } + } +}