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 20:33:52 +0200
changeset 1275 913732a84aa3
parent 1273 37ad459579bc
child 1347 9cc0e1034f92
permissions -rw-r--r--
Verify all placeholders are substituted when building final ZIP distribution
jaroslav@1202
     1
/**
jaroslav@1227
     2
 * Back 2 Browser Bytecode Translator
jaroslav@1227
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@1202
     4
 *
jaroslav@1202
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@1202
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@1202
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@1202
     8
 *
jaroslav@1202
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@1202
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@1202
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@1227
    12
 * GNU General Public License for more details.
jaroslav@1202
    13
 *
jaroslav@1202
    14
 * You should have received a copy of the GNU General Public License
jaroslav@1202
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1227
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@1202
    17
 */
jaroslav@1228
    18
package org.apidesign.bck2brwsr.ko.archetype.test;
jaroslav@1202
    19
jaroslav@1202
    20
import java.io.File;
jaroslav@1275
    21
import java.io.IOException;
jaroslav@1275
    22
import java.io.InputStream;
jaroslav@1202
    23
import java.util.Properties;
jaroslav@1275
    24
import java.util.zip.ZipEntry;
jaroslav@1208
    25
import java.util.zip.ZipFile;
jaroslav@1202
    26
import org.apache.maven.it.Verifier;
jaroslav@1202
    27
import org.testng.annotations.Test;
jaroslav@1202
    28
import static org.testng.Assert.*;
jaroslav@1275
    29
import org.testng.reporters.Files;
jaroslav@1202
    30
jaroslav@1202
    31
/**
jaroslav@1202
    32
 *
jaroslav@1202
    33
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1202
    34
 */
jaroslav@1202
    35
public class VerifyArchetypeTest {
jaroslav@1202
    36
    @Test public void fxBrwsrCompiles() throws Exception {
jaroslav@1202
    37
        final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
jaroslav@1202
    38
        generateFromArchetype(dir);
jaroslav@1202
    39
        
jaroslav@1202
    40
        File created = new File(dir, "o-a-test");
jaroslav@1202
    41
        assertTrue(created.isDirectory(), "Project created");
jaroslav@1202
    42
        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
jaroslav@1202
    43
        
jaroslav@1202
    44
        Verifier v = new Verifier(created.getAbsolutePath());
jaroslav@1202
    45
        v.executeGoal("verify");
jaroslav@1202
    46
        
jaroslav@1202
    47
        v.verifyErrorFreeLog();
jaroslav@1203
    48
        
jaroslav@1203
    49
        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
jaroslav@1203
    50
            if (l.contains("j2js")) {
jaroslav@1203
    51
                fail("No pre-compilaton:\n" + l);
jaroslav@1203
    52
            }
jaroslav@1203
    53
        }
jaroslav@1203
    54
        
jaroslav@1203
    55
        v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
jaroslav@1203
    56
        v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
jaroslav@1203
    57
    }
jaroslav@1203
    58
    
jaroslav@1203
    59
    @Test public void bck2BrwsrCompiles() throws Exception {
jaroslav@1203
    60
        final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
jaroslav@1203
    61
        generateFromArchetype(dir);
jaroslav@1203
    62
        
jaroslav@1203
    63
        File created = new File(dir, "o-a-test");
jaroslav@1203
    64
        assertTrue(created.isDirectory(), "Project created");
jaroslav@1203
    65
        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
jaroslav@1203
    66
        
jaroslav@1203
    67
        Verifier v = new Verifier(created.getAbsolutePath());
jaroslav@1212
    68
        Properties sysProp = v.getSystemProperties();
jaroslav@1212
    69
        if (Boolean.getBoolean("java.awt.headless")) {
jaroslav@1212
    70
            sysProp.put("java.awt.headless", "true");
jaroslav@1212
    71
        }
jaroslav@1203
    72
        v.addCliOption("-Pbck2brwsr");
jaroslav@1203
    73
        v.executeGoal("verify");
jaroslav@1203
    74
        
jaroslav@1203
    75
        v.verifyErrorFreeLog();
jaroslav@1203
    76
        
jaroslav@1203
    77
        // does pre-compilation to JavaScript
jaroslav@1203
    78
        v.verifyTextInLog("j2js");
jaroslav@1203
    79
        // uses Bck2BrwsrLauncher
jaroslav@1237
    80
        v.verifyTextInLog("BaseHTTPLauncher showBrwsr");
jaroslav@1203
    81
        // building zip:
jaroslav@1203
    82
        v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
jaroslav@1203
    83
        
jaroslav@1203
    84
        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
jaroslav@1203
    85
            if (l.contains("fxbrwsr")) {
jaroslav@1203
    86
                fail("No fxbrwsr:\n" + l);
jaroslav@1203
    87
            }
jaroslav@1203
    88
        }
jaroslav@1203
    89
jaroslav@1208
    90
        File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
jaroslav@1208
    91
        assertTrue(zip.isFile(), "Zip file with website was created");
jaroslav@1208
    92
        
jaroslav@1208
    93
        ZipFile zf = new ZipFile(zip);
jaroslav@1275
    94
        final ZipEntry index = zf.getEntry("public_html/index.html");
jaroslav@1275
    95
        assertNotNull(index, "index.html found");
jaroslav@1208
    96
        
jaroslav@1275
    97
        String txt = readText(zf.getInputStream(index));
jaroslav@1275
    98
        final int beg = txt.indexOf("${");
jaroslav@1275
    99
        if (beg >= 0) {
jaroslav@1275
   100
            int end = txt.indexOf("}", beg);
jaroslav@1275
   101
            if (end < beg) {
jaroslav@1275
   102
                end = txt.length();
jaroslav@1275
   103
            }
jaroslav@1275
   104
            fail("No substitutions in index.html. Found: " + txt.substring(beg, end));
jaroslav@1275
   105
        }
jaroslav@1202
   106
    }
jaroslav@1202
   107
jaroslav@1203
   108
    private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
jaroslav@1202
   109
        Verifier v = new Verifier(dir.getAbsolutePath());
jaroslav@1202
   110
        v.setAutoclean(false);
jaroslav@1203
   111
        v.setLogFileName("generate.log");
jaroslav@1202
   112
        v.deleteDirectory("");
jaroslav@1202
   113
        dir.mkdirs();
jaroslav@1202
   114
        Properties sysProp = v.getSystemProperties();
jaroslav@1202
   115
        sysProp.put("groupId", "org.apidesign.test");
jaroslav@1202
   116
        sysProp.put("artifactId", "o-a-test");
jaroslav@1202
   117
        sysProp.put("package", "org.apidesign.test.oat");
jaroslav@1237
   118
        sysProp.put("archetypeGroupId", "org.apidesign.bck2brwsr");
jaroslav@1202
   119
        sysProp.put("archetypeArtifactId", "knockout4j-archetype");
jaroslav@1202
   120
        sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
jaroslav@1203
   121
        
jaroslav@1203
   122
        for (String p : params) {
jaroslav@1203
   123
            v.addCliOption(p);
jaroslav@1203
   124
        }
jaroslav@1202
   125
        v.executeGoal("archetype:generate");
jaroslav@1202
   126
        v.verifyErrorFreeLog();
jaroslav@1202
   127
        return v;
jaroslav@1202
   128
    }
jaroslav@1275
   129
    
jaroslav@1275
   130
    private static String readText(InputStream is) throws IOException {
jaroslav@1275
   131
        return Files.readFile(is);
jaroslav@1275
   132
    }
jaroslav@1202
   133
}