ko-bck2brwsr/src/test/java/org/apidesign/html/ko2brwsr/Bck2BrwsrKnockoutTest.java
Moving Context into its own separate module, renaming to BrwsrCtx and making it flexible
2 * HTML via Java(tm) Language Bindings
3 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. apidesign.org
13 * designates this particular file as subject to the
14 * "Classpath" exception as provided by apidesign.org
15 * in the License file that accompanied this code.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. Look for COPYING file in the top folder.
19 * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
21 package org.apidesign.html.ko2brwsr;
24 import net.java.html.BrwsrCtx;
25 import org.apidesign.bck2brwsr.core.JavaScriptBody;
26 import org.apidesign.bck2brwsr.vmtest.VMTest;
27 import org.apidesign.html.context.spi.Contexts;
28 import org.apidesign.html.json.spi.Technology;
29 import org.apidesign.html.json.spi.Transfer;
30 import org.apidesign.html.json.tck.KnockoutTCK;
31 import org.openide.util.lookup.ServiceProvider;
32 import org.testng.annotations.Factory;
36 * @author Jaroslav Tulach <jtulach@netbeans.org>
38 @ServiceProvider(service = KnockoutTCK.class)
39 public final class Bck2BrwsrKnockoutTest extends KnockoutTCK {
40 @Factory public static Object[] create() {
41 return VMTest.newTests().
42 withClasses(testClasses()).
43 withLaunchers("bck2brwsr").
48 public BrwsrCtx createContext() {
49 return Contexts.newBuilder().
50 register(Transfer.class, BrwsrCtxImpl.DEFAULT, 9).
51 register(Technology.class, BrwsrCtxImpl.DEFAULT, 9).build();
57 public Object createJSON(Map<String, Object> values) {
58 Object json = createJSON();
60 for (Map.Entry<String, Object> entry : values.entrySet()) {
61 putValue(json, entry.getKey(), entry.getValue());
66 @JavaScriptBody(args = {}, body = "return new Object();")
67 private static native Object createJSON();
69 @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
70 private static native void putValue(Object json, String key, Object value);
73 public Object executeScript(String script, Object[] arguments) {
74 return execScript(script, arguments);
77 @JavaScriptBody(args = { "s", "args" }, body =
78 "var f = new Function(s); return f.apply(null, args);"
80 private static native Object execScript(String s, Object[] arguments);