ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java
changeset 1619 a7bf87c2c1d9
parent 1574 d51a5533a2e7
parent 1618 f62b42f0b751
child 1620 15c6f1aabe13
     1.1 --- a/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/VerifyArchetypeTest.java	Thu May 15 11:38:27 2014 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,133 +0,0 @@
     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.io.IOException;
    1.25 -import java.io.InputStream;
    1.26 -import java.util.Properties;
    1.27 -import java.util.zip.ZipEntry;
    1.28 -import java.util.zip.ZipFile;
    1.29 -import org.apache.maven.it.Verifier;
    1.30 -import org.testng.annotations.Test;
    1.31 -import static org.testng.Assert.*;
    1.32 -import org.testng.reporters.Files;
    1.33 -
    1.34 -/**
    1.35 - *
    1.36 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.37 - */
    1.38 -public class VerifyArchetypeTest {
    1.39 -    @Test public void fxBrwsrCompiles() throws Exception {
    1.40 -        final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
    1.41 -        generateFromArchetype(dir);
    1.42 -        
    1.43 -        File created = new File(dir, "o-a-test");
    1.44 -        assertTrue(created.isDirectory(), "Project created");
    1.45 -        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    1.46 -        
    1.47 -        Verifier v = new Verifier(created.getAbsolutePath());
    1.48 -        v.executeGoal("verify");
    1.49 -        
    1.50 -        v.verifyErrorFreeLog();
    1.51 -        
    1.52 -        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    1.53 -            if (l.contains("j2js")) {
    1.54 -                fail("No pre-compilaton:\n" + l);
    1.55 -            }
    1.56 -        }
    1.57 -        
    1.58 -        v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
    1.59 -        v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
    1.60 -    }
    1.61 -    
    1.62 -    @Test public void bck2BrwsrCompiles() throws Exception {
    1.63 -        final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
    1.64 -        generateFromArchetype(dir);
    1.65 -        
    1.66 -        File created = new File(dir, "o-a-test");
    1.67 -        assertTrue(created.isDirectory(), "Project created");
    1.68 -        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
    1.69 -        
    1.70 -        Verifier v = new Verifier(created.getAbsolutePath());
    1.71 -        Properties sysProp = v.getSystemProperties();
    1.72 -        if (Boolean.getBoolean("java.awt.headless")) {
    1.73 -            sysProp.put("java.awt.headless", "true");
    1.74 -        }
    1.75 -        v.addCliOption("-Pbck2brwsr");
    1.76 -        v.executeGoal("verify");
    1.77 -        
    1.78 -        v.verifyErrorFreeLog();
    1.79 -        
    1.80 -        // no longer does pre-compilation to JavaScript
    1.81 -        // v.verifyTextInLog("j2js");
    1.82 -        // uses Bck2BrwsrLauncher
    1.83 -        v.verifyTextInLog("BaseHTTPLauncher showBrwsr");
    1.84 -        // building zip:
    1.85 -        v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    1.86 -        
    1.87 -        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
    1.88 -            if (l.contains("fxbrwsr")) {
    1.89 -                fail("No fxbrwsr:\n" + l);
    1.90 -            }
    1.91 -        }
    1.92 -
    1.93 -        File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
    1.94 -        assertTrue(zip.isFile(), "Zip file with website was created");
    1.95 -        
    1.96 -        ZipFile zf = new ZipFile(zip);
    1.97 -        final ZipEntry index = zf.getEntry("public_html/index.html");
    1.98 -        assertNotNull(index, "index.html found");
    1.99 -        
   1.100 -        String txt = readText(zf.getInputStream(index));
   1.101 -        final int beg = txt.indexOf("${");
   1.102 -        if (beg >= 0) {
   1.103 -            int end = txt.indexOf("}", beg);
   1.104 -            if (end < beg) {
   1.105 -                end = txt.length();
   1.106 -            }
   1.107 -            fail("No substitutions in index.html. Found: " + txt.substring(beg, end));
   1.108 -        }
   1.109 -    }
   1.110 -
   1.111 -    private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
   1.112 -        Verifier v = new Verifier(dir.getAbsolutePath());
   1.113 -        v.setAutoclean(false);
   1.114 -        v.setLogFileName("generate.log");
   1.115 -        v.deleteDirectory("");
   1.116 -        dir.mkdirs();
   1.117 -        Properties sysProp = v.getSystemProperties();
   1.118 -        sysProp.put("groupId", "org.apidesign.test");
   1.119 -        sysProp.put("artifactId", "o-a-test");
   1.120 -        sysProp.put("package", "org.apidesign.test.oat");
   1.121 -        sysProp.put("archetypeGroupId", "org.apidesign.bck2brwsr");
   1.122 -        sysProp.put("archetypeArtifactId", "knockout4j-archetype");
   1.123 -        sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
   1.124 -        
   1.125 -        for (String p : params) {
   1.126 -            v.addCliOption(p);
   1.127 -        }
   1.128 -        v.executeGoal("archetype:generate");
   1.129 -        v.verifyErrorFreeLog();
   1.130 -        return v;
   1.131 -    }
   1.132 -    
   1.133 -    private static String readText(InputStream is) throws IOException {
   1.134 -        return Files.readFile(is);
   1.135 -    }
   1.136 -}