# HG changeset patch # User Jaroslav Tulach # Date 1363906941 -3600 # Node ID 448bed1f6d5ad57e33c421e8975a7c98276d8f26 # Parent 03fe918c468439524e8dbdba213ab62953a653df Separating the archetype into its own module - to give it better name among archetypes diff -r 03fe918c4684 -r 448bed1f6d5a pom.xml --- a/pom.xml Thu Mar 21 15:53:55 2013 +0100 +++ b/pom.xml Fri Mar 22 00:02:21 2013 +0100 @@ -80,7 +80,7 @@ .*/** rt/emul/*/src/main/** rt/vm/src/main/java/org/apidesign/vm4brwsr/ByteCodeParser.java - rt/mojo/src/main/resources/archetype-resources/** + rt/archetype/src/main/resources/archetype-resources/** rt/vmtest/src/test/resources/** dew/src/main/resources/org/apidesign/bck2brwsr/dew/** javaquery/api/src/main/resources/org/apidesign/bck2brwsr/htmlpage/knockout*.js diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/pom.xml Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,62 @@ + + + 4.0.0 + + rt + org.apidesign.bck2brwsr + 0.5-SNAPSHOT + + org.apidesign.bck2brwsr + bck2brwsr-archetype-html-sample + 0.5-SNAPSHOT + jar + Bck2Brwsr Maven Archetype + + Creates a skeletal HTML page and associated Java controller class. + Runs in any browser (even without Java plugin) with the help of Bck2Brwsr + virtual machine. + + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + + + + org.apache.maven.plugins + maven-surefire-plugin + + true + + + + test + + test + + integration-test + + + ${project.build.directory}/bck2brwsr-archetype-html-sample-${project.version}.jar + + false + + + + + + + + + + org.testng + testng + test + + + diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/java/org/apidesign/bck2brwsr/archetype/package-info.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/java/org/apidesign/bck2brwsr/archetype/package-info.java Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,18 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.archetype; diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/META-INF/maven/archetype-metadata.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/META-INF/maven/archetype-metadata.xml Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,55 @@ + + + + + + src/main/java + + **/App.java + + + + src/main/resources + + **/*.xhtml + **/*.html + + + + src/test/java + + **/*Test.java + + + + + + nbactions.xml + + + + + + bck2brwsr-assembly.xml + + + + \ No newline at end of file diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/bck2brwsr-assembly.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/bck2brwsr-assembly.xml Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,61 @@ + + + + + bck2brwsr + + zip + + public_html + + + false + runtime + lib + + *:jar + *:rt + + + + false + provided + + *:js + + true + / + + + + + ${project.build.directory}/${project.build.finalName}.jar + / + + + ${project.build.directory}/classes/${package.replace('.','/')}/index.html + / + index.html + + + + \ No newline at end of file diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/nbactions.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/nbactions.xml Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,10 @@ + + + + run + + process-classes + org.apidesign.bck2brwsr:mojo:0.5-SNAPSHOT:brwsr + + + diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/pom.xml --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/pom.xml Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,135 @@ + + + 4.0.0 + + ${groupId} + ${artifactId} + ${version} + jar + + ${artifactId} + + + + java.net + Java.net + https://maven.java.net/content/repositories/releases/ + + true + + + + netbeans + NetBeans + http://bits.netbeans.org/maven2/ + + + + + java.net + Java.net + https://maven.java.net/content/repositories/releases/ + + true + + + + + + UTF-8 + + + + + org.apidesign.bck2brwsr + mojo + 0.5-SNAPSHOT + + + + brwsr + + + + + ${package.replace('.','/')}/index.html + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.7 + 1.7 + + + + org.apache.maven.plugins + maven-jar-plugin + 2.4 + + + + true + lib/ + + + + + + maven-assembly-plugin + 2.4 + + + distro-assembly + package + + single + + + + bck2brwsr-assembly.xml + + + + + + + + + + + org.apidesign.bck2brwsr + emul + 0.5-SNAPSHOT + rt + + + org.apidesign.bck2brwsr + javaquery.api + 0.5-SNAPSHOT + + + org.testng + testng + 6.5.2 + test + + + org.apidesign.bck2brwsr + vm4brwsr + js + zip + 0.5-SNAPSHOT + provided + + + org.apidesign.bck2brwsr + vmtest + 0.5-SNAPSHOT + test + + + diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/src/main/java/App.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/src/main/java/App.java Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,34 @@ +package ${package}; + +import org.apidesign.bck2brwsr.htmlpage.api.*; +import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*; +import org.apidesign.bck2brwsr.htmlpage.api.Page; +import org.apidesign.bck2brwsr.htmlpage.api.Property; +import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty; + +/** Edit the index.xhtml file. Use 'id' to name certain HTML elements. + * Use this class to define behavior of the elements. + */ +@Page(xhtml="index.html", className="Index", properties={ + @Property(name="name", type=String.class) +}) +public class App { + static { + Index model = new Index(); + model.setName("World"); + model.applyBindings(); + } + + @On(event = CLICK, id="hello") + static void hello(Index m) { + GraphicsContext g = m.CANVAS.getContext(); + g.clearRect(0, 0, 1000, 1000); + g.setFont("italic 40px Calibri"); + g.fillText(m.getHelloMessage(), 10, 40); + } + + @ComputedProperty + static String helloMessage(String name) { + return "Hello " + name + "!"; + } +} diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/src/main/resources/index.html --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/src/main/resources/index.html Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,22 @@ + + + + + Bck2Brwsr's Hello World + + +

Loading Bck2Brwsr's Hello World...

+ Your name: + +

+ + +

+ + + + + diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/src/test/java/AppTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/src/test/java/AppTest.java Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,26 @@ +package ${package}; + +import static org.testng.Assert.*; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot + * as it does not reference any HTML elements or browser functionality. Just + * operates on the page model. + * + * @author Jaroslav Tulach + */ +public class AppTest { + private Index model; + + + @BeforeMethod + public void initModel() { + model = new Index().applyBindings(); + } + + @Test public void testHelloMessage() { + model.setName("Joe"); + assertEquals(model.getHelloMessage(), "Hello Joe!", "Cleared after pressing +"); + } +} diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,40 @@ +package ${package}; + +import org.apidesign.bck2brwsr.vmtest.Compare; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +/** Bck2brwsr cares about compatibility with real Java. Whatever API is + * supported by bck2brwsr, it needs to behave the same way as when running + * in HotSpot VM. + *

+ * There can be bugs, however. To help us fix them, we kindly ask you to + * write an "inconsistency" test. A test that compares behavior of the API + * between real VM and bck2brwsr VM. This class is skeleton of such test. + * + * @author Jaroslav Tulach + */ +public class InconsistencyTest { + /** A method to demonstrate inconsistency between bck2brwsr and HotSpot. + * Make calls to an API that behaves strangely, return some result at + * the end. No need to use any assert. + * + * @return value to compare between HotSpot and bck2brwsr + */ + @Compare + public int checkStringHashCode() throws Exception { + return "Is string hashCode the same?".hashCode(); + } + + /** Factory method that creates a three tests for each method annotated with + * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in + * HotSpot, one in Rhino and the last one compares the results. + * + * @see org.apidesign.bck2brwsr.vmtest.VMTest + */ + @Factory + public static Object[] create() { + return VMTest.create(InconsistencyTest.class); + } + +} diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,46 @@ +package ${package}; + +import org.apidesign.bck2brwsr.htmlpage.api.OnEvent; +import org.apidesign.bck2brwsr.vmtest.BrwsrTest; +import org.apidesign.bck2brwsr.vmtest.HtmlFragment; +import org.apidesign.bck2brwsr.vmtest.VMTest; +import org.testng.annotations.Factory; + +/** Sometimes it is useful to run tests inside of the real browser. + * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest} + * and that is it. If your code references elements on the HTML page, + * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which + * will be made available on the page before your test starts. + * + * @author Jaroslav Tulach + */ +public class IntegrationTest { + + /** Write to testing code here. Use assert (but not TestNG's + * Assert, as TestNG is not compiled with target 1.6 yet). + */ + @HtmlFragment( + "

Loading Bck2Brwsr's Hello World...

\n" + + "Your name: \n" + + "\n" + + "

\n" + + " \n" + + "

\n" + ) + @BrwsrTest + public void modifyValueAssertChangeInModel() { + Index m = new Index(); + m.setName("Joe Hacker"); + m.applyBindings(); + assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue(); + m.INPUT.setValue("Happy Joe"); + m.triggerEvent(m.INPUT, OnEvent.CHANGE); + assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName(); + } + + @Factory + public static Object[] create() { + return VMTest.create(IntegrationTest.class); + } + +} diff -r 03fe918c4684 -r 448bed1f6d5a rt/archetype/src/test/java/org/apidesign/bck2brwsr/archetype/ArchetypeVersionTest.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/rt/archetype/src/test/java/org/apidesign/bck2brwsr/archetype/ArchetypeVersionTest.java Fri Mar 22 00:02:21 2013 +0100 @@ -0,0 +1,104 @@ +/** + * Back 2 Browser Bytecode Translator + * Copyright (C) 2012 Jaroslav Tulach + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 2 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. Look for COPYING file in the top folder. + * If not, see http://opensource.org/licenses/GPL-2.0. + */ +package org.apidesign.bck2brwsr.archetype; + +import java.net.URL; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathExpression; +import javax.xml.xpath.XPathFactory; +import org.testng.annotations.Test; +import org.xml.sax.InputSource; +import static org.testng.Assert.*; +import org.testng.annotations.BeforeClass; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; + +/** + * + * @author Jaroslav Tulach + */ +public class ArchetypeVersionTest { + private String version; + + public ArchetypeVersionTest() { + } + + @BeforeClass public void readCurrentVersion() throws Exception { + final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); + URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/bck2brwsr-archetype-html-sample/pom.xml"); + assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path")); + + final XPathFactory fact = XPathFactory.newInstance(); + fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + + XPathExpression xp = fact.newXPath().compile("project/version/text()"); + + Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream()); + version = xp.evaluate(dom); + + assertFalse(version.isEmpty(), "There should be some version string"); + } + + + @Test public void testComparePomDepsVersions() throws Exception { + final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); + URL r = l.getResource("archetype-resources/pom.xml"); + assertNotNull(r, "Archetype pom found"); + + final XPathFactory fact = XPathFactory.newInstance(); + XPathExpression xp2 = fact.newXPath().compile( + "//version[../groupId/text() = 'org.apidesign.bck2brwsr']/text()" + ); + + Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); + NodeList arch = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET); + + if (arch.getLength() < 3) { + fail("There should be at least three dependencies to bck2brwsr APIs: " + arch.getLength()); + } + + for (int i = 0; i < arch.getLength(); i++) { + assertEquals(arch.item(i).getTextContent(), version, i + "th dependency needs to be on latest version of bck2brwsr"); + } + } + + @Test public void testNbActions() throws Exception { + final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); + URL r = l.getResource("archetype-resources/nbactions.xml"); + assertNotNull(r, "Archetype nb file found"); + + final XPathFactory fact = XPathFactory.newInstance(); + XPathExpression xp2 = fact.newXPath().compile( + "//goal/text()" + ); + + Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); + NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET); + + for (int i = 0; i < goals.getLength(); i++) { + String s = goals.item(i).getTextContent(); + if (s.contains("bck2brwsr")) { + String[] arr = s.split(":"); + assertEquals(arr.length, 4, "Three :"); + assertEquals(arr[2], version, "Proper version is used"); + } + } + } +} diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/pom.xml --- a/rt/mojo/pom.xml Thu Mar 21 15:53:55 2013 +0100 +++ b/rt/mojo/pom.xml Fri Mar 22 00:02:21 2013 +0100 @@ -10,7 +10,7 @@ mojo 0.5-SNAPSHOT maven-plugin - Bck2Brwsr Maven Project + Bck2Brwsr Maven Plugins http://maven.apache.org @@ -62,7 +62,7 @@ ${project.groupId} vm4brwsr - 0.5-SNAPSHOT + ${project.version} emul.mini @@ -81,11 +81,5 @@ launcher ${project.version} - - org.testng - testng - 6.5.2 - test - diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml --- a/rt/mojo/src/main/resources/META-INF/maven/archetype-metadata.xml Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ - - - - - - src/main/java - - **/App.java - - - - src/main/resources - - **/*.xhtml - **/*.html - - - - src/test/java - - **/*Test.java - - - - - - nbactions.xml - - - - - - bck2brwsr-assembly.xml - - - - \ No newline at end of file diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/bck2brwsr-assembly.xml --- a/rt/mojo/src/main/resources/archetype-resources/bck2brwsr-assembly.xml Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,61 +0,0 @@ - - - - - bck2brwsr - - zip - - public_html - - - false - runtime - lib - - *:jar - *:rt - - - - false - provided - - *:js - - true - / - - - - - ${project.build.directory}/${project.build.finalName}.jar - / - - - ${project.build.directory}/classes/${package.replace('.','/')}/index.html - / - index.html - - - - \ No newline at end of file diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/nbactions.xml --- a/rt/mojo/src/main/resources/archetype-resources/nbactions.xml Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ - - - - run - - process-classes - org.apidesign.bck2brwsr:mojo:0.5-SNAPSHOT:brwsr - - - diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/pom.xml --- a/rt/mojo/src/main/resources/archetype-resources/pom.xml Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,135 +0,0 @@ - - - 4.0.0 - - ${groupId} - ${artifactId} - ${version} - jar - - ${artifactId} - - - - java.net - Java.net - https://maven.java.net/content/repositories/releases/ - - true - - - - netbeans - NetBeans - http://bits.netbeans.org/maven2/ - - - - - java.net - Java.net - https://maven.java.net/content/repositories/releases/ - - true - - - - - - UTF-8 - - - - - org.apidesign.bck2brwsr - mojo - 0.5-SNAPSHOT - - - - brwsr - - - - - ${package.replace('.','/')}/index.html - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - true - lib/ - - - - - - maven-assembly-plugin - 2.4 - - - distro-assembly - package - - single - - - - bck2brwsr-assembly.xml - - - - - - - - - - - org.apidesign.bck2brwsr - emul - 0.5-SNAPSHOT - rt - - - org.apidesign.bck2brwsr - javaquery.api - 0.5-SNAPSHOT - - - org.testng - testng - 6.5.2 - test - - - org.apidesign.bck2brwsr - vm4brwsr - js - zip - 0.5-SNAPSHOT - provided - - - org.apidesign.bck2brwsr - vmtest - 0.5-SNAPSHOT - test - - - diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/src/main/java/App.java --- a/rt/mojo/src/main/resources/archetype-resources/src/main/java/App.java Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -package ${package}; - -import org.apidesign.bck2brwsr.htmlpage.api.*; -import static org.apidesign.bck2brwsr.htmlpage.api.OnEvent.*; -import org.apidesign.bck2brwsr.htmlpage.api.Page; -import org.apidesign.bck2brwsr.htmlpage.api.Property; -import org.apidesign.bck2brwsr.htmlpage.api.ComputedProperty; - -/** Edit the index.xhtml file. Use 'id' to name certain HTML elements. - * Use this class to define behavior of the elements. - */ -@Page(xhtml="index.html", className="Index", properties={ - @Property(name="name", type=String.class) -}) -public class App { - static { - Index model = new Index(); - model.setName("World"); - model.applyBindings(); - } - - @On(event = CLICK, id="hello") - static void hello(Index m) { - GraphicsContext g = m.CANVAS.getContext(); - g.clearRect(0, 0, 1000, 1000); - g.setFont("italic 40px Calibri"); - g.fillText(m.getHelloMessage(), 10, 40); - } - - @ComputedProperty - static String helloMessage(String name) { - return "Hello " + name + "!"; - } -} diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/src/main/resources/index.html --- a/rt/mojo/src/main/resources/archetype-resources/src/main/resources/index.html Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,22 +0,0 @@ - - - - - Bck2Brwsr's Hello World - - -

Loading Bck2Brwsr's Hello World...

- Your name: - -

- - -

- - - - - diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java --- a/rt/mojo/src/main/resources/archetype-resources/src/test/java/AppTest.java Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,26 +0,0 @@ -package ${package}; - -import static org.testng.Assert.*; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** Demonstrating POJO testing of HTML page model. Runs in good old HotSpot - * as it does not reference any HTML elements or browser functionality. Just - * operates on the page model. - * - * @author Jaroslav Tulach - */ -public class AppTest { - private Index model; - - - @BeforeMethod - public void initModel() { - model = new Index().applyBindings(); - } - - @Test public void testHelloMessage() { - model.setName("Joe"); - assertEquals(model.getHelloMessage(), "Hello Joe!", "Cleared after pressing +"); - } -} diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java --- a/rt/mojo/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -package ${package}; - -import org.apidesign.bck2brwsr.vmtest.Compare; -import org.apidesign.bck2brwsr.vmtest.VMTest; -import org.testng.annotations.Factory; - -/** Bck2brwsr cares about compatibility with real Java. Whatever API is - * supported by bck2brwsr, it needs to behave the same way as when running - * in HotSpot VM. - *

- * There can be bugs, however. To help us fix them, we kindly ask you to - * write an "inconsistency" test. A test that compares behavior of the API - * between real VM and bck2brwsr VM. This class is skeleton of such test. - * - * @author Jaroslav Tulach - */ -public class InconsistencyTest { - /** A method to demonstrate inconsistency between bck2brwsr and HotSpot. - * Make calls to an API that behaves strangely, return some result at - * the end. No need to use any assert. - * - * @return value to compare between HotSpot and bck2brwsr - */ - @Compare - public int checkStringHashCode() throws Exception { - return "Is string hashCode the same?".hashCode(); - } - - /** Factory method that creates a three tests for each method annotated with - * {@link org.apidesign.bck2brwsr.vmtest.Compare}. One executes the code in - * HotSpot, one in Rhino and the last one compares the results. - * - * @see org.apidesign.bck2brwsr.vmtest.VMTest - */ - @Factory - public static Object[] create() { - return VMTest.create(InconsistencyTest.class); - } - -} diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java --- a/rt/mojo/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,46 +0,0 @@ -package ${package}; - -import org.apidesign.bck2brwsr.htmlpage.api.OnEvent; -import org.apidesign.bck2brwsr.vmtest.BrwsrTest; -import org.apidesign.bck2brwsr.vmtest.HtmlFragment; -import org.apidesign.bck2brwsr.vmtest.VMTest; -import org.testng.annotations.Factory; - -/** Sometimes it is useful to run tests inside of the real browser. - * To do that just annotate your method with {@link org.apidesign.bck2brwsr.vmtest.BrwsrTest} - * and that is it. If your code references elements on the HTML page, - * you can pass in an {@link org.apidesign.bck2brwsr.vmtest.HtmlFragment} which - * will be made available on the page before your test starts. - * - * @author Jaroslav Tulach - */ -public class IntegrationTest { - - /** Write to testing code here. Use assert (but not TestNG's - * Assert, as TestNG is not compiled with target 1.6 yet). - */ - @HtmlFragment( - "

Loading Bck2Brwsr's Hello World...

\n" + - "Your name: \n" + - "\n" + - "

\n" + - " \n" + - "

\n" - ) - @BrwsrTest - public void modifyValueAssertChangeInModel() { - Index m = new Index(); - m.setName("Joe Hacker"); - m.applyBindings(); - assert "Joe Hacker".equals(m.INPUT.getValue()) : "Value is really Joe Hacker: " + m.INPUT.getValue(); - m.INPUT.setValue("Happy Joe"); - m.triggerEvent(m.INPUT, OnEvent.CHANGE); - assert "Happy Joe".equals(m.getName()) : "Name property updated to Happy Joe: " + m.getName(); - } - - @Factory - public static Object[] create() { - return VMTest.create(IntegrationTest.class); - } - -} diff -r 03fe918c4684 -r 448bed1f6d5a rt/mojo/src/test/java/org/apidesign/bck2brwsr/mojo/ArchetypeVersionTest.java --- a/rt/mojo/src/test/java/org/apidesign/bck2brwsr/mojo/ArchetypeVersionTest.java Thu Mar 21 15:53:55 2013 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,102 +0,0 @@ -/** - * Back 2 Browser Bytecode Translator - * Copyright (C) 2012 Jaroslav Tulach - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, version 2 of the License. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. Look for COPYING file in the top folder. - * If not, see http://opensource.org/licenses/GPL-2.0. - */ -package org.apidesign.bck2brwsr.mojo; - -import java.net.URL; -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathFactory; -import org.testng.annotations.Test; -import org.xml.sax.InputSource; -import static org.testng.Assert.*; -import org.testng.annotations.BeforeClass; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; - -/** - * - * @author Jaroslav Tulach - */ -public class ArchetypeVersionTest { - private String version; - - public ArchetypeVersionTest() { - } - - @BeforeClass public void readCurrentVersion() throws Exception { - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); - URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/mojo/plugin-help.xml"); - assertNotNull(u, "Own pom found"); - - final XPathFactory fact = XPathFactory.newInstance(); - fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - - XPathExpression xp = fact.newXPath().compile("plugin/version/text()"); - version = xp.evaluate(new InputSource(u.openStream())); - - assertFalse(version.isEmpty(), "There should be some version string"); - } - - - @Test public void testComparePomDepsVersions() throws Exception { - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); - URL r = l.getResource("archetype-resources/pom.xml"); - assertNotNull(r, "Archetype pom found"); - - final XPathFactory fact = XPathFactory.newInstance(); - XPathExpression xp2 = fact.newXPath().compile( - "//version[../groupId/text() = 'org.apidesign.bck2brwsr']/text()" - ); - - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); - NodeList arch = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET); - - if (arch.getLength() < 3) { - fail("There should be at least three dependencies to bck2brwsr APIs: " + arch.getLength()); - } - - for (int i = 0; i < arch.getLength(); i++) { - assertEquals(arch.item(i).getTextContent(), version, i + "th dependency needs to be on latest version of bck2brwsr"); - } - } - - @Test public void testNbActions() throws Exception { - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); - URL r = l.getResource("archetype-resources/nbactions.xml"); - assertNotNull(r, "Archetype nb file found"); - - final XPathFactory fact = XPathFactory.newInstance(); - XPathExpression xp2 = fact.newXPath().compile( - "//goal/text()" - ); - - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); - NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET); - - for (int i = 0; i < goals.getLength(); i++) { - String s = goals.item(i).getTextContent(); - if (s.contains("bck2brwsr")) { - String[] arr = s.split(":"); - assertEquals(arr.length, 4, "Three :"); - assertEquals(arr[2], version, "Proper version is used"); - } - } - } -} diff -r 03fe918c4684 -r 448bed1f6d5a rt/pom.xml --- a/rt/pom.xml Thu Mar 21 15:53:55 2013 +0100 +++ b/rt/pom.xml Fri Mar 22 00:02:21 2013 +0100 @@ -15,6 +15,7 @@ core emul launcher + archetype mojo vm vmtest