javaquery/api/src/test/java/org/apidesign/bck2brwsr/htmlpage/Bck2BrwsrKnockoutTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 29 Apr 2013 08:27:54 +0200
branchmodel
changeset 1051 284898f3e0ff
parent 1019 814e4be6a104
child 1054 fef28d5bee88
permissions -rw-r--r--
Use the builder methods of VMTest
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 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.
    13  *
    14  * You should have received a copy of the GNU General Public License
    15  * along with this program. Look for COPYING file in the top folder.
    16  * If not, see http://opensource.org/licenses/GPL-2.0.
    17  */
    18 package org.apidesign.bck2brwsr.htmlpage;
    19 
    20 import java.util.Map;
    21 import net.java.html.json.Context;
    22 import org.apidesign.bck2brwsr.core.JavaScriptBody;
    23 import org.apidesign.bck2brwsr.vmtest.VMTest;
    24 import org.apidesign.html.json.tck.KnockoutTCK;
    25 import org.openide.util.lookup.ServiceProvider;
    26 import org.testng.annotations.Factory;
    27 
    28 /**
    29  *
    30  * @author Jaroslav Tulach <jtulach@netbeans.org>
    31  */
    32 @ServiceProvider(service = KnockoutTCK.class)
    33 public final class Bck2BrwsrKnockoutTest extends KnockoutTCK {
    34     @Factory public static Object[] create() {
    35         return VMTest.newTests().addClass(testClasses()).addLauncher("bck2brwsr").build();
    36     }
    37     
    38     @Override
    39     public Context createContext() {
    40         return BrwsrCntxt.DEFAULT;
    41     }
    42 
    43 
    44     
    45     @Override
    46     public Object createJSON(Map<String, Object> values) {
    47         Object json = createJSON();
    48         
    49         for (Map.Entry<String, Object> entry : values.entrySet()) {
    50             putValue(json, entry.getKey(), entry.getValue());
    51         }
    52         return json;
    53     }
    54 
    55     @JavaScriptBody(args = {}, body = "return new Object();")
    56     private static native Object createJSON();
    57 
    58     @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
    59     private static native void putValue(Object json, String key, Object value);
    60 
    61     @Override
    62     public Object executeScript(String script, Object[] arguments) {
    63         return execScript(script, arguments);
    64     }
    65     
    66     @JavaScriptBody(args = { "s", "args" }, body = 
    67         "var f = new Function(s); return f.apply(null, args);"
    68     )
    69     private static native Object execScript(String s, Object[] arguments);
    70 }