ko-archetype/src/test/java/org/apidesign/html/archetype/ArchetypeVersionTest.java
2 * HTML via Java(tm) Language Bindings
3 * Copyright (C) 2013 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
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.
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.
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
21 package org.apidesign.html.archetype;
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;
37 * @author Jaroslav Tulach <jtulach@netbeans.org>
39 public class ArchetypeVersionTest {
40 private String version;
42 public ArchetypeVersionTest() {
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"));
50 final XPathFactory fact = XPathFactory.newInstance();
51 fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
53 XPathExpression xp = fact.newXPath().compile("project/version/text()");
55 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
56 version = xp.evaluate(dom);
58 assertFalse(version.isEmpty(), "There should be some version string");
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");
67 final XPathFactory fact = XPathFactory.newInstance();
68 XPathExpression xp2 = fact.newXPath().compile(
69 "//properties/net.java.html.version/text()"
72 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
73 String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
75 assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
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");
83 final XPathFactory fact = XPathFactory.newInstance();
84 XPathExpression xp2 = fact.newXPath().compile(
88 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
89 NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
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);