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