# HG changeset patch # User Jaroslav Tulach # Date 1402299599 -7200 # Node ID d3cbe257c4e9e91097d7851154147a37932bd834 # Parent 80e39583b35d65835c2bc9c4bd1fe09fc3a4f8ac Removing the archetype. Enough to have a shared one at https://github.com/jtulach/html4j-archetype diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype-test/pom.xml --- a/ko/archetype-test/pom.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,48 +0,0 @@ - - - 4.0.0 - - org.apidesign.bck2brwsr - ko - 0.9-SNAPSHOT - - org.apidesign.bck2brwsr - ko-archetype-test - 0.9-SNAPSHOT - Knockout Bck2Brwsr Archetype Test - http://maven.apache.org - Verifies the Knockout & net.java.html.json archetype behaves properly. - - UTF-8 - - - - ${project.groupId} - knockout4j-archetype - ${project.version} - - - org.testng - testng - test - - - org.apache.maven.shared - maven-verifier - 1.4 - test - - - ${project.groupId} - ko-fx - ${project.version} - provided - - - ${project.groupId} - ko-bck2brwsr - ${project.version} - provided - - - diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java --- a/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,140 +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.ko.archetype.test; - -import java.io.IOException; -import java.net.URL; -import javax.xml.XMLConstants; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.xpath.XPathConstants; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; -import javax.xml.xpath.XPathFactory; -import javax.xml.xpath.XPathFactoryConfigurationException; -import org.testng.annotations.Test; -import static org.testng.Assert.*; -import org.testng.annotations.BeforeClass; -import org.w3c.dom.Document; -import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; - -/** - * - * @author Jaroslav Tulach - */ -public class ArchetypeVersionTest { - private String version; - - public ArchetypeVersionTest() { - } - - @BeforeClass public void readCurrentVersion() throws Exception { - version = findCurrentVersion(); - 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( - "//properties/net.java.html.version/text()" - ); - - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING); - - int snapshot = arch.indexOf("-SNAPSHOT"); - if (snapshot >= 0) { - arch = arch.substring(0, snapshot); - } - - assertTrue(arch.matches("[0-9\\.]+"), "net.java.html.json version seems valid: " + arch); - } - - @Test public void testCheckLauncher() 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( - "//properties/bck2brwsr.launcher.version/text()" - ); - - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING); - - assertEquals(arch, version, "launcher dependency is on more recent version"); - } - - @Test public void testCheckBck2Brwsr() 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( - "//properties/bck2brwsr.version/text()" - ); - - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING); - - assertEquals(arch, version, "bck2brwsr dependency is on more recent version"); - } - - @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("apidesign")) { - assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s); - } - } - } - - static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException { - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); - URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/knockout4j-archetype/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()); - return xp.evaluate(dom); - } -} diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java --- a/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,133 +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.ko.archetype.test; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.Properties; -import java.util.zip.ZipEntry; -import java.util.zip.ZipFile; -import org.apache.maven.it.Verifier; -import org.testng.annotations.Test; -import static org.testng.Assert.*; -import org.testng.reporters.Files; - -/** - * - * @author Jaroslav Tulach - */ -public class VerifyArchetypeTest { - @Test public void fxBrwsrCompiles() throws Exception { - final File dir = new File("target/tests/fxcompile/").getAbsoluteFile(); - generateFromArchetype(dir); - - File created = new File(dir, "o-a-test"); - assertTrue(created.isDirectory(), "Project created"); - assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there"); - - Verifier v = new Verifier(created.getAbsolutePath()); - v.executeGoal("verify"); - - v.verifyErrorFreeLog(); - - for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) { - if (l.contains("j2js")) { - fail("No pre-compilaton:\n" + l); - } - } - - v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher"); - v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip"); - } - - @Test public void bck2BrwsrCompiles() throws Exception { - final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile(); - generateFromArchetype(dir); - - File created = new File(dir, "o-a-test"); - assertTrue(created.isDirectory(), "Project created"); - assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there"); - - Verifier v = new Verifier(created.getAbsolutePath()); - Properties sysProp = v.getSystemProperties(); - if (Boolean.getBoolean("java.awt.headless")) { - sysProp.put("java.awt.headless", "true"); - } - v.addCliOption("-Pbck2brwsr"); - v.executeGoal("verify"); - - v.verifyErrorFreeLog(); - - // no longer does pre-compilation to JavaScript - // v.verifyTextInLog("j2js"); - // uses Bck2BrwsrLauncher - v.verifyTextInLog("BaseHTTPLauncher showBrwsr"); - // building zip: - v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip"); - - for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) { - if (l.contains("fxbrwsr")) { - fail("No fxbrwsr:\n" + l); - } - } - - File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip"); - assertTrue(zip.isFile(), "Zip file with website was created"); - - ZipFile zf = new ZipFile(zip); - final ZipEntry index = zf.getEntry("public_html/index.html"); - assertNotNull(index, "index.html found"); - - String txt = readText(zf.getInputStream(index)); - final int beg = txt.indexOf("${"); - if (beg >= 0) { - int end = txt.indexOf("}", beg); - if (end < beg) { - end = txt.length(); - } - fail("No substitutions in index.html. Found: " + txt.substring(beg, end)); - } - } - - private Verifier generateFromArchetype(final File dir, String... params) throws Exception { - Verifier v = new Verifier(dir.getAbsolutePath()); - v.setAutoclean(false); - v.setLogFileName("generate.log"); - v.deleteDirectory(""); - dir.mkdirs(); - Properties sysProp = v.getSystemProperties(); - sysProp.put("groupId", "org.apidesign.test"); - sysProp.put("artifactId", "o-a-test"); - sysProp.put("package", "org.apidesign.test.oat"); - sysProp.put("archetypeGroupId", "org.apidesign.bck2brwsr"); - sysProp.put("archetypeArtifactId", "knockout4j-archetype"); - sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion()); - - for (String p : params) { - v.addCliOption(p); - } - v.executeGoal("archetype:generate"); - v.verifyErrorFreeLog(); - return v; - } - - private static String readText(InputStream is) throws IOException { - return Files.readFile(is); - } -} diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/pom.xml --- a/ko/archetype/pom.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ - - - 4.0.0 - - ko - org.apidesign.bck2brwsr - 0.9-SNAPSHOT - - org.apidesign.bck2brwsr - knockout4j-archetype - 0.9-SNAPSHOT - jar - Knockout Bck2Brwsr Maven Archetype - - HTML page with Knockout.js bindings driven by application model - written in Java. Use your favorite language to code. Use - HTML as a lightweight rendering toolkit. Deploy using JavaFX or - bck2brwsr virtual machine. - - - - - src/main/resources - true - - **/pom.xml - - - - src/main/resources - false - - **/pom.xml - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.6 - 1.6 - - - - org.apache.maven.plugins - maven-resources-plugin - 2.6 - - \ - 1.6 - - - - - diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/java/org/apidesign/bck2brwsr/ko/archetype/package-info.java --- a/ko/archetype/src/main/java/org/apidesign/bck2brwsr/ko/archetype/package-info.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +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.ko.archetype; diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/META-INF/maven/archetype-metadata.xml --- a/ko/archetype/src/main/resources/META-INF/maven/archetype-metadata.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,63 +0,0 @@ - - - - - - src/main/java - - **/*.java - - - - src/main/webapp/pages - - **/*.xhtml - **/*.html - **/*.css - - - - src/test/java - - **/*Test.java - - - - src/main/assembly - - **/*.xml - - - - - - nbactions*.xml - - - - assembly - - fxbrwsr-assembly.xml - bck2brwsr-assembly.xml - - - - \ No newline at end of file diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/nbactions-bck2brwsr.xml --- a/ko/archetype/src/main/resources/archetype-resources/nbactions-bck2brwsr.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,14 +0,0 @@ - - - - run - - package - bck2brwsr:brwsr - - - true - NONE - - - diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/nbactions-fxbrwsr.xml --- a/ko/archetype/src/main/resources/archetype-resources/nbactions-fxbrwsr.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - - - - run - - process-classes - bck2brwsr:brwsr - - - - debug - - process-classes - bck2brwsr:brwsr - - - maven - - - diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/nbactions.xml --- a/ko/archetype/src/main/resources/archetype-resources/nbactions.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,20 +0,0 @@ - - - - run - - process-classes - bck2brwsr:brwsr - - - - debug - - process-classes - bck2brwsr:brwsr - - - maven - - - diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/pom.xml --- a/ko/archetype/src/main/resources/archetype-resources/pom.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,283 +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 - ${net.java.html.version} - ${project.version} - ${project.version} - MINIMAL - pages/index.html - none - - - - - org.apidesign.bck2brwsr - bck2brwsr-maven-plugin - \${bck2brwsr.launcher.version} - - - - brwsr - - - - - \${basedir}/src/main/webapp/ - ${brwsr.startpage} - ${brwsr} - - - - org.netbeans.html - html4j-maven-plugin - ${net.java.html.version} - - - js-classes - - process-js-annotations - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 2.3.2 - - 1.7 - 1.7 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.14.1 - - - \${brwsr} - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - true - lib/ - - - - - - org.apache.maven.plugins - maven-deploy-plugin - 2.7 - - true - - - - - - - - org.testng - testng - 6.7 - test - - - org.apidesign.bck2brwsr - launcher.http - \${bck2brwsr.launcher.version} - test - - - org.apidesign.bck2brwsr - vmtest - \${bck2brwsr.version} - test - - - org.netbeans.html - net.java.html.json - \${net.java.html.version} - jar - - - org.netbeans.html - net.java.html.boot - \${net.java.html.version} - jar - - - - - fxbrwsr - - true - - - fxbrwsr - - - - - org.apache.maven.plugins - maven-jar-plugin - 2.4 - - - - org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher - true - lib/ - - - \${brwsr.startpage} - - - - - - maven-assembly-plugin - 2.4 - - - distro-assembly - package - - single - - - - src/main/assembly/fxbrwsr.xml - - - - - - - - - - org.netbeans.html - ko4j - \${net.java.html.version} - - - org.apidesign.bck2brwsr - launcher.fx - \${bck2brwsr.launcher.version} - runtime - - - - - bck2brwsr - - - brwsr - bck2brwsr - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - - netbeans.ignore.jdk.bootclasspath - - - **/JsInteractionTest* - - - - - maven-assembly-plugin - 2.4 - - - distro-assembly - package - - single - - - - src/main/assembly/bck2brwsr.xml - - - - - - - - - - org.apidesign.bck2brwsr - emul - \${bck2brwsr.version} - rt - - - org.apidesign.bck2brwsr - ko-bck2brwsr - \${bck2brwsr.version} - runtime - - - org.apidesign.bck2brwsr - vm4brwsr - js - zip - \${bck2brwsr.version} - provided - - - - - diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/main/assembly/bck2brwsr.xml --- a/ko/archetype/src/main/resources/archetype-resources/src/main/assembly/bck2brwsr.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ - - - - bck2brwsr - - zip - - public_html - - - false - runtime - lib - - *:jar - *:rt - - - - false - provided - - *:js - - true - / - - - - - src/main/webapp/pages - / - true - - - - - ${project.build.directory}/${project.build.finalName}.jar - / - - - \ No newline at end of file diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/main/assembly/fxbrwsr.xml --- a/ko/archetype/src/main/resources/archetype-resources/src/main/assembly/fxbrwsr.xml Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ - - - - fxbrwsr - - zip - - ${project.build.finalName}-fxbrwsr - - - false - runtime - lib - - - - - ${project.build.directory}/${project.build.finalName}.jar - / - - - - - src/main/webapp/ - / - - pages/** - - true - - - \ No newline at end of file diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/main/java/DataModel.java --- a/ko/archetype/src/main/resources/archetype-resources/src/main/java/DataModel.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,45 +0,0 @@ -package ${package}; - -import net.java.html.json.ComputedProperty; -import net.java.html.json.Function; -import net.java.html.json.Model; -import net.java.html.json.Property; - -/** Model annotation generates class Data with - * one message property, boolean property and read only words property - */ -@Model(className = "Data", properties = { - @Property(name = "message", type = String.class), - @Property(name = "on", type = boolean.class) -}) -final class DataModel { - @ComputedProperty static java.util.List words(String message) { - String[] arr = new String[6]; - String[] words = message == null ? new String[0] : message.split(" ", 6); - for (int i = 0; i < 6; i++) { - arr[i] = words.length > i ? words[i] : "!"; - } - return java.util.Arrays.asList(arr); - } - - @Function static void turnOn(Data model) { - model.setOn(true); - } - - @Function static void turnOff(final Data model) { - confirmByUser("Really turn off?", new Runnable() { - @Override - public void run() { - model.setOn(false); - } - }); - } - - /** Shows direct interaction with JavaScript */ - @net.java.html.js.JavaScriptBody( - args = { "msg", "callback" }, - javacall = true, - body = "alert(msg); callback.@java.lang.Runnable::run()();" - ) - static native void confirmByUser(String msg, Runnable callback); -} diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/main/java/Main.java --- a/ko/archetype/src/main/resources/archetype-resources/src/main/java/Main.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -package ${package}; - -public final class Main { - private Main() { - } - - /** - * Called when the page is ready. - */ - static { - Data d = new Data(); - d.setMessage("Hello World from HTML and Java!"); - d.applyBindings(); - } -} diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/main/webapp/pages/index.html --- a/ko/archetype/src/main/resources/archetype-resources/src/main/webapp/pages/index.html Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,72 +0,0 @@ - - - - - - - - - - -

Words Demo

- -
- - - -
- - - -
- - - - diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/test/java/DataModelTest.java --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/DataModelTest.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,16 +0,0 @@ -package ${package}; - -import static org.testng.Assert.*; -import org.testng.annotations.Test; - -public class DataModelTest { - @Test public void areHelloWorldTwoWords() { - Data model = new Data(); - model.setMessage("Hello World!"); - - java.util.List arr = model.getWords(); - assertEquals(arr.size(), 6, "Six words always"); - assertEquals("Hello", arr.get(0), "Hello is the first word"); - assertEquals("World!", arr.get(1), "World is the second word"); - } -} diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/InconsistencyTest.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,38 +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. - */ -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 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/IntegrationTest.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,31 +0,0 @@ -package ${package}; - -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. - */ -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( - "

Put this snippet on the HTML page

\n" - ) - @BrwsrTest - public void runThisTestInABrowser() { - } - - @Factory - public static Object[] create() { - return VMTest.create(IntegrationTest.class); - } - -} diff -r 80e39583b35d -r d3cbe257c4e9 ko/archetype/src/main/resources/archetype-resources/src/test/java/JsInteractionTest.java --- a/ko/archetype/src/main/resources/archetype-resources/src/test/java/JsInteractionTest.java Mon Jun 09 09:38:03 2014 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -package ${package}; - -import java.io.Closeable; -import java.io.Reader; -import java.net.URL; -import java.util.ArrayList; -import java.util.List; -import javax.script.Invocable; -import javax.script.ScriptEngine; -import javax.script.ScriptEngineManager; -import javax.script.ScriptException; -import org.apidesign.html.boot.spi.Fn; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -/** Tests for behavior of @JavaScriptBody methods. Set your JavaScript - * environment up (for example define alert or use some - * emulation library like env.js), register script presenter - * and then you can call methods that deal with JavaScript in your tests. - */ -public class JsInteractionTest { - private Closeable jsEngine; - @BeforeMethod public void initializeJSEngine() throws Exception { - jsEngine = Fn.activate(new ScriptPresenter()); - } - - @AfterMethod public void shutdownJSEngine() throws Exception { - jsEngine.close(); - } - - @Test public void testCallbackFromJavaScript() throws Exception { - class R implements Runnable { - int called; - - @Override - public void run() { - called++; - } - } - R callback = new R(); - - DataModel.confirmByUser("Hello", callback); - - assertEquals(callback.called, 1, "One immediate callback"); - } - - private static class ScriptPresenter implements Fn.Presenter { - private final ScriptEngine eng; - - public ScriptPresenter() throws ScriptException { - eng = new ScriptEngineManager().getEngineByName("javascript"); - eng.eval("function alert(msg) { Packages.java.lang.System.out.println(msg); };"); - } - - @Override - public Fn defineFn(String code, String... names) { - StringBuilder sb = new StringBuilder(); - sb.append("(function() {"); - sb.append(" return function("); - String sep = ""; - for (String n : names) { - sb.append(sep).append(n); - sep = ","; - } - sb.append(") {\n"); - sb.append(code); - sb.append("};"); - sb.append("})()"); - - final Object fn; - try { - fn = eng.eval(sb.toString()); - } catch (ScriptException ex) { - throw new IllegalStateException(ex); - } - return new Fn(this) { - @Override - public Object invoke(Object thiz, Object... args) throws Exception { - List all = new ArrayList(args.length + 1); - all.add(thiz == null ? fn : thiz); - for (int i = 0; i < args.length; i++) { - all.add(args[i]); - } - Object ret = ((Invocable)eng).invokeMethod(fn, "call", all.toArray()); // NOI18N - return fn.equals(ret) ? null : thiz; - } - }; - } - - @Override - public void displayPage(URL page, Runnable onPageLoad) { - // not really displaying anything - onPageLoad.run(); - } - - @Override - public void loadScript(Reader code) throws Exception { - eng.eval(code); - } - } -} diff -r 80e39583b35d -r d3cbe257c4e9 ko/pom.xml --- a/ko/pom.xml Mon Jun 09 09:38:03 2014 +0200 +++ b/ko/pom.xml Mon Jun 09 09:39:59 2014 +0200 @@ -12,8 +12,6 @@ 0.9-SNAPSHOT - archetype - archetype-test bck2brwsr fx