ko-bck2brwsr/src/test/java/org/apidesign/html/ko2brwsr/Bck2BrwsrKnockoutTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 29 Apr 2013 12:50:19 +0200
changeset 1189 9f8b07dcbe79
child 1220 cf9ba1d883c5
permissions -rw-r--r--
Putting the bck2brwsr bindings into html.java.net repository
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@1189
    24
import net.java.html.json.Context;
jaroslav@1189
    25
import org.apidesign.bck2brwsr.core.JavaScriptBody;
jaroslav@1189
    26
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@1189
    27
import org.apidesign.html.json.tck.KnockoutTCK;
jaroslav@1189
    28
import org.openide.util.lookup.ServiceProvider;
jaroslav@1189
    29
import org.testng.annotations.Factory;
jaroslav@1189
    30
jaroslav@1189
    31
/**
jaroslav@1189
    32
 *
jaroslav@1189
    33
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1189
    34
 */
jaroslav@1189
    35
@ServiceProvider(service = KnockoutTCK.class)
jaroslav@1189
    36
public final class Bck2BrwsrKnockoutTest extends KnockoutTCK {
jaroslav@1189
    37
    @Factory public static Object[] create() {
jaroslav@1189
    38
        return VMTest.newTests().
jaroslav@1189
    39
            withClasses(testClasses()).
jaroslav@1189
    40
            withLaunchers("bck2brwsr").
jaroslav@1189
    41
            build();
jaroslav@1189
    42
    }
jaroslav@1189
    43
    
jaroslav@1189
    44
    @Override
jaroslav@1189
    45
    public Context createContext() {
jaroslav@1189
    46
        return BrwsrCntxt.DEFAULT;
jaroslav@1189
    47
    }
jaroslav@1189
    48
jaroslav@1189
    49
jaroslav@1189
    50
    
jaroslav@1189
    51
    @Override
jaroslav@1189
    52
    public Object createJSON(Map<String, Object> values) {
jaroslav@1189
    53
        Object json = createJSON();
jaroslav@1189
    54
        
jaroslav@1189
    55
        for (Map.Entry<String, Object> entry : values.entrySet()) {
jaroslav@1189
    56
            putValue(json, entry.getKey(), entry.getValue());
jaroslav@1189
    57
        }
jaroslav@1189
    58
        return json;
jaroslav@1189
    59
    }
jaroslav@1189
    60
jaroslav@1189
    61
    @JavaScriptBody(args = {}, body = "return new Object();")
jaroslav@1189
    62
    private static native Object createJSON();
jaroslav@1189
    63
jaroslav@1189
    64
    @JavaScriptBody(args = { "json", "key", "value" }, body = "json[key] = value;")
jaroslav@1189
    65
    private static native void putValue(Object json, String key, Object value);
jaroslav@1189
    66
jaroslav@1189
    67
    @Override
jaroslav@1189
    68
    public Object executeScript(String script, Object[] arguments) {
jaroslav@1189
    69
        return execScript(script, arguments);
jaroslav@1189
    70
    }
jaroslav@1189
    71
    
jaroslav@1189
    72
    @JavaScriptBody(args = { "s", "args" }, body = 
jaroslav@1189
    73
        "var f = new Function(s); return f.apply(null, args);"
jaroslav@1189
    74
    )
jaroslav@1189
    75
    private static native Object execScript(String s, Object[] arguments);
jaroslav@1189
    76
}