ko-archetype/src/test/java/org/apidesign/html/archetype/ArchetypeVersionTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 13 May 2013 11:39:33 +0200
changeset 1201 b6fd8b9ccc7a
permissions -rw-r--r--
First sketch of the Knockout4J archetype
     1 /**
     2  * HTML via Java(tm) Language Bindings
     3  * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     5  * This program is free software: you can redistribute it and/or modify
     6  * it under the terms of the GNU General Public License as published by
     7  * the Free Software Foundation, version 2 of the License.
     8  *
     9  * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU General Public License for more details. apidesign.org
    13  * designates this particular file as subject to the
    14  * "Classpath" exception as provided by apidesign.org
    15  * in the License file that accompanied this code.
    16  *
    17  * You should have received a copy of the GNU General Public License
    18  * along with this program. Look for COPYING file in the top folder.
    19  * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    20  */
    21 package org.apidesign.html.archetype;
    22 
    23 import java.net.URL;
    24 import javax.xml.XMLConstants;
    25 import javax.xml.parsers.DocumentBuilderFactory;
    26 import javax.xml.xpath.XPathConstants;
    27 import javax.xml.xpath.XPathExpression;
    28 import javax.xml.xpath.XPathFactory;
    29 import org.testng.annotations.Test;
    30 import static org.testng.Assert.*;
    31 import org.testng.annotations.BeforeClass;
    32 import org.w3c.dom.Document;
    33 import org.w3c.dom.NodeList;
    34 
    35 /**
    36  *
    37  * @author Jaroslav Tulach <jtulach@netbeans.org>
    38  */
    39 public class ArchetypeVersionTest {
    40     private String version;
    41     
    42     public ArchetypeVersionTest() {
    43     }
    44     
    45     @BeforeClass public void readCurrentVersion() throws Exception {
    46         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    47         URL u = l.getResource("META-INF/maven/org.apidesign.html/knockout4j-archetype/pom.xml");
    48         assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
    49 
    50         final XPathFactory fact = XPathFactory.newInstance();
    51         fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    52 
    53         XPathExpression xp = fact.newXPath().compile("project/version/text()");
    54         
    55         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
    56         version = xp.evaluate(dom);
    57 
    58         assertFalse(version.isEmpty(), "There should be some version string");
    59     }
    60     
    61 
    62     @Test public void testComparePomDepsVersions() throws Exception {
    63         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    64         URL r = l.getResource("archetype-resources/pom.xml");
    65         assertNotNull(r, "Archetype pom found");
    66         
    67         final XPathFactory fact = XPathFactory.newInstance();
    68         XPathExpression xp2 = fact.newXPath().compile(
    69             "//properties/net.java.html.version/text()"
    70         );
    71         
    72         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    73         String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    74 
    75         assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
    76     }
    77     
    78     @Test public void testNbActions() throws Exception {
    79         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    80         URL r = l.getResource("archetype-resources/nbactions.xml");
    81         assertNotNull(r, "Archetype nb file found");
    82         
    83         final XPathFactory fact = XPathFactory.newInstance();
    84         XPathExpression xp2 = fact.newXPath().compile(
    85             "//goal/text()"
    86         );
    87         
    88         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    89         NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
    90         
    91         for (int i = 0; i < goals.getLength(); i++) {
    92             String s = goals.item(i).getTextContent();
    93             if (s.contains("apidesign")) {
    94                 assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
    95             }
    96         }
    97     }
    98 }