ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.ko.archetype.test;
21 import java.io.IOException;
22 import java.io.InputStream;
23 import java.util.Properties;
24 import java.util.zip.ZipEntry;
25 import java.util.zip.ZipFile;
26 import org.apache.maven.it.Verifier;
27 import org.testng.annotations.Test;
28 import static org.testng.Assert.*;
29 import org.testng.reporters.Files;
33 * @author Jaroslav Tulach <jtulach@netbeans.org>
35 public class VerifyArchetypeTest {
36 @Test public void fxBrwsrCompiles() throws Exception {
37 final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
38 generateFromArchetype(dir);
40 File created = new File(dir, "o-a-test");
41 assertTrue(created.isDirectory(), "Project created");
42 assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
44 Verifier v = new Verifier(created.getAbsolutePath());
45 v.executeGoal("verify");
47 v.verifyErrorFreeLog();
49 for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
50 if (l.contains("j2js")) {
51 fail("No pre-compilaton:\n" + l);
55 v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
56 v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
59 @Test public void bck2BrwsrCompiles() throws Exception {
60 final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
61 generateFromArchetype(dir);
63 File created = new File(dir, "o-a-test");
64 assertTrue(created.isDirectory(), "Project created");
65 assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
67 Verifier v = new Verifier(created.getAbsolutePath());
68 Properties sysProp = v.getSystemProperties();
69 if (Boolean.getBoolean("java.awt.headless")) {
70 sysProp.put("java.awt.headless", "true");
72 v.addCliOption("-Pbck2brwsr");
73 v.executeGoal("verify");
75 v.verifyErrorFreeLog();
77 // does pre-compilation to JavaScript
78 v.verifyTextInLog("j2js");
79 // uses Bck2BrwsrLauncher
80 v.verifyTextInLog("BaseHTTPLauncher showBrwsr");
82 v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
84 for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
85 if (l.contains("fxbrwsr")) {
86 fail("No fxbrwsr:\n" + l);
90 File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
91 assertTrue(zip.isFile(), "Zip file with website was created");
93 ZipFile zf = new ZipFile(zip);
94 final ZipEntry index = zf.getEntry("public_html/index.html");
95 assertNotNull(index, "index.html found");
97 String txt = readText(zf.getInputStream(index));
98 final int beg = txt.indexOf("${");
100 int end = txt.indexOf("}", beg);
104 fail("No substitutions in index.html. Found: " + txt.substring(beg, end));
108 private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
109 Verifier v = new Verifier(dir.getAbsolutePath());
110 v.setAutoclean(false);
111 v.setLogFileName("generate.log");
112 v.deleteDirectory("");
114 Properties sysProp = v.getSystemProperties();
115 sysProp.put("groupId", "org.apidesign.test");
116 sysProp.put("artifactId", "o-a-test");
117 sysProp.put("package", "org.apidesign.test.oat");
118 sysProp.put("archetypeGroupId", "org.apidesign.bck2brwsr");
119 sysProp.put("archetypeArtifactId", "knockout4j-archetype");
120 sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
122 for (String p : params) {
125 v.executeGoal("archetype:generate");
126 v.verifyErrorFreeLog();
130 private static String readText(InputStream is) throws IOException {
131 return Files.readFile(is);