ko-bck2brwsr/src/test/java/org/apidesign/html/ko2brwsr/Bck2BrwsrKnockoutTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Tue, 28 May 2013 13:31:42 +0200
branchcontext
changeset 1220 cf9ba1d883c5
parent 1189 9f8b07dcbe79
child 1223 aa8587804f92
permissions -rw-r--r--
Moving Context into its own separate module, renaming to BrwsrCtx and making it flexible
     1 /**
     2  * HTML via Java(tm) Language Bindings
     3  * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    16  *
    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
    20  */
    21 package org.apidesign.html.ko2brwsr;
    22 
    23 import java.util.Map;
    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;
    33 
    34 /**
    35  *
    36  * @author Jaroslav Tulach <jtulach@netbeans.org>
    37  */
    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").
    44             build();
    45     }
    46     
    47     @Override
    48     public BrwsrCtx createContext() {
    49         return Contexts.newBuilder().
    50             register(Transfer.class, BrwsrCtxImpl.DEFAULT, 9).
    51             register(Technology.class, BrwsrCtxImpl.DEFAULT, 9).build();
    52     }
    53 
    54 
    55     
    56     @Override
    57     public Object createJSON(Map<String, Object> values) {
    58         Object json = createJSON();
    59         
    60         for (Map.Entry<String, Object> entry : values.entrySet()) {
    61             putValue(json, entry.getKey(), entry.getValue());
    62         }
    63         return json;
    64     }
    65 
    66     @JavaScriptBody(args = {}, body = "return new Object();")
    67     private static native Object createJSON();
    68 
    69     @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
    70     private static native void putValue(Object json, String key, Object value);
    71 
    72     @Override
    73     public Object executeScript(String script, Object[] arguments) {
    74         return execScript(script, arguments);
    75     }
    76     
    77     @JavaScriptBody(args = { "s", "args" }, body = 
    78         "var f = new Function(s); return f.apply(null, args);"
    79     )
    80     private static native Object execScript(String s, Object[] arguments);
    81 }