1.1 --- a/vmtest/src/test/java/org/apidesign/bck2brwsr/tck/HttpResourceTest.java Thu Feb 14 12:06:16 2013 +0100
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,94 +0,0 @@
1.4 -/**
1.5 - * Back 2 Browser Bytecode Translator
1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 - *
1.8 - * This program is free software: you can redistribute it and/or modify
1.9 - * it under the terms of the GNU General Public License as published by
1.10 - * the Free Software Foundation, version 2 of the License.
1.11 - *
1.12 - * This program is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 - * GNU General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU General Public License
1.18 - * along with this program. Look for COPYING file in the top folder.
1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
1.20 - */
1.21 -package org.apidesign.bck2brwsr.tck;
1.22 -
1.23 -import java.io.InputStream;
1.24 -import java.net.URL;
1.25 -import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.26 -import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
1.27 -import org.apidesign.bck2brwsr.vmtest.HttpResource;
1.28 -import org.apidesign.bck2brwsr.vmtest.VMTest;
1.29 -import org.testng.annotations.Factory;
1.30 -
1.31 -/**
1.32 - *
1.33 - * @author Jaroslav Tulach <jtulach@netbeans.org>
1.34 - */
1.35 -public class HttpResourceTest {
1.36 -
1.37 - @HttpResource(path = "/xhr", content = "Hello Brwsr!", mimeType = "text/plain")
1.38 - @BrwsrTest
1.39 - public String testReadContentViaXHR() throws Exception {
1.40 - String msg = read("/xhr");
1.41 - assert "Hello Brwsr!".equals(msg) : "The message was " + msg;
1.42 - return msg;
1.43 - }
1.44 -
1.45 - @HttpResource(path = "/url", content = "Hello via URL!", mimeType = "text/plain")
1.46 - @BrwsrTest
1.47 - public String testReadContentViaURL() throws Exception {
1.48 - URL url = new URL("http:/url");
1.49 - String msg = (String) url.getContent();
1.50 - assert "Hello via URL!".equals(msg) : "The message was " + msg;
1.51 - return msg;
1.52 - }
1.53 - @HttpResource(path = "/url", content = "Hello via URL!", mimeType = "text/plain")
1.54 - @BrwsrTest
1.55 - public String testReadContentViaURLWithStringParam() throws Exception {
1.56 - URL url = new URL("http:/url");
1.57 - String msg = (String) url.getContent(new Class[] { String.class });
1.58 - assert "Hello via URL!".equals(msg) : "The message was " + msg;
1.59 - return msg;
1.60 - }
1.61 -
1.62 - @HttpResource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
1.63 - @BrwsrTest
1.64 - public void testReadByte() throws Exception {
1.65 - URL url = new URL("http:/bytes");
1.66 - final Object res = url.getContent(new Class[] { byte[].class });
1.67 - assert res instanceof byte[] : "Expecting byte[]: " + res;
1.68 - byte[] arr = (byte[]) res;
1.69 - assert arr.length == 1 : "One byte " + arr.length;
1.70 - assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
1.71 - }
1.72 -
1.73 - @HttpResource(path = "/bytes", content = "", resource = "0xfe", mimeType = "x-application/binary")
1.74 - @BrwsrTest
1.75 - public void testReadByteViaInputStream() throws Exception {
1.76 - URL url = new URL("http:/bytes");
1.77 - InputStream is = url.openStream();
1.78 - byte[] arr = new byte[10];
1.79 - int len = is.read(arr);
1.80 - assert len == 1 : "One byte " + len;
1.81 - assert arr[0] == 0xfe : "It is 0xfe: " + Integer.toHexString(arr[0]);
1.82 - }
1.83 -
1.84 - @JavaScriptBody(args = { "url" }, body =
1.85 - "var req = new XMLHttpRequest();\n"
1.86 - + "req.open('GET', url, false);\n"
1.87 - + "req.send();\n"
1.88 - + "return req.responseText;"
1.89 - )
1.90 - private static native String read(String url);
1.91 -
1.92 -
1.93 - @Factory
1.94 - public static Object[] create() {
1.95 - return VMTest.create(HttpResourceTest.class);
1.96 - }
1.97 -}