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