ko-archetype-test/src/test/java/org/apidesign/html/archetype/test/VerifyArchetypeTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Wed, 15 May 2013 11:01:17 +0200
changeset 1212 70defaefc082
parent 1211 c4bcb9c2a973
permissions -rw-r--r--
Pass on the headless flag
jaroslav@1202
     1
/**
jaroslav@1202
     2
 * HTML via Java(tm) Language Bindings
jaroslav@1202
     3
 * Copyright (C) 2013 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@1202
    12
 * GNU General Public License for more details. apidesign.org
jaroslav@1202
    13
 * designates this particular file as subject to the
jaroslav@1202
    14
 * "Classpath" exception as provided by apidesign.org
jaroslav@1202
    15
 * in the License file that accompanied this code.
jaroslav@1202
    16
 *
jaroslav@1202
    17
 * You should have received a copy of the GNU General Public License
jaroslav@1202
    18
 * along with this program. Look for COPYING file in the top folder.
jaroslav@1202
    19
 * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
jaroslav@1202
    20
 */
jaroslav@1202
    21
package org.apidesign.html.archetype.test;
jaroslav@1202
    22
jaroslav@1202
    23
import java.io.File;
jaroslav@1202
    24
import java.util.Properties;
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@1202
    29
jaroslav@1202
    30
/**
jaroslav@1202
    31
 *
jaroslav@1202
    32
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1202
    33
 */
jaroslav@1202
    34
public class VerifyArchetypeTest {
jaroslav@1202
    35
    @Test public void fxBrwsrCompiles() throws Exception {
jaroslav@1202
    36
        final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
jaroslav@1202
    37
        generateFromArchetype(dir);
jaroslav@1202
    38
        
jaroslav@1202
    39
        File created = new File(dir, "o-a-test");
jaroslav@1202
    40
        assertTrue(created.isDirectory(), "Project created");
jaroslav@1202
    41
        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
jaroslav@1202
    42
        
jaroslav@1202
    43
        Verifier v = new Verifier(created.getAbsolutePath());
jaroslav@1202
    44
        v.executeGoal("verify");
jaroslav@1202
    45
        
jaroslav@1202
    46
        v.verifyErrorFreeLog();
jaroslav@1203
    47
        
jaroslav@1203
    48
        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
jaroslav@1203
    49
            if (l.contains("j2js")) {
jaroslav@1203
    50
                fail("No pre-compilaton:\n" + l);
jaroslav@1203
    51
            }
jaroslav@1203
    52
        }
jaroslav@1203
    53
        
jaroslav@1203
    54
        v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
jaroslav@1203
    55
        v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
jaroslav@1203
    56
    }
jaroslav@1203
    57
    
jaroslav@1203
    58
    @Test public void bck2BrwsrCompiles() throws Exception {
jaroslav@1203
    59
        final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
jaroslav@1203
    60
        generateFromArchetype(dir);
jaroslav@1203
    61
        
jaroslav@1203
    62
        File created = new File(dir, "o-a-test");
jaroslav@1203
    63
        assertTrue(created.isDirectory(), "Project created");
jaroslav@1203
    64
        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
jaroslav@1203
    65
        
jaroslav@1203
    66
        Verifier v = new Verifier(created.getAbsolutePath());
jaroslav@1212
    67
        Properties sysProp = v.getSystemProperties();
jaroslav@1212
    68
        if (Boolean.getBoolean("java.awt.headless")) {
jaroslav@1212
    69
            sysProp.put("java.awt.headless", "true");
jaroslav@1212
    70
        }
jaroslav@1203
    71
        v.addCliOption("-Pbck2brwsr");
jaroslav@1203
    72
        v.executeGoal("verify");
jaroslav@1203
    73
        
jaroslav@1203
    74
        v.verifyErrorFreeLog();
jaroslav@1203
    75
        
jaroslav@1203
    76
        // does pre-compilation to JavaScript
jaroslav@1203
    77
        v.verifyTextInLog("j2js");
jaroslav@1203
    78
        // uses Bck2BrwsrLauncher
jaroslav@1211
    79
        v.verifyTextInLog("BaseHTTPLauncher stopServerAndBrwsr");
jaroslav@1203
    80
        // building zip:
jaroslav@1203
    81
        v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
jaroslav@1203
    82
        
jaroslav@1203
    83
        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
jaroslav@1203
    84
            if (l.contains("fxbrwsr")) {
jaroslav@1203
    85
                fail("No fxbrwsr:\n" + l);
jaroslav@1203
    86
            }
jaroslav@1203
    87
        }
jaroslav@1203
    88
jaroslav@1208
    89
        File zip = new File(new File(created, "target"), "o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
jaroslav@1208
    90
        assertTrue(zip.isFile(), "Zip file with website was created");
jaroslav@1208
    91
        
jaroslav@1208
    92
        ZipFile zf = new ZipFile(zip);
jaroslav@1208
    93
        assertNotNull(zf.getEntry("public_html/index.html"), "index.html found");
jaroslav@1208
    94
        assertNotNull(zf.getEntry("public_html/twitterExample.css"), "css file found");
jaroslav@1208
    95
        
jaroslav@1202
    96
    }
jaroslav@1202
    97
jaroslav@1203
    98
    private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
jaroslav@1202
    99
        Verifier v = new Verifier(dir.getAbsolutePath());
jaroslav@1202
   100
        v.setAutoclean(false);
jaroslav@1203
   101
        v.setLogFileName("generate.log");
jaroslav@1202
   102
        v.deleteDirectory("");
jaroslav@1202
   103
        dir.mkdirs();
jaroslav@1202
   104
        Properties sysProp = v.getSystemProperties();
jaroslav@1202
   105
        sysProp.put("groupId", "org.apidesign.test");
jaroslav@1202
   106
        sysProp.put("artifactId", "o-a-test");
jaroslav@1202
   107
        sysProp.put("package", "org.apidesign.test.oat");
jaroslav@1202
   108
        sysProp.put("archetypeGroupId", "org.apidesign.html");
jaroslav@1202
   109
        sysProp.put("archetypeArtifactId", "knockout4j-archetype");
jaroslav@1202
   110
        sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
jaroslav@1203
   111
        
jaroslav@1203
   112
        for (String p : params) {
jaroslav@1203
   113
            v.addCliOption(p);
jaroslav@1203
   114
        }
jaroslav@1202
   115
        v.executeGoal("archetype:generate");
jaroslav@1202
   116
        v.verifyErrorFreeLog();
jaroslav@1202
   117
        return v;
jaroslav@1202
   118
    }
jaroslav@1202
   119
}