ko-archetype-test/src/test/java/org/netbeans/html/archetype/test/VerifyArchetypeIT.java
author Jaroslav Tulach <jaroslav.tulach@netbeans.org>
Fri, 07 Feb 2014 07:44:34 +0100
changeset 551 7ca2253fa86d
parent 478 d135f0263960
permissions -rw-r--r--
Updating copyright headers to mention current year
jaroslav@478
     1
/**
jaroslav@478
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
jaroslav@478
     3
 *
jaroslav@551
     4
 * Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
jaroslav@478
     5
 *
jaroslav@478
     6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
jaroslav@478
     7
 * Other names may be trademarks of their respective owners.
jaroslav@478
     8
 *
jaroslav@478
     9
 * The contents of this file are subject to the terms of either the GNU
jaroslav@478
    10
 * General Public License Version 2 only ("GPL") or the Common
jaroslav@478
    11
 * Development and Distribution License("CDDL") (collectively, the
jaroslav@478
    12
 * "License"). You may not use this file except in compliance with the
jaroslav@478
    13
 * License. You can obtain a copy of the License at
jaroslav@478
    14
 * http://www.netbeans.org/cddl-gplv2.html
jaroslav@478
    15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
jaroslav@478
    16
 * specific language governing permissions and limitations under the
jaroslav@478
    17
 * License.  When distributing the software, include this License Header
jaroslav@478
    18
 * Notice in each file and include the License file at
jaroslav@478
    19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
jaroslav@478
    20
 * particular file as subject to the "Classpath" exception as provided
jaroslav@478
    21
 * by Oracle in the GPL Version 2 section of the License file that
jaroslav@478
    22
 * accompanied this code. If applicable, add the following below the
jaroslav@478
    23
 * License Header, with the fields enclosed by brackets [] replaced by
jaroslav@478
    24
 * your own identifying information:
jaroslav@478
    25
 * "Portions Copyrighted [year] [name of copyright owner]"
jaroslav@478
    26
 *
jaroslav@478
    27
 * Contributor(s):
jaroslav@478
    28
 *
jaroslav@478
    29
 * The Original Software is NetBeans. The Initial Developer of the Original
jaroslav@551
    30
 * Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
jaroslav@478
    31
 *
jaroslav@478
    32
 * If you wish your version of this file to be governed by only the CDDL
jaroslav@478
    33
 * or only the GPL Version 2, indicate your decision by adding
jaroslav@478
    34
 * "[Contributor] elects to include this software in this distribution
jaroslav@478
    35
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
jaroslav@478
    36
 * single choice of license, a recipient has the option to distribute
jaroslav@478
    37
 * your version of this file under either the CDDL, the GPL Version 2 or
jaroslav@478
    38
 * to extend the choice of license to its licensees as provided above.
jaroslav@478
    39
 * However, if you add GPL Version 2 code and therefore, elected the GPL
jaroslav@478
    40
 * Version 2 license, then the option applies only if the new code is
jaroslav@478
    41
 * made subject to such option by the copyright holder.
jaroslav@478
    42
 */
jaroslav@478
    43
package org.netbeans.html.archetype.test;
jaroslav@478
    44
jaroslav@478
    45
import java.io.File;
jaroslav@478
    46
import java.util.Properties;
jaroslav@478
    47
import org.apache.maven.it.Verifier;
jaroslav@478
    48
import org.testng.annotations.Test;
jaroslav@478
    49
import static org.testng.Assert.*;
jaroslav@478
    50
jaroslav@478
    51
/**
jaroslav@478
    52
 *
jaroslav@478
    53
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@478
    54
 */
jaroslav@478
    55
public class VerifyArchetypeIT {
jaroslav@478
    56
    @Test public void projectCompiles() throws Exception {
jaroslav@478
    57
        final File dir = new File("target/tests/fxcompile/").getAbsoluteFile();
jaroslav@478
    58
        generateFromArchetype(dir);
jaroslav@478
    59
        
jaroslav@478
    60
        File created = new File(dir, "o-a-test");
jaroslav@478
    61
        assertTrue(created.isDirectory(), "Project created");
jaroslav@478
    62
        assertTrue(new File(created, "pom.xml").isFile(), "Pom file is in there");
jaroslav@478
    63
        
jaroslav@478
    64
        Verifier v = new Verifier(created.getAbsolutePath());
jaroslav@478
    65
        v.executeGoal("verify");
jaroslav@478
    66
        
jaroslav@478
    67
        v.verifyErrorFreeLog();
jaroslav@478
    68
        
jaroslav@478
    69
        for (String l : v.loadFile(v.getBasedir(), v.getLogFileName(), false)) {
jaroslav@478
    70
            if (l.contains("j2js")) {
jaroslav@478
    71
                fail("No pre-compilaton:\n" + l);
jaroslav@478
    72
            }
jaroslav@478
    73
        }
jaroslav@478
    74
        
jaroslav@478
    75
        v.verifyTextInLog("fxcompile/o-a-test/target/o-a-test-1.0-SNAPSHOT-html.java.net.zip");
jaroslav@478
    76
    }
jaroslav@478
    77
    
jaroslav@478
    78
    private Verifier generateFromArchetype(final File dir, String... params) throws Exception {
jaroslav@478
    79
        Verifier v = new Verifier(dir.getAbsolutePath());
jaroslav@478
    80
        v.setAutoclean(false);
jaroslav@478
    81
        v.setLogFileName("generate.log");
jaroslav@478
    82
        v.deleteDirectory("");
jaroslav@478
    83
        dir.mkdirs();
jaroslav@478
    84
        Properties sysProp = v.getSystemProperties();
jaroslav@478
    85
        sysProp.put("groupId", "org.someuser.test");
jaroslav@478
    86
        sysProp.put("artifactId", "o-a-test");
jaroslav@478
    87
        sysProp.put("package", "org.someuser.test.oat");
jaroslav@478
    88
        sysProp.put("archetypeGroupId", "org.apidesign.html");
jaroslav@478
    89
        sysProp.put("archetypeArtifactId", "knockout4j-archetype");
jaroslav@478
    90
        sysProp.put("archetypeVersion", ArchetypeVersionIT.findCurrentVersion());
jaroslav@478
    91
        
jaroslav@478
    92
        for (String p : params) {
jaroslav@478
    93
            v.addCliOption(p);
jaroslav@478
    94
        }
jaroslav@478
    95
        v.executeGoal("archetype:generate");
jaroslav@478
    96
        v.verifyErrorFreeLog();
jaroslav@478
    97
        return v;
jaroslav@478
    98
    }
jaroslav@478
    99
}