ko-archetype/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 13 May 2013 11:39:33 +0200
changeset 1201 b6fd8b9ccc7a
child 1202 5f04bdbc6ee1
permissions -rw-r--r--
First sketch of the Knockout4J archetype
jaroslav@1201
     1
package ${package};
jaroslav@1201
     2
jaroslav@1201
     3
import org.apidesign.bck2brwsr.htmlpage.api.OnEvent;
jaroslav@1201
     4
import org.apidesign.bck2brwsr.vmtest.BrwsrTest;
jaroslav@1201
     5
import org.apidesign.bck2brwsr.vmtest.HtmlFragment;
jaroslav@1201
     6
import org.apidesign.bck2brwsr.vmtest.VMTest;
jaroslav@1201
     7
import org.testng.annotations.Factory;
jaroslav@1201
     8
jaroslav@1201
     9
/** Sometimes it is useful to run tests inside of the real browser. 
jaroslav@1201
    10
 * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest}
jaroslav@1201
    11
 * and that is it. If your code references elements on the HTML page,
jaroslav@1201
    12
 * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which
jaroslav@1201
    13
 * will be made available on the page before your test starts.
jaroslav@1201
    14
 *
jaroslav@1201
    15
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1201
    16
 */
jaroslav@1201
    17
public class IntegrationTest {
jaroslav@1201
    18
    
jaroslav@1201
    19
    /** Write to testing code here. Use <code>assert</code> (but not TestNG's
jaroslav@1201
    20
     * Assert, as TestNG is not compiled with target 1.6 yet).
jaroslav@1201
    21
     */
jaroslav@1201
    22
    @HtmlFragment(
jaroslav@1201
    23
        "<h1 data-bind=\"text: helloMessage\">Loading Bck2Brwsr's Hello World...</h1>\n" +
jaroslav@1201
    24
        "Your name: <input id='input' data-bind=\"value: name, valueUpdate: 'afterkeydown'\"></input>\n" +
jaroslav@1201
    25
        "<button id=\"hello\">Say Hello!</button>\n" +
jaroslav@1201
    26
        "<p>\n" +
jaroslav@1201
    27
        "    <canvas id=\"canvas\" width=\"300\" height=\"50\"></canvas>\n" +
jaroslav@1201
    28
        "</p>\n"
jaroslav@1201
    29
    )
jaroslav@1201
    30
    @BrwsrTest
jaroslav@1201
    31
    public void modifyValueAssertChangeInModel() {
jaroslav@1201
    32
        Index m = new Index();
jaroslav@1201
    33
        m.setName("Joe Hacker");
jaroslav@1201
    34
        m.applyBindings();
jaroslav@1201
    35
        assert "Joe Hacker".equals(m.input.getValue()) : "Value is really Joe Hacker: " + m.input.getValue();
jaroslav@1201
    36
        m.input.setValue("Happy Joe");
jaroslav@1201
    37
        m.triggerEvent(m.input, OnEvent.CHANGE);
jaroslav@1201
    38
        assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName();
jaroslav@1201
    39
    }
jaroslav@1201
    40
jaroslav@1201
    41
    @Factory
jaroslav@1201
    42
    public static Object[] create() {
jaroslav@1201
    43
        return VMTest.create(IntegrationTest.class);
jaroslav@1201
    44
    }
jaroslav@1201
    45
    
jaroslav@1201
    46
}