ko-archetype-test/src/test/java/org/apidesign/html/archetype/test/ArchetypeVersionTest.java
Moving archetype tests into separate module - at that moment it is possible to use the previously generated archetype
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.test;
23 import java.io.IOException;
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;
42 * @author Jaroslav Tulach <jtulach@netbeans.org>
44 public class ArchetypeVersionTest {
45 private String version;
47 public ArchetypeVersionTest() {
50 @BeforeClass public void readCurrentVersion() throws Exception {
51 version = findCurrentVersion();
52 assertFalse(version.isEmpty(), "There should be some version string");
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");
61 final XPathFactory fact = XPathFactory.newInstance();
62 XPathExpression xp2 = fact.newXPath().compile(
63 "//properties/net.java.html.version/text()"
66 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
67 String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
69 assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
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");
77 final XPathFactory fact = XPathFactory.newInstance();
78 XPathExpression xp2 = fact.newXPath().compile(
82 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
83 NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
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);
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"));
98 final XPathFactory fact = XPathFactory.newInstance();
99 fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
101 XPathExpression xp = fact.newXPath().compile("project/version/text()");
103 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
104 return xp.evaluate(dom);