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