diff options
author | Jiri Vanek <[email protected]> | 2012-09-24 17:05:41 +0200 |
---|---|---|
committer | Jiri Vanek <[email protected]> | 2012-09-24 17:05:41 +0200 |
commit | cf1f7e5aec4ec8a39d6e71d7367ca70891908397 (patch) | |
tree | 7fea3e1c0b97e82aae30aff08e1bb1b77c329137 /tests/test-extensions/net | |
parent | fc1ee10f943727271803fd3d4b33265175faa703 (diff) |
Added basic ClosingLIstener support, implementation and example
Diffstat (limited to 'tests/test-extensions/net')
8 files changed, 362 insertions, 1 deletions
diff --git a/tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java b/tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java new file mode 100644 index 0000000..b9997ec --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/ClosingListener.java @@ -0,0 +1,55 @@ +/* ClosingListener.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. + */ +package net.sourceforge.jnlp; + +public abstract class ClosingListener implements ContentReaderListener { + + private ThreadedProcess process; + private ProcessAssasin assasin; + + void setProcess(ThreadedProcess p) { + this.process = p; + } + + void setAssasin(ProcessAssasin assasin) { + this.assasin = assasin; + } + + public void terminate() { + assasin.setTimeout(Long.MIN_VALUE); + } +} diff --git a/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java b/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java index b435eeb..e5dda22 100644 --- a/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java +++ b/tests/test-extensions/net/sourceforge/jnlp/ProcessAssasin.java @@ -98,6 +98,11 @@ class ProcessAssasin extends Thread { return skipInstedOfDesroy; } + void setTimeout(long timeout) { + this.timeout = timeout; + } + + @Override public void run() { long startTime = System.nanoTime() / ServerAccess.NANO_TIME_DELIMITER; diff --git a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java index 62b502b..148378e 100644 --- a/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java +++ b/tests/test-extensions/net/sourceforge/jnlp/ServerAccess.java @@ -1,5 +1,5 @@ /* ServerAccess.java -Copyright (C) 2011 Red Hat, Inc. +Copyright (C) 2011, 2012 Red Hat, Inc. This file is part of IcedTea. @@ -58,6 +58,8 @@ import java.util.List; import net.sourceforge.jnlp.browsertesting.Browser; import net.sourceforge.jnlp.browsertesting.BrowserFactory; import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.closinglisteners.AutoErrorClosingListener; +import net.sourceforge.jnlp.closinglisteners.AutoOkClosingListener; import org.junit.Assert; /** @@ -77,6 +79,11 @@ import org.junit.Assert; */ public class ServerAccess { + public static enum AutoClose { + + CLOSE_ON_EXCEPTION, CLOSE_ON_CORRECT_END, CLOSE_ON_BOTH + } + public static final long NANO_TIME_DELIMITER=1000000l; /** * java property which value containing path to default (makefile by) directory with deployed resources @@ -545,6 +552,20 @@ public class ServerAccess { public ProcessResult executeJavaws(String resource,ContentReaderListener stdoutl,ContentReaderListener stderrl) throws Exception { return executeJavaws(null, resource,stdoutl,stderrl); } + + public net.sourceforge.jnlp.ProcessResult executeBrowser(String string, AutoClose autoClose) throws Exception { + ClosingListener errClosing = null; + ClosingListener outClosing = null; + if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose == AutoClose.CLOSE_ON_EXCEPTION){ + errClosing=new AutoErrorClosingListener(); + } + if (autoClose == AutoClose.CLOSE_ON_BOTH || autoClose == AutoClose.CLOSE_ON_CORRECT_END){ + outClosing=new AutoOkClosingListener(); + } + return executeBrowser(string, outClosing, errClosing); + } + + public ProcessResult executeBrowser(String resource) throws Exception { return executeBrowser(getBrowserParams(), resource); } @@ -797,6 +818,8 @@ public class ServerAccess { log(connectionMesaage, true, true); } ProcessAssasin pa = new ProcessAssasin(t, PROCESS_TIMEOUT); + setUpClosingListener(stdoutl, pa, t); + setUpClosingListener(stderrl, pa, t); pa.start(); t.start(); while (t.getP() == null && t.deadlyException == null) { @@ -834,6 +857,13 @@ public class ServerAccess { return pr; } + private static void setUpClosingListener(ContentReaderListener listener, ProcessAssasin pa, ThreadedProcess t) { + if (listener != null && (listener instanceof ClosingListener)) { + ((ClosingListener) listener).setAssasin(pa); + ((ClosingListener) listener).setProcess(t); + } + } + /** * this is temprary solution until refactoring is fully done * Use net.sourceforge.jnlp.ProcessResult instead diff --git a/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java new file mode 100644 index 0000000..933fce6 --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoAllClosingListener.java @@ -0,0 +1,57 @@ +/* CountingClosingListener.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. + */ +package net.sourceforge.jnlp.closinglisteners; + +import net.sourceforge.jnlp.ClosingListener; + +public class AutoAllClosingListener extends ClosingListener { + + + + @Override + public void charReaded(char ch) { + + } + + @Override + public void lineReaded(String s) { + if (s.contains(AutoErrorClosingListener.MAGICAL_ERROR_CLOSING_STRING) || s.contains(AutoOkClosingListener.MAGICAL_OK_CLOSING_STRING)){ + terminate(); + } + } + +} diff --git a/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java new file mode 100644 index 0000000..aa42e1d --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoErrorClosingListener.java @@ -0,0 +1,46 @@ +/* AutoErrorClosingListener.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. + */ +package net.sourceforge.jnlp.closinglisteners; + +public class AutoErrorClosingListener extends StringBasedClosingListener { + + public static final String MAGICAL_ERROR_CLOSING_STRING = "xception"; + + public AutoErrorClosingListener() { + super(MAGICAL_ERROR_CLOSING_STRING); + } +} diff --git a/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java new file mode 100644 index 0000000..c4cfa00 --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/AutoOkClosingListener.java @@ -0,0 +1,48 @@ +/* CountingClosingListener.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. + */ +package net.sourceforge.jnlp.closinglisteners; + + +public class AutoOkClosingListener extends StringBasedClosingListener { + + public static final String MAGICAL_OK_CLOSING_STRING = "*** APPLET FINISHED ***"; + + public AutoOkClosingListener() { + super(MAGICAL_OK_CLOSING_STRING); + } + +} diff --git a/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringBasedClosingListener.java b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringBasedClosingListener.java new file mode 100644 index 0000000..ab6b28e --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringBasedClosingListener.java @@ -0,0 +1,67 @@ +/* StringBasedClosingListener.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. + */ +package net.sourceforge.jnlp.closinglisteners; + +import net.sourceforge.jnlp.ClosingListener; + +public class StringBasedClosingListener extends ClosingListener { + + private final String condition; + + public StringBasedClosingListener(String condition) { + this.condition = condition; + } + + @Override + public void charReaded(char ch) { + + } + + @Override + public void lineReaded(String s) { + if (s.contains(condition)){ + terminate(); + } + } + + + public String getCondition() { + return condition; + } + + +} diff --git a/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringMatchClosingListener.java b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringMatchClosingListener.java new file mode 100644 index 0000000..3d9d52c --- /dev/null +++ b/tests/test-extensions/net/sourceforge/jnlp/closinglisteners/StringMatchClosingListener.java @@ -0,0 +1,53 @@ +/* StringMatchClosingListener.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. + */ + +import net.sourceforge.jnlp.closinglisteners.StringBasedClosingListener; + + +public class StringMatchClosingListener extends StringBasedClosingListener { + + public StringMatchClosingListener(String s) { + super(s); + } + + @Override + public void lineReaded(String s) { + if (s.matches(getCondition())) { + terminate(); + } + } +} |