diff options
author | Jiri Vanek <jvanek@redhat.com> | 2012-07-02 15:08:21 +0200 |
---|---|---|
committer | Jiri Vanek <jvanek@redhat.com> | 2012-07-02 15:08:21 +0200 |
commit | d71e609b1279077474135364ed4bb223e068d0bd (patch) | |
tree | 28544c882d03f00e270b8b6f1d15130dea63e17c /tests/test-extensions-tests/net/sourceforge/jnlp | |
parent | d11831804f320ce432b904032d5cfbf00c1a198b (diff) |
Refactored reproducers directry structure
Diffstat (limited to 'tests/test-extensions-tests/net/sourceforge/jnlp')
-rw-r--r-- | tests/test-extensions-tests/net/sourceforge/jnlp/ResourcesTest.java | 379 | ||||
-rw-r--r-- | tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java | 233 |
2 files changed, 612 insertions, 0 deletions
diff --git a/tests/test-extensions-tests/net/sourceforge/jnlp/ResourcesTest.java b/tests/test-extensions-tests/net/sourceforge/jnlp/ResourcesTest.java new file mode 100644 index 0000000..0116152 --- /dev/null +++ b/tests/test-extensions-tests/net/sourceforge/jnlp/ResourcesTest.java @@ -0,0 +1,379 @@ +/* ResourcesTest.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 java.io.FileInputStream; +import java.io.IOException; +import java.net.URI; +import java.util.Arrays; +import java.util.List; +import net.sourceforge.jnlp.browsertesting.Browser; +import net.sourceforge.jnlp.browsertesting.BrowserFactory; +import net.sourceforge.jnlp.browsertesting.BrowserTest; +import net.sourceforge.jnlp.browsertesting.Browsers; +import net.sourceforge.jnlp.annotations.NeedsDisplay; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import net.sourceforge.jnlp.browsertesting.browsers.LinuxBrowser; +import net.sourceforge.jnlp.annotations.TestInBrowsers; +import org.junit.Assert; + +import org.junit.Test; + +public class ResourcesTest extends BrowserTest{ + + + @Test + @NeedsDisplay + public void testNonExisitngBrowserWillNotDeadlock() throws Exception { + server.setCurrentBrowser(Browsers.none); + ServerAccess.ProcessResult pr = server.executeBrowser("simpletest1.jnlp"); + Assert.assertNull(pr.process); + Assert.assertEquals(pr.stderr, ""); + Assert.assertEquals(pr.stdout, ""); + Assert.assertTrue(pr.wasTerminated); + Assert.assertTrue(pr.returnValue < 0); + junit.framework.Assert.assertNotNull(pr.deadlyException); + } + + @Test + public void testUnexistingProcessWillFailRecognizedly() throws Exception { + server.setCurrentBrowser(Browsers.none); + List<String> al=Arrays.asList(new String[] {"definietly_not_Existing_process"}); + ServerAccess.ProcessResult pr = server.executeProcess(al); + Assert.assertNull(pr.process); + Assert.assertEquals(pr.stderr, ""); + Assert.assertEquals(pr.stdout, ""); + Assert.assertTrue(pr.wasTerminated); + Assert.assertTrue(pr.returnValue < 0); + junit.framework.Assert.assertNotNull(pr.deadlyException); + } + + @Test + @TestInBrowsers(testIn=Browsers.none) + public void testNonExisitngBrowserWillNotCauseMess() throws Exception { + ServerAccess.ProcessResult pr = server.executeBrowser("simpletest1.jnlp"); + Assert.assertNull(pr.process); + Assert.assertEquals(pr.stderr, ""); + Assert.assertEquals(pr.stdout, ""); + Assert.assertTrue(pr.wasTerminated); + Assert.assertTrue(pr.returnValue < 0); + junit.framework.Assert.assertNotNull(pr.deadlyException); + } + + @Test + public void testBrowsers2() throws Exception { + List<Browser> a = BrowserFactory.getFactory().getAllBrowsers(); + Assert.assertNotNull("returned browsers array must not be null", a); + Assert.assertTrue("at least one browser must be configured", a.size() > 0); + for (Browser b : a) { + testBrowser(b); + } + + } + + @Test + @TestInBrowsers(testIn = Browsers.all) + public void testBrowser3() throws Exception { + testBrowser(server.getCurrentBrowser()); + + + } + + @Test + public void testBrowsers1() throws Exception { + BrowserFactory bf = new BrowserFactory(null); + int expected = 0; + Assert.assertTrue("Created from null there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + bf = new BrowserFactory(""); + expected = 0; + Assert.assertTrue("Created from empty there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + String s = "dsgrdg"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from nonsense " + s + " there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "sgrg/jkik"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from nonsense " + s + " there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox + "/jkik"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from nonsense " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "sgrg/jkik:sege"; + bf = new BrowserFactory(s); + expected = 0; + Assert.assertTrue("Created from two nonsenses " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + Browsers.firefox; + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec(); + bf = new BrowserFactory(s); + expected = 1; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "something/somewhere/" + Browsers.firefox.toExec(); + bf = new BrowserFactory(s); + expected = 1; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "something/somewhere/" + Browsers.firefox.toExec() + ":" + "something/somewhere/" + Browsers.opera.toExec(); + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = "something/somewhere/" + Browsers.firefox.toExec() + ":" + "something/somewhere/" + Browsers.opera.toExec() + ":" + Browsers.chromiumBrowser; + bf = new BrowserFactory(s); + expected = 3; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + "vfdgf" + ":" + Browsers.googleChrome.toExec(); + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + Browsers.chromiumBrowser + ":" + Browsers.googleChrome.toExec() + ":" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 4; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + testFullFactory(bf); + + s = "fgfd/" + Browsers.firefox.toExec() + ":" + "/fgfd/" + Browsers.chromiumBrowser + ":" + "fgfd/dfsdf/" + Browsers.googleChrome.toExec() + ":" + "/g/fgfd/" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 4; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + testFullFactory(bf); + + s = Browsers.firefox.toExec() + ":" + ":" + Browsers.googleChrome.toExec() + ":" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 3; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = Browsers.firefox.toExec() + ":" + ":" + ":" + Browsers.opera; + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = ":" + ":" + Browsers.googleChrome.toExec() + ":"; + bf = new BrowserFactory(s); + expected = 1; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + s = ":" + Browsers.firefox.toExec() + ":bfgbfg/fddf/" + Browsers.googleChrome.toExec() + ":"; + bf = new BrowserFactory(s); + expected = 2; + Assert.assertTrue("Created from " + s + "there must be " + expected + " browsers in factory. Is" + bf.getAllBrowsers().size(), bf.getAllBrowsers().size() == expected); + + + + + } + + @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]; + ServerAccess.logOutputReprint(file.getName()); + //server port have in fact no usage in converting filename to uri-like-filename. + //But if there is null, instead if some number, then nullpointer exception is thrown (Integer->int). + //So I'm using "real" currently used port, instead of some random value. + URI u = new URI((String) null, (String) null, (String) null, server.getPort(), file.getName(), (String) null, null); + ServerAccess.logOutputReprint(" ("+u.toString()+")"); + String fname = u.toString(); + if (file.getName().toLowerCase().endsWith(".jnlp")) { + String c = server.getResourceAsString("/" + fname); + Assert.assertTrue(c.contains("<")); + Assert.assertTrue(c.contains(">")); + Assert.assertTrue(c.contains("jnlp")); + Assert.assertTrue(c.contains("resources")); + Assert.assertTrue(c.replaceAll("\\s*", "").contains("</jnlp>")); + + } else { + byte[] c = server.getResourceAsBytes("/" + fname).toByteArray(); + Assert.assertEquals(c.length, file.length()); + } + + } + + } + + @Test + @NeedsDisplay + @TestInBrowsers(testIn = Browsers.one) + public void testListeners() throws Exception { + final StringBuilder o1 = new StringBuilder(); + final StringBuilder e1 = new StringBuilder(); + final StringBuilder o2 = new StringBuilder(); + final StringBuilder e2 = new StringBuilder(); + final ContentReaderListener lo = new ContentReaderListener() { + + @Override + public void charReaded(char ch) { + //ServerAccess.logOutputReprint("OO recieved char: "+ch); + o1.append(ch); + } + + @Override + public void lineReaded(String s) { + //ServerAccess.logOutputReprint("OO recieved line: "+s); + o2.append(s).append("\n"); + } + }; + ContentReaderListener le = new ContentReaderListener() { + + @Override + public void charReaded(char ch) { + //ServerAccess.logOutputReprint("EE recieved char: "+ch); + e1.append(ch); + } + + @Override + public void lineReaded(String s) { + //ServerAccess.logOutputReprint("EE recieved line: "+s); + e2.append(s).append("\n"); + } + }; + ServerAccess.ProcessResult pr=server.executeBrowser("simpletest1.jnlp",le,lo); + server.setCurrentBrowser(BrowserFactory.getFactory().getFirst().getID()); + Assert.assertNotNull(server.getCurrentBrowsers()); + Assert.assertNotNull(server.getCurrentBrowser()); +// ServerAccess.logOutputReprint("total o"); +// ServerAccess.logOutputReprint(pr.stdout); +// ServerAccess.logOutputReprint("total e"); +// ServerAccess.logOutputReprint(pr.stderr); + Assert.assertEquals(pr.stdout, o1.toString()); + Assert.assertEquals(pr.stderr, e1.toString()); + //the last \n is mandatory as las tline is flushed also when proces dies + Assert.assertEquals(pr.stdout.replace("\n", ""), o2.toString().replace("\n", "")); + Assert.assertEquals(pr.stderr.replace("\n", ""), e2.toString().replace("\n", "")); + + } + + private void testFullFactory(BrowserFactory bf) { + Assert.assertEquals(bf.getBrowser(Browsers.chromiumBrowser).getID(), Browsers.chromiumBrowser); + Assert.assertEquals(bf.getBrowser(Browsers.googleChrome).getID(), Browsers.googleChrome); + Assert.assertEquals(bf.getBrowser(Browsers.firefox).getID(), Browsers.firefox); + Assert.assertEquals(bf.getBrowser(Browsers.opera).getID(), Browsers.opera); + } + + private void testBrowser(Browser browser) throws IOException { + File f1 = null; + if (browser.getDefaultPluginExpectedLocation() != null) { + f1 = new File(browser.getDefaultPluginExpectedLocation()); + } + File f2 = null; + if (browser.getUserDefaultPluginExpectedLocation() != null) { + f2 = new File(browser.getUserDefaultPluginExpectedLocation()); + } + if (f1 != null) { + Assert.assertTrue("browser's plugins location should exist " + f1.toString() + " for " + browser.getID().toString(), f1.exists()); + } + if (f2 != null) { + Assert.assertTrue("browser's users-plugins location should exist " + f2.toString() + " for " + browser.getID().toString(), f2.exists()); + } + + File[] ff1 = new File[0]; + if (f1 != null) { + ff1 = f1.listFiles(); + } + + File[] ff2 = new File[0]; + if (f2 != null) { + ff2 = f2.listFiles(); + } + + Assert.assertTrue("at least one of browser's plugins directory should contains at least one file didn't. For " + browser.getID().toString(), ff1.length + ff2.length > 0); + + ff1 = new File[0]; + if (f1 != null) { + ff1 = f1.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + return (pathname.getName().equals(LinuxBrowser.DEFAULT_PLUGIN_NAME)); + } + }); + } + + ff2 = new File[0]; + if (f2 != null) { + ff2 = f2.listFiles(new FileFilter() { + + @Override + public boolean accept(File pathname) { + return (pathname.getName().equals(LinuxBrowser.DEFAULT_PLUGIN_NAME)); + } + }); + } + + Assert.assertTrue("browser's plugins directories should contains exactly one " + LinuxBrowser.DEFAULT_PLUGIN_NAME + ", but didnt for " + browser.getID().toString(), + ff1.length + ff2.length == 1); + String currentPath = server.getJavawsFile().getParentFile().getParentFile().getAbsolutePath(); + + File[] ff; + if (ff1.length == 1) { + ff = ff1; + } else { + ff = ff2; + } + String s = ServerAccess.getContentOfStream(new FileInputStream(ff[0]), "ASCII"); + Assert.assertTrue("browser's plugins shoud points to" + currentPath + ", but didnt", + s.contains(s)); + } +} diff --git a/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java b/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java new file mode 100644 index 0000000..25415be --- /dev/null +++ b/tests/test-extensions-tests/net/sourceforge/jnlp/ServerAccessTest.java @@ -0,0 +1,233 @@ +/* ServerAccessTest.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.FileInputStream; +import java.net.URL; +import org.junit.Assert; +import org.junit.Test; + +/** + * + * This class provides access to virtual server and stuff around. + * It can find unoccupied port, start server, provides its singleton instantiation, lunch parallel instantiations, + * read location of installed (tested javaws) see javaws.build.bin java property, + * location of server www root on file system (see test.server.dir java property), + * stubs for lunching javaws and for locating resources and read resources. + * + * It can also execute processes with timeout (@see PROCESS_TIMEOUT) (used during lunching javaws) + * Some protected apis are exported because public classes in this package are put to be tested by makefile. + * + * There are included test cases which show some basic usages. + * + * + */ +public class ServerAccessTest { + + ServerAccess serverAccess = new ServerAccess(); + + @Test + public void testsProcessResultFiltering() throws Exception { + ProcessResult pn = new ProcessResult(null, null, null, true, 0, null); + Assert.assertNull(pn.notFilteredStdout); + Assert.assertNull(pn.stdout); + Assert.assertNull(pn.stderr); + String fakeOut2 = + "EMMA: processing instrumentation path ...\n" + + "EMMA: package [net.sourceforge.filebrowser] contains classes [ArrayOfString] without full debug info\n" + + "EMMA: instrumentation path processed in 1407 ms\n" + + "test stage 1\n" + + "test stage 2\n" + + "EMMA: The intruder!\n" + + "test stage 3\n" + + "EMMA: [45 class(es) instrumented, 13 resource(s) copied]\n" + + "EMMA: metadata merged into [icedtea-web/inc] {in 105 ms}\n" + + "EMMA: processing instrumentation path ..."; + String filteredOut2 = + "test stage 1\n" + + "test stage 2\n" + + "test stage 3\n"; + ProcessResult p2 = new ProcessResult(fakeOut2, fakeOut2, null, true, 0, null); + Assert.assertEquals(p2.notFilteredStdout, fakeOut2); + Assert.assertEquals(p2.stdout, filteredOut2); + Assert.assertEquals(p2.stderr, fakeOut2); + fakeOut2 += "\n"; + p2 = new ProcessResult(fakeOut2, fakeOut2, null, true, 0, null); + Assert.assertEquals(p2.notFilteredStdout, fakeOut2); + Assert.assertEquals(p2.stdout, filteredOut2); + Assert.assertEquals(p2.stderr, fakeOut2); + String fakeOut = + "test string\n" + + "EMMA: processing instrumentation path ...\n" + + "EMMA: package [net.sourceforge.filebrowser] contains classes [ArrayOfString] without full debug info\n" + + "EMMA: instrumentation path processed in 1407 ms\n" + + "test stage 1\n" + + "test stage 2\n" + + "test stage 3\n" + + "EMMA: [45 class(es) instrumented, 13 resource(s) copied]\n" + + "EMMA: metadata merged into [icedtea-web/inc] {in 105 ms}\n" + + "EMMA: processing instrumentation path ...\n" + + "test ends"; + String filteredOut = + "test string\n" + + "test stage 1\n" + + "test stage 2\n" + + "test stage 3\n" + + "test ends"; + ProcessResult p = new ProcessResult(fakeOut, fakeOut, null, true, 0, null); + Assert.assertEquals(p.notFilteredStdout, fakeOut); + Assert.assertEquals(p.stdout, filteredOut); + Assert.assertEquals(p.stderr, fakeOut); + fakeOut += "\n"; + filteredOut += "\n"; + p = new ProcessResult(fakeOut, fakeOut, null, true, 0, null); + Assert.assertEquals(p.notFilteredStdout, fakeOut); + Assert.assertEquals(p.stdout, filteredOut); + Assert.assertEquals(p.stderr, fakeOut); + } + + @Test + public void ensureJavaws() throws Exception { + String javawsValue = serverAccess.getJavawsLocation(); + Assert.assertNotNull(javawsValue); + Assert.assertTrue(javawsValue.trim().length() > 2); + File javawsFile = serverAccess.getJavawsFile(); + Assert.assertTrue(javawsFile.exists()); + Assert.assertFalse(javawsFile.isDirectory()); + } + + @Test + public void ensureServer() throws Exception { + ServerLauncher server = ServerAccess.getInstance(); + 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"); + + ServerAccess.saveFile(server.getDir().getAbsolutePath(), dirFile); + ServerAccess.saveFile(server.getPort().toString(), portFile); + ServerAccess.saveFile(server.getPort().toString(), portFile); + + Assert.assertTrue(portFile.exists()); + Assert.assertTrue(dirFile.exists()); + Assert.assertTrue(server.getDir().listFiles().length > 1); + + String portFileContent = ServerAccess.getContentOfStream(new FileInputStream(portFile)); + String dirFileContent = ServerAccess.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 = ServerAccess.getContentOfStream(portUrl.openConnection().getInputStream()); + String dirUrlContent = ServerAccess.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()); + + URL fastUrl = new URL("http", "localhost", server.getPort(), "/simpletest1.jnlp"); + URL slowUrl = new URL("http", "localhost", server.getPort(), "/XslowXsimpletest1.jnlp"); + + String fastUrlcontent = ServerAccess.getContentOfStream(fastUrl.openConnection().getInputStream()); + String slowUrlContent = ServerAccess.getContentOfStream(slowUrl.openConnection().getInputStream()); + Assert.assertEquals(fastUrlcontent, slowUrlContent); + + } + + @Test + public void splitArrayTest0() throws Exception { + byte[] b = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}; + byte[][] bb = TinyHttpdImpl.splitArray(b, 3); + //printArrays(bb); + byte[] b1 = {1, 2, 3, 4, 5}; + byte[] b2 = {6, 7, 8, 9, 10}; + byte[] b3 = {11, 12, 13, 14}; + Assert.assertEquals(3, bb.length); + Assert.assertArrayEquals(b1, bb[0]); + Assert.assertArrayEquals(b2, bb[1]); + Assert.assertArrayEquals(b3, bb[2]); + } + + @Test + public void splitArrayTest1() throws Exception { + byte[] b = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; + byte[][] bb = TinyHttpdImpl.splitArray(b, 3); + //printArrays(bb); + byte[] b1 = {1, 2, 3, 4, 5}; + byte[] b2 = {6, 7, 8, 9, 10}; + byte[] b3 = {11, 12, 13}; + Assert.assertEquals(3, bb.length); + Assert.assertArrayEquals(b1, bb[0]); + Assert.assertArrayEquals(b2, bb[1]); + Assert.assertArrayEquals(b3, bb[2]); + } + + @Test + public void splitArrayTest2() throws Exception { + byte[] b = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}; + byte[][] bb = TinyHttpdImpl.splitArray(b, 3); + //printArrays(bb); + byte[] b1 = {1, 2, 3, 4}; + byte[] b2 = {5, 6, 7, 8}; + byte[] b3 = {9, 10, 11, 12}; + Assert.assertEquals(3, bb.length); + Assert.assertArrayEquals(b1, bb[0]); + Assert.assertArrayEquals(b2, bb[1]); + Assert.assertArrayEquals(b3, bb[2]); + } + + private void printArrays(byte[][] bb) { + System.out.println("[][] l=" + bb.length); + for (int i = 0; i < bb.length; i++) { + byte[] bs = bb[i]; + System.out.println(i + ": l=" + bs.length); + for (int j = 0; j < bs.length; j++) { + byte c = bs[j]; + System.out.print(" " + j + ":" + c + " "); + } + System.out.println(""); + } + } +} |