ko-archetype-test/src/test/java/org/apidesign/html/archetype/test/ArchetypeVersionTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Mon, 13 May 2013 14:53:16 +0200
changeset 1203 eaa7c421a09e
parent 1201 b6fd8b9ccc7a
child 1210 82300c4f5c54
permissions -rw-r--r--
Verifies the compilation and test execution works on both profiles: fxbrwsr as well as bck2brwsr
     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.test;
    22 
    23 import java.io.IOException;
    24 import java.net.URL;
    25 import javax.xml.XMLConstants;
    26 import javax.xml.parsers.DocumentBuilderFactory;
    27 import javax.xml.parsers.ParserConfigurationException;
    28 import javax.xml.xpath.XPathConstants;
    29 import javax.xml.xpath.XPathExpression;
    30 import javax.xml.xpath.XPathExpressionException;
    31 import javax.xml.xpath.XPathFactory;
    32 import javax.xml.xpath.XPathFactoryConfigurationException;
    33 import org.testng.annotations.Test;
    34 import static org.testng.Assert.*;
    35 import org.testng.annotations.BeforeClass;
    36 import org.w3c.dom.Document;
    37 import org.w3c.dom.NodeList;
    38 import org.xml.sax.SAXException;
    39 
    40 /**
    41  *
    42  * @author Jaroslav Tulach <jtulach@netbeans.org>
    43  */
    44 public class ArchetypeVersionTest {
    45     private String version;
    46     
    47     public ArchetypeVersionTest() {
    48     }
    49     
    50     @BeforeClass public void readCurrentVersion() throws Exception {
    51         version = findCurrentVersion();
    52         assertFalse(version.isEmpty(), "There should be some version string");
    53     }
    54     
    55 
    56     @Test public void testComparePomDepsVersions() throws Exception {
    57         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    58         URL r = l.getResource("archetype-resources/pom.xml");
    59         assertNotNull(r, "Archetype pom found");
    60         
    61         final XPathFactory fact = XPathFactory.newInstance();
    62         XPathExpression xp2 = fact.newXPath().compile(
    63             "//properties/net.java.html.version/text()"
    64         );
    65         
    66         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    67         String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    68 
    69         assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
    70     }
    71     
    72     @Test public void testNbActions() throws Exception {
    73         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    74         URL r = l.getResource("archetype-resources/nbactions.xml");
    75         assertNotNull(r, "Archetype nb file found");
    76         
    77         final XPathFactory fact = XPathFactory.newInstance();
    78         XPathExpression xp2 = fact.newXPath().compile(
    79             "//goal/text()"
    80         );
    81         
    82         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    83         NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
    84         
    85         for (int i = 0; i < goals.getLength(); i++) {
    86             String s = goals.item(i).getTextContent();
    87             if (s.contains("apidesign")) {
    88                 assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
    89             }
    90         }
    91     }
    92 
    93     static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
    94         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    95         URL u = l.getResource("META-INF/maven/org.apidesign.html/knockout4j-archetype/pom.xml");
    96         assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
    97 
    98         final XPathFactory fact = XPathFactory.newInstance();
    99         fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
   100 
   101         XPathExpression xp = fact.newXPath().compile("project/version/text()");
   102         
   103         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
   104         return xp.evaluate(dom);
   105     }
   106 }