Moving tests for @JavaScriptBody into TCK preprocess
authorJaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 25 Nov 2013 09:44:59 +0100
branchpreprocess
changeset 33392f39197f0d2
parent 332 386429032402
child 334 ffdba74e8a35
Moving tests for @JavaScriptBody into TCK
boot-fx/pom.xml
boot-fx/src/test/java/org/apidesign/html/boot/fx/BootstrapTest.java
boot-fx/src/test/java/org/apidesign/html/boot/fx/FXPresenterTst.java
boot-fx/src/test/java/org/apidesign/html/boot/fx/FxJavaScriptTst.java
json-tck/pom.xml
json-tck/src/main/java/net/java/html/js/tests/Bodies.java
json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java
json-tck/src/main/java/org/apidesign/html/json/tck/JavaScriptTCK.java
json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java
     1.1 --- a/boot-fx/pom.xml	Mon Nov 25 09:15:27 2013 +0100
     1.2 +++ b/boot-fx/pom.xml	Mon Nov 25 09:44:59 2013 +0100
     1.3 @@ -65,6 +65,12 @@
     1.4        <scope>test</scope>
     1.5        <type>jar</type>
     1.6      </dependency>
     1.7 +    <dependency>
     1.8 +      <groupId>${project.groupId}</groupId>
     1.9 +      <artifactId>net.java.html.json.tck</artifactId>
    1.10 +      <version>${project.version}</version>
    1.11 +      <scope>test</scope>
    1.12 +    </dependency>
    1.13    </dependencies>
    1.14      <description>A presentation provider to show JavaFX WebView 
    1.15  when a Java/HTML based application is about to boot.</description>
     2.1 --- a/boot-fx/src/test/java/org/apidesign/html/boot/fx/BootstrapTest.java	Mon Nov 25 09:15:27 2013 +0100
     2.2 +++ b/boot-fx/src/test/java/org/apidesign/html/boot/fx/BootstrapTest.java	Mon Nov 25 09:44:59 2013 +0100
     2.3 @@ -28,6 +28,8 @@
     2.4  import net.java.html.boot.BrowserBuilder;
     2.5  import org.apidesign.html.boot.impl.FnContext;
     2.6  import org.apidesign.html.boot.spi.Fn;
     2.7 +import org.apidesign.html.json.tck.JavaScriptTCK;
     2.8 +import org.apidesign.html.json.tck.KOTest;
     2.9  import org.testng.annotations.Factory;
    2.10  import org.testng.annotations.Test;
    2.11  
    2.12 @@ -56,11 +58,15 @@
    2.13  
    2.14          List<Object> res = new ArrayList<Object>();
    2.15          Class<? extends Annotation> test = 
    2.16 -            loadClass().getClassLoader().loadClass(Test.class.getName()).
    2.17 +            loadClass().getClassLoader().loadClass(KOTest.class.getName()).
    2.18              asSubclass(Annotation.class);
    2.19 -        for (Method m : loadClass().getMethods()) {
    2.20 -            if (m.getAnnotation(test) != null) {
    2.21 -                res.add(new KOFx(browserPresenter, m));
    2.22 +
    2.23 +        Class[] arr = (Class[]) loadClass().getDeclaredMethod("tests").invoke(null);
    2.24 +        for (Class c : arr) {
    2.25 +            for (Method m : c.getMethods()) {
    2.26 +                if (m.getAnnotation(test) != null) {
    2.27 +                    res.add(new KOFx(browserPresenter, m));
    2.28 +                }
    2.29              }
    2.30          }
    2.31          return res.toArray();
    2.32 @@ -82,6 +88,6 @@
    2.33      public static void initialized() throws Exception {
    2.34          Class<?> classpathClass = ClassLoader.getSystemClassLoader().loadClass(BootstrapTest.class.getName());
    2.35          Method m = classpathClass.getMethod("ready", Class.class);
    2.36 -        m.invoke(null, FXPresenterTst.class);
    2.37 +        m.invoke(null, FxJavaScriptTst.class);
    2.38      }
    2.39  }
     3.1 --- a/boot-fx/src/test/java/org/apidesign/html/boot/fx/FXPresenterTst.java	Mon Nov 25 09:15:27 2013 +0100
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,49 +0,0 @@
     3.4 -/**
     3.5 - * HTML via Java(tm) Language Bindings
     3.6 - * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     3.7 - *
     3.8 - * This program is free software: you can redistribute it and/or modify
     3.9 - * it under the terms of the GNU General Public License as published by
    3.10 - * the Free Software Foundation, version 2 of the License.
    3.11 - *
    3.12 - * This program is distributed in the hope that it will be useful,
    3.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.15 - * GNU General Public License for more details. apidesign.org
    3.16 - * designates this particular file as subject to the
    3.17 - * "Classpath" exception as provided by apidesign.org
    3.18 - * in the License file that accompanied this code.
    3.19 - *
    3.20 - * You should have received a copy of the GNU General Public License
    3.21 - * along with this program. Look for COPYING file in the top folder.
    3.22 - * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    3.23 - */
    3.24 -package org.apidesign.html.boot.fx;
    3.25 -
    3.26 -import net.java.html.js.JavaScriptBody;
    3.27 -import static org.testng.Assert.*;
    3.28 -import org.testng.annotations.Test;
    3.29 -
    3.30 -/**
    3.31 - *
    3.32 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    3.33 - */
    3.34 -public class FXPresenterTst {
    3.35 -    @Test public void showClassLoader() {
    3.36 -        R run = new R();
    3.37 -        callback(run);
    3.38 -        assertEquals(run.cnt, 1, "Can call even private implementation classes");
    3.39 -    }
    3.40 -    
    3.41 -    @JavaScriptBody(args = { "r" }, javacall = true, body = "r.@java.lang.Runnable::run()();")
    3.42 -    private static native void callback(Runnable r);
    3.43 -
    3.44 -    private static class R implements Runnable {
    3.45 -        int cnt;
    3.46 -
    3.47 -        @Override
    3.48 -        public void run() {
    3.49 -            cnt++;
    3.50 -        }
    3.51 -    }
    3.52 -}
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/boot-fx/src/test/java/org/apidesign/html/boot/fx/FxJavaScriptTst.java	Mon Nov 25 09:44:59 2013 +0100
     4.3 @@ -0,0 +1,33 @@
     4.4 +/**
     4.5 + * HTML via Java(tm) Language Bindings
     4.6 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4.7 + *
     4.8 + * This program is free software: you can redistribute it and/or modify
     4.9 + * it under the terms of the GNU General Public License as published by
    4.10 + * the Free Software Foundation, version 2 of the License.
    4.11 + *
    4.12 + * This program is distributed in the hope that it will be useful,
    4.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.15 + * GNU General Public License for more details. apidesign.org
    4.16 + * designates this particular file as subject to the
    4.17 + * "Classpath" exception as provided by apidesign.org
    4.18 + * in the License file that accompanied this code.
    4.19 + *
    4.20 + * You should have received a copy of the GNU General Public License
    4.21 + * along with this program. Look for COPYING file in the top folder.
    4.22 + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    4.23 + */
    4.24 +package org.apidesign.html.boot.fx;
    4.25 +
    4.26 +import org.apidesign.html.json.tck.JavaScriptTCK;
    4.27 +
    4.28 +/**
    4.29 + *
    4.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    4.31 + */
    4.32 +public final class FxJavaScriptTst extends JavaScriptTCK {
    4.33 +    public static Class[] tests() {
    4.34 +        return testClasses();
    4.35 +    }
    4.36 +}
     5.1 --- a/json-tck/pom.xml	Mon Nov 25 09:15:27 2013 +0100
     5.2 +++ b/json-tck/pom.xml	Mon Nov 25 09:44:59 2013 +0100
     5.3 @@ -10,7 +10,7 @@
     5.4    <artifactId>net.java.html.json.tck</artifactId>
     5.5    <version>0.7-SNAPSHOT</version>
     5.6    <packaging>bundle</packaging>
     5.7 -  <name>TCK for JSON Model</name>
     5.8 +  <name>HTML for Java TCK</name>
     5.9    <url>http://maven.apache.org</url>
    5.10    <properties>
    5.11      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    5.12 @@ -57,6 +57,11 @@
    5.13        <artifactId>org-openide-util</artifactId>
    5.14        <scope>provided</scope>
    5.15      </dependency>
    5.16 +    <dependency>
    5.17 +      <groupId>${project.groupId}</groupId>
    5.18 +      <artifactId>net.java.html.boot</artifactId>
    5.19 +      <version>${project.version}</version>
    5.20 +    </dependency>
    5.21    </dependencies>
    5.22      <description>Test Compatibility Kit for anyone who wants to consume the net.java.html.json APIs and
    5.23  render their objects using own technology (e.g. own browser, MVVC, etc.).</description>
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/Bodies.java	Mon Nov 25 09:44:59 2013 +0100
     6.3 @@ -0,0 +1,36 @@
     6.4 +/**
     6.5 + * HTML via Java(tm) Language Bindings
     6.6 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     6.7 + *
     6.8 + * This program is free software: you can redistribute it and/or modify
     6.9 + * it under the terms of the GNU General Public License as published by
    6.10 + * the Free Software Foundation, version 2 of the License.
    6.11 + *
    6.12 + * This program is distributed in the hope that it will be useful,
    6.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    6.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    6.15 + * GNU General Public License for more details. apidesign.org
    6.16 + * designates this particular file as subject to the
    6.17 + * "Classpath" exception as provided by apidesign.org
    6.18 + * in the License file that accompanied this code.
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License
    6.21 + * along with this program. Look for COPYING file in the top folder.
    6.22 + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    6.23 + */
    6.24 +
    6.25 +package net.java.html.js.tests;
    6.26 +
    6.27 +import net.java.html.js.JavaScriptBody;
    6.28 +
    6.29 +/**
    6.30 + *
    6.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    6.32 + */
    6.33 +final class Bodies {
    6.34 +    @JavaScriptBody(args = { "a", "b" }, body = "return a + b;")
    6.35 +    public static native int sum(int a, int b);
    6.36 +    
    6.37 +    @JavaScriptBody(args = {"r"}, javacall = true, body = "r.@java.lang.Runnable::run()();")
    6.38 +    static native void callback(Runnable r);
    6.39 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/JavaScriptBodyTest.java	Mon Nov 25 09:44:59 2013 +0100
     7.3 @@ -0,0 +1,50 @@
     7.4 +/**
     7.5 + * HTML via Java(tm) Language Bindings
     7.6 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     7.7 + *
     7.8 + * This program is free software: you can redistribute it and/or modify
     7.9 + * it under the terms of the GNU General Public License as published by
    7.10 + * the Free Software Foundation, version 2 of the License.
    7.11 + *
    7.12 + * This program is distributed in the hope that it will be useful,
    7.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    7.15 + * GNU General Public License for more details. apidesign.org
    7.16 + * designates this particular file as subject to the
    7.17 + * "Classpath" exception as provided by apidesign.org
    7.18 + * in the License file that accompanied this code.
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License
    7.21 + * along with this program. Look for COPYING file in the top folder.
    7.22 + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    7.23 + */
    7.24 +package net.java.html.js.tests;
    7.25 +
    7.26 +import org.apidesign.html.json.tck.KOTest;
    7.27 +
    7.28 +/**
    7.29 + *
    7.30 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    7.31 + */
    7.32 +public class JavaScriptBodyTest {
    7.33 +    @KOTest public void sumTwoNumbers() {
    7.34 +        int res = Bodies.sum(5, 3);
    7.35 +        assert res == 8 : "Expecting 8: " + res;
    7.36 +    }
    7.37 +    
    7.38 +    @KOTest public void callbackToRunnable() {
    7.39 +        R run = new R();
    7.40 +        Bodies.callback(run);
    7.41 +        assert run.cnt == 1 : "Can call even private implementation classes: " + run.cnt;
    7.42 +    }
    7.43 +
    7.44 +    private static class R implements Runnable {
    7.45 +        int cnt;
    7.46 +
    7.47 +        @Override
    7.48 +        public void run() {
    7.49 +            cnt++;
    7.50 +        }
    7.51 +    }
    7.52 +    
    7.53 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/json-tck/src/main/java/org/apidesign/html/json/tck/JavaScriptTCK.java	Mon Nov 25 09:44:59 2013 +0100
     8.3 @@ -0,0 +1,45 @@
     8.4 +/**
     8.5 + * HTML via Java(tm) Language Bindings
     8.6 + * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     8.7 + *
     8.8 + * This program is free software: you can redistribute it and/or modify
     8.9 + * it under the terms of the GNU General Public License as published by
    8.10 + * the Free Software Foundation, version 2 of the License.
    8.11 + *
    8.12 + * This program is distributed in the hope that it will be useful,
    8.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    8.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    8.15 + * GNU General Public License for more details. apidesign.org
    8.16 + * designates this particular file as subject to the
    8.17 + * "Classpath" exception as provided by apidesign.org
    8.18 + * in the License file that accompanied this code.
    8.19 + *
    8.20 + * You should have received a copy of the GNU General Public License
    8.21 + * along with this program. Look for COPYING file in the top folder.
    8.22 + * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    8.23 + */
    8.24 +package org.apidesign.html.json.tck;
    8.25 +
    8.26 +import net.java.html.js.tests.JavaScriptBodyTest;
    8.27 +import org.apidesign.html.boot.spi.Fn;
    8.28 +
    8.29 +/** Subclass this class, implements is abstract methods (if any).
    8.30 + *
    8.31 + * @author Jaroslav Tulach <jtulach@netbeans.org>
    8.32 + * @sine 0.7
    8.33 + */
    8.34 +public abstract class JavaScriptTCK {
    8.35 +    /** Gives you list of classes included in the TCK. Their test methods
    8.36 +     * are annotated by {@link KOTest} annotation. The methods are public
    8.37 +     * instance methods that take no arguments. The method should be 
    8.38 +     * invoke in a presenter context {@link Fn#activate(org.apidesign.html.boot.spi.Fn.Presenter)}.
    8.39 +     * 
    8.40 +     * @return classes with methods annotated by {@link KOTest} annotation
    8.41 +     */
    8.42 +    protected static Class<?>[] testClasses() {
    8.43 +        return new Class[] { 
    8.44 +            JavaScriptBodyTest.class
    8.45 +        };
    8.46 +    }
    8.47 +    
    8.48 +}
     9.1 --- a/json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java	Mon Nov 25 09:15:27 2013 +0100
     9.2 +++ b/json-tck/src/main/java/org/apidesign/html/json/tck/KnockoutTCK.java	Mon Nov 25 09:44:59 2013 +0100
     9.3 @@ -85,7 +85,7 @@
     9.4       * are annotated by {@link KOTest} annotation. The methods are public
     9.5       * instance methods that take no arguments.
     9.6       * 
     9.7 -     * @return classes with methods annotated by {@link BrwsrTest} annotation
     9.8 +     * @return classes with methods annotated by {@link KOTest} annotation
     9.9       */
    9.10      protected static Class<?>[] testClasses() {
    9.11          return new Class[] {