ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 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.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.ko.archetype.test;
20 import java.io.IOException;
22 import javax.xml.XMLConstants;
23 import javax.xml.parsers.DocumentBuilderFactory;
24 import javax.xml.parsers.ParserConfigurationException;
25 import javax.xml.xpath.XPathConstants;
26 import javax.xml.xpath.XPathExpression;
27 import javax.xml.xpath.XPathExpressionException;
28 import javax.xml.xpath.XPathFactory;
29 import javax.xml.xpath.XPathFactoryConfigurationException;
30 import org.testng.annotations.Test;
31 import static org.testng.Assert.*;
32 import org.testng.annotations.BeforeClass;
33 import org.w3c.dom.Document;
34 import org.w3c.dom.NodeList;
35 import org.xml.sax.SAXException;
39 * @author Jaroslav Tulach <jtulach@netbeans.org>
41 public class ArchetypeVersionTest {
42 private String version;
44 public ArchetypeVersionTest() {
47 @BeforeClass public void readCurrentVersion() throws Exception {
48 version = findCurrentVersion();
49 assertFalse(version.isEmpty(), "There should be some version string");
53 @Test public void testComparePomDepsVersions() throws Exception {
54 final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
55 URL r = l.getResource("archetype-resources/pom.xml");
56 assertNotNull(r, "Archetype pom found");
58 final XPathFactory fact = XPathFactory.newInstance();
59 XPathExpression xp2 = fact.newXPath().compile(
60 "//properties/net.java.html.version/text()"
63 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
64 String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
66 int snapshot = arch.indexOf("-SNAPSHOT");
68 arch = arch.substring(0, snapshot);
71 assertTrue(arch.matches("[0-9\\.]+"), "net.java.html.json version seems valid: " + arch);
74 @Test public void testCheckLauncher() throws Exception {
75 final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
76 URL r = l.getResource("archetype-resources/pom.xml");
77 assertNotNull(r, "Archetype pom found");
79 final XPathFactory fact = XPathFactory.newInstance();
80 XPathExpression xp2 = fact.newXPath().compile(
81 "//properties/bck2brwsr.launcher.version/text()"
84 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
85 String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
87 assertEquals(arch, version, "launcher dependency is on more recent version");
90 @Test public void testCheckBck2Brwsr() throws Exception {
91 final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
92 URL r = l.getResource("archetype-resources/pom.xml");
93 assertNotNull(r, "Archetype pom found");
95 final XPathFactory fact = XPathFactory.newInstance();
96 XPathExpression xp2 = fact.newXPath().compile(
97 "//properties/bck2brwsr.version/text()"
100 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
101 String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
103 assertEquals(arch, version, "bck2brwsr dependency is on more recent version");
106 @Test public void testNbActions() throws Exception {
107 final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
108 URL r = l.getResource("archetype-resources/nbactions.xml");
109 assertNotNull(r, "Archetype nb file found");
111 final XPathFactory fact = XPathFactory.newInstance();
112 XPathExpression xp2 = fact.newXPath().compile(
116 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
117 NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
119 for (int i = 0; i < goals.getLength(); i++) {
120 String s = goals.item(i).getTextContent();
121 if (s.contains("apidesign")) {
122 assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
127 static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
128 final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
129 URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/knockout4j-archetype/pom.xml");
130 assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
132 final XPathFactory fact = XPathFactory.newInstance();
133 fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
135 XPathExpression xp = fact.newXPath().compile("project/version/text()");
137 Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
138 return xp.evaluate(dom);