ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 09 Sep 2013 17:34:30 +0200
changeset 1273 37ad459579bc
parent 1237 558604864a1b
child 1275 913732a84aa3
permissions -rw-r--r--
Rewritting the archetype to be simpler and more easily modifiable to one's needs
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    13  *
    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.
    17  */
    18 package org.apidesign.bck2brwsr.ko.archetype.test;
    19 
    20 import java.io.File;
    21 import java.util.Properties;
    22 import java.util.zip.ZipFile;
    23 import org.apache.maven.it.Verifier;
    24 import org.testng.annotations.Test;
    25 import static org.testng.Assert.*;
    26 
    27 /**
    28  *
    29  * @author Jaroslav Tulach <jtulach@netbeans.org>
    30  */
    31 public class VerifyArchetypeTest {
    32     @Test public void fxBrwsrCompiles() throws Exception {
    33         final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
    34         generateFromArchetype(dir);
    35         
    36         File created = new File(dir, "o-a-test");
    37         assertTrue(created.isDirectory(), "Project created");
    38         assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    39         
    40         Verifier v = new Verifier(created.getAbsolutePath());
    41         v.executeGoal("verify");
    42         
    43         v.verifyErrorFreeLog();
    44         
    45         for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    46             if (l.contains("j2js")) {
    47                 fail("No pre-compilaton:\n" + l);
    48             }
    49         }
    50         
    51         v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
    52         v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
    53     }
    54     
    55     @Test public void bck2BrwsrCompiles() throws Exception {
    56         final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
    57         generateFromArchetype(dir);
    58         
    59         File created = new File(dir, "o-a-test");
    60         assertTrue(created.isDirectory(), "Project created");
    61         assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    62         
    63         Verifier v = new Verifier(created.getAbsolutePath());
    64         Properties sysProp = v.getSystemProperties();
    65         if (Boolean.getBoolean("java.awt.headless")) {
    66             sysProp.put("java.awt.headless", "true");
    67         }
    68         v.addCliOption("-Pbck2brwsr");
    69         v.executeGoal("verify");
    70         
    71         v.verifyErrorFreeLog();
    72         
    73         // does pre-compilation to JavaScript
    74         v.verifyTextInLog("j2js");
    75         // uses Bck2BrwsrLauncher
    76         v.verifyTextInLog("BaseHTTPLauncher showBrwsr");
    77         // building zip:
    78         v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    79         
    80         for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    81             if (l.contains("fxbrwsr")) {
    82                 fail("No fxbrwsr:\n" + l);
    83             }
    84         }
    85 
    86         File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    87         assertTrue(zip.isFile(), "Zip file with website was created");
    88         
    89         ZipFile zf = new ZipFile(zip);
    90         assertNotNull(zf.getEntry("public_html/index.html"), "index.html found");
    91         
    92     }
    93 
    94     private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
    95         Verifier v = new Verifier(dir.getAbsolutePath());
    96         v.setAutoclean(false);
    97         v.setLogFileName("generate.log");
    98         v.deleteDirectory("");
    99         dir.mkdirs();
   100         Properties sysProp = v.getSystemProperties();
   101         sysProp.put("groupId", "org.apidesign.test");
   102         sysProp.put("artifactId", "o-a-test");
   103         sysProp.put("package", "org.apidesign.test.oat");
   104         sysProp.put("archetypeGroupId", "org.apidesign.bck2brwsr");
   105         sysProp.put("archetypeArtifactId", "knockout4j-archetype");
   106         sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
   107         
   108         for (String p : params) {
   109             v.addCliOption(p);
   110         }
   111         v.executeGoal("archetype:generate");
   112         v.verifyErrorFreeLog();
   113         return v;
   114     }
   115 }