ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java Wed Jun 26 19:29:54 2013 +0200
1.3 @@ -0,0 +1,116 @@
1.4 +/**
1.5 + * Back 2 Browser Bytecode Translator
1.6 + * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 + *
1.8 + * This program is free software: you can redistribute it and/or modify
1.9 + * it under the terms of the GNU General Public License as published by
1.10 + * the Free Software Foundation, version 2 of the License.
1.11 + *
1.12 + * This program is distributed in the hope that it will be useful,
1.13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 + * GNU General Public License for more details.
1.16 + *
1.17 + * You should have received a copy of the GNU General Public License
1.18 + * along with this program. Look for COPYING file in the top folder.
1.19 + * If not, see http://opensource.org/licenses/GPL-2.0.
1.20 + */
1.21 +package org.apidesign.bck2brwsr.ko.archetype.test;
1.22 +
1.23 +import java.io.File;
1.24 +import java.util.Properties;
1.25 +import java.util.zip.ZipFile;
1.26 +import org.apache.maven.it.Verifier;
1.27 +import org.testng.annotations.Test;
1.28 +import static org.testng.Assert.*;
1.29 +
1.30 +/**
1.31 + *
1.32 + * @author Jaroslav Tulach <jtulach@netbeans.org>
1.33 + */
1.34 +public class VerifyArchetypeTest {
1.35 + @Test public void fxBrwsrCompiles() throws Exception {
1.36 + final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
1.37 + generateFromArchetype(dir);
1.38 +
1.39 + File created = new File(dir, "o-a-test");
1.40 + assertTrue(created.isDirectory(), "Project created");
1.41 + assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
1.42 +
1.43 + Verifier v = new Verifier(created.getAbsolutePath());
1.44 + v.executeGoal("verify");
1.45 +
1.46 + v.verifyErrorFreeLog();
1.47 +
1.48 + for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
1.49 + if (l.contains("j2js")) {
1.50 + fail("No pre-compilaton:\n" + l);
1.51 + }
1.52 + }
1.53 +
1.54 + v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
1.55 + v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
1.56 + }
1.57 +
1.58 + @Test public void bck2BrwsrCompiles() throws Exception {
1.59 + final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
1.60 + generateFromArchetype(dir);
1.61 +
1.62 + File created = new File(dir, "o-a-test");
1.63 + assertTrue(created.isDirectory(), "Project created");
1.64 + assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
1.65 +
1.66 + Verifier v = new Verifier(created.getAbsolutePath());
1.67 + Properties sysProp = v.getSystemProperties();
1.68 + if (Boolean.getBoolean("java.awt.headless")) {
1.69 + sysProp.put("java.awt.headless", "true");
1.70 + }
1.71 + v.addCliOption("-Pbck2brwsr");
1.72 + v.executeGoal("verify");
1.73 +
1.74 + v.verifyErrorFreeLog();
1.75 +
1.76 + // does pre-compilation to JavaScript
1.77 + v.verifyTextInLog("j2js");
1.78 + // uses Bck2BrwsrLauncher
1.79 + v.verifyTextInLog("BaseHTTPLauncher stopServerAndBrwsr");
1.80 + // building zip:
1.81 + v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
1.82 +
1.83 + for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
1.84 + if (l.contains("fxbrwsr")) {
1.85 + fail("No fxbrwsr:\n" + l);
1.86 + }
1.87 + }
1.88 +
1.89 + File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
1.90 + assertTrue(zip.isFile(), "Zip file with website was created");
1.91 +
1.92 + ZipFile zf = new ZipFile(zip);
1.93 + assertNotNull(zf.getEntry("public_html/index.html"), "index.html found");
1.94 + assertNotNull(zf.getEntry("public_html/twitterExample.css"), "css file found");
1.95 +
1.96 + }
1.97 +
1.98 + private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
1.99 + Verifier v = new Verifier(dir.getAbsolutePath());
1.100 + v.setAutoclean(false);
1.101 + v.setLogFileName("generate.log");
1.102 + v.deleteDirectory("");
1.103 + dir.mkdirs();
1.104 + Properties sysProp = v.getSystemProperties();
1.105 + sysProp.put("groupId", "org.apidesign.test");
1.106 + sysProp.put("artifactId", "o-a-test");
1.107 + sysProp.put("package", "org.apidesign.test.oat");
1.108 + sysProp.put("archetypeGroupId", "org.apidesign.html");
1.109 + sysProp.put("archetypeArtifactId", "knockout4j-archetype");
1.110 + sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
1.111 +
1.112 + for (String p : params) {
1.113 + v.addCliOption(p);
1.114 + }
1.115 + v.executeGoal("archetype:generate");
1.116 + v.verifyErrorFreeLog();
1.117 + return v;
1.118 + }
1.119 +}