ko-archetype-test/src/test/java/org/apidesign/html/archetype/test/VerifyArchetypeTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 13 May 2013 14:53:16 +0200
changeset 1203 eaa7c421a09e
parent 1202 5f04bdbc6ee1
child 1208 ea9ac5eea2d4
permissions -rw-r--r--
Verifies the compilation and test execution works on both profiles: fxbrwsr as well as bck2brwsr
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@1202
    25
import org.apache.maven.it.Verifier;
jaroslav@1202
    26
import org.testng.annotations.Test;
jaroslav@1202
    27
import static org.testng.Assert.*;
jaroslav@1202
    28
jaroslav@1202
    29
/**
jaroslav@1202
    30
 *
jaroslav@1202
    31
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@1202
    32
 */
jaroslav@1202
    33
public class VerifyArchetypeTest {
jaroslav@1202
    34
    @Test public void fxBrwsrCompiles() throws Exception {
jaroslav@1202
    35
        final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
jaroslav@1202
    36
        generateFromArchetype(dir);
jaroslav@1202
    37
        
jaroslav@1202
    38
        File created = new File(dir, "o-a-test");
jaroslav@1202
    39
        assertTrue(created.isDirectory(), "Project created");
jaroslav@1202
    40
        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
jaroslav@1202
    41
        
jaroslav@1202
    42
        Verifier v = new Verifier(created.getAbsolutePath());
jaroslav@1202
    43
        v.executeGoal("verify");
jaroslav@1202
    44
        
jaroslav@1202
    45
        v.verifyErrorFreeLog();
jaroslav@1203
    46
        
jaroslav@1203
    47
        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
jaroslav@1203
    48
            if (l.contains("j2js")) {
jaroslav@1203
    49
                fail("No pre-compilaton:\n" + l);
jaroslav@1203
    50
            }
jaroslav@1203
    51
        }
jaroslav@1203
    52
        
jaroslav@1203
    53
        v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.FXBrwsrLauncher");
jaroslav@1203
    54
        v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-fxbrwsr.zip");
jaroslav@1203
    55
    }
jaroslav@1203
    56
    
jaroslav@1203
    57
    @Test public void bck2BrwsrCompiles() throws Exception {
jaroslav@1203
    58
        final File dir = new File("target/tests/b2bcompile/").getAbsoluteFile();
jaroslav@1203
    59
        generateFromArchetype(dir);
jaroslav@1203
    60
        
jaroslav@1203
    61
        File created = new File(dir, "o-a-test");
jaroslav@1203
    62
        assertTrue(created.isDirectory(), "Project created");
jaroslav@1203
    63
        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
jaroslav@1203
    64
        
jaroslav@1203
    65
        Verifier v = new Verifier(created.getAbsolutePath());
jaroslav@1203
    66
        v.addCliOption("-Pbck2brwsr");
jaroslav@1203
    67
        v.executeGoal("verify");
jaroslav@1203
    68
        
jaroslav@1203
    69
        v.verifyErrorFreeLog();
jaroslav@1203
    70
        
jaroslav@1203
    71
        // does pre-compilation to JavaScript
jaroslav@1203
    72
        v.verifyTextInLog("j2js");
jaroslav@1203
    73
        // uses Bck2BrwsrLauncher
jaroslav@1203
    74
        v.verifyTextInLog("org.apidesign.bck2brwsr.launcher.Bck2BrwsrLauncher stopServerAndBrwsr");
jaroslav@1203
    75
        // building zip:
jaroslav@1203
    76
        v.verifyTextInLog("b2bcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-bck2brwsr.zip");
jaroslav@1203
    77
        
jaroslav@1203
    78
        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
jaroslav@1203
    79
            if (l.contains("fxbrwsr")) {
jaroslav@1203
    80
                fail("No fxbrwsr:\n" + l);
jaroslav@1203
    81
            }
jaroslav@1203
    82
        }
jaroslav@1203
    83
jaroslav@1202
    84
    }
jaroslav@1202
    85
jaroslav@1203
    86
    private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
jaroslav@1202
    87
        Verifier v = new Verifier(dir.getAbsolutePath());
jaroslav@1202
    88
        v.setAutoclean(false);
jaroslav@1203
    89
        v.setLogFileName("generate.log");
jaroslav@1202
    90
        v.deleteDirectory("");
jaroslav@1202
    91
        dir.mkdirs();
jaroslav@1202
    92
        Properties sysProp = v.getSystemProperties();
jaroslav@1202
    93
        sysProp.put("groupId", "org.apidesign.test");
jaroslav@1202
    94
        sysProp.put("artifactId", "o-a-test");
jaroslav@1202
    95
        sysProp.put("package", "org.apidesign.test.oat");
jaroslav@1202
    96
        sysProp.put("archetypeGroupId", "org.apidesign.html");
jaroslav@1202
    97
        sysProp.put("archetypeArtifactId", "knockout4j-archetype");
jaroslav@1202
    98
        sysProp.put("archetypeVersion", ArchetypeVersionTest.findCurrentVersion());
jaroslav@1203
    99
        
jaroslav@1203
   100
        for (String p : params) {
jaroslav@1203
   101
            v.addCliOption(p);
jaroslav@1203
   102
        }
jaroslav@1202
   103
        v.executeGoal("archetype:generate");
jaroslav@1202
   104
        v.verifyErrorFreeLog();
jaroslav@1202
   105
        return v;
jaroslav@1202
   106
    }
jaroslav@1202
   107
}