ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java
1.1 --- a/ko/archetype-test/src/test/java/org/apidesign/bck2brwsr/ko/archetype/test/ArchetypeVersionTest.java Thu May 15 11:38:27 2014 +0200
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,140 +0,0 @@
1.4 -/**
1.5 - * Back 2 Browser Bytecode Translator
1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 - *
1.8 - * This program is free software: you can redistribute it and/or modify
1.9 - * it under the terms of the GNU General Public License as published by
1.10 - * the Free Software Foundation, version 2 of the License.
1.11 - *
1.12 - * This program is distributed in the hope that it will be useful,
1.13 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.14 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.15 - * GNU General Public License for more details.
1.16 - *
1.17 - * You should have received a copy of the GNU General Public License
1.18 - * along with this program. Look for COPYING file in the top folder.
1.19 - * If not, see http://opensource.org/licenses/GPL-2.0.
1.20 - */
1.21 -package org.apidesign.bck2brwsr.ko.archetype.test;
1.22 -
1.23 -import java.io.IOException;
1.24 -import java.net.URL;
1.25 -import javax.xml.XMLConstants;
1.26 -import javax.xml.parsers.DocumentBuilderFactory;
1.27 -import javax.xml.parsers.ParserConfigurationException;
1.28 -import javax.xml.xpath.XPathConstants;
1.29 -import javax.xml.xpath.XPathExpression;
1.30 -import javax.xml.xpath.XPathExpressionException;
1.31 -import javax.xml.xpath.XPathFactory;
1.32 -import javax.xml.xpath.XPathFactoryConfigurationException;
1.33 -import org.testng.annotations.Test;
1.34 -import static org.testng.Assert.*;
1.35 -import org.testng.annotations.BeforeClass;
1.36 -import org.w3c.dom.Document;
1.37 -import org.w3c.dom.NodeList;
1.38 -import org.xml.sax.SAXException;
1.39 -
1.40 -/**
1.41 - *
1.42 - * @author Jaroslav Tulach <jtulach@netbeans.org>
1.43 - */
1.44 -public class ArchetypeVersionTest {
1.45 - private String version;
1.46 -
1.47 - public ArchetypeVersionTest() {
1.48 - }
1.49 -
1.50 - @BeforeClass public void readCurrentVersion() throws Exception {
1.51 - version = findCurrentVersion();
1.52 - assertFalse(version.isEmpty(), "There should be some version string");
1.53 - }
1.54 -
1.55 -
1.56 - @Test public void testComparePomDepsVersions() throws Exception {
1.57 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.58 - URL r = l.getResource("archetype-resources/pom.xml");
1.59 - assertNotNull(r, "Archetype pom found");
1.60 -
1.61 - final XPathFactory fact = XPathFactory.newInstance();
1.62 - XPathExpression xp2 = fact.newXPath().compile(
1.63 - "//properties/net.java.html.version/text()"
1.64 - );
1.65 -
1.66 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
1.67 - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
1.68 -
1.69 - int snapshot = arch.indexOf("-SNAPSHOT");
1.70 - if (snapshot >= 0) {
1.71 - arch = arch.substring(0, snapshot);
1.72 - }
1.73 -
1.74 - assertTrue(arch.matches("[0-9\\.]+"), "net.java.html.json version seems valid: " + arch);
1.75 - }
1.76 -
1.77 - @Test public void testCheckLauncher() throws Exception {
1.78 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.79 - URL r = l.getResource("archetype-resources/pom.xml");
1.80 - assertNotNull(r, "Archetype pom found");
1.81 -
1.82 - final XPathFactory fact = XPathFactory.newInstance();
1.83 - XPathExpression xp2 = fact.newXPath().compile(
1.84 - "//properties/bck2brwsr.launcher.version/text()"
1.85 - );
1.86 -
1.87 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
1.88 - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
1.89 -
1.90 - assertEquals(arch, version, "launcher dependency is on more recent version");
1.91 - }
1.92 -
1.93 - @Test public void testCheckBck2Brwsr() throws Exception {
1.94 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.95 - URL r = l.getResource("archetype-resources/pom.xml");
1.96 - assertNotNull(r, "Archetype pom found");
1.97 -
1.98 - final XPathFactory fact = XPathFactory.newInstance();
1.99 - XPathExpression xp2 = fact.newXPath().compile(
1.100 - "//properties/bck2brwsr.version/text()"
1.101 - );
1.102 -
1.103 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
1.104 - String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
1.105 -
1.106 - assertEquals(arch, version, "bck2brwsr dependency is on more recent version");
1.107 - }
1.108 -
1.109 - @Test public void testNbActions() throws Exception {
1.110 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.111 - URL r = l.getResource("archetype-resources/nbactions.xml");
1.112 - assertNotNull(r, "Archetype nb file found");
1.113 -
1.114 - final XPathFactory fact = XPathFactory.newInstance();
1.115 - XPathExpression xp2 = fact.newXPath().compile(
1.116 - "//goal/text()"
1.117 - );
1.118 -
1.119 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
1.120 - NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
1.121 -
1.122 - for (int i = 0; i < goals.getLength(); i++) {
1.123 - String s = goals.item(i).getTextContent();
1.124 - if (s.contains("apidesign")) {
1.125 - assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
1.126 - }
1.127 - }
1.128 - }
1.129 -
1.130 - static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
1.131 - final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.132 - URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/knockout4j-archetype/pom.xml");
1.133 - assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
1.134 -
1.135 - final XPathFactory fact = XPathFactory.newInstance();
1.136 - fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
1.137 -
1.138 - XPathExpression xp = fact.newXPath().compile("project/version/text()");
1.139 -
1.140 - Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
1.141 - return xp.evaluate(dom);
1.142 - }
1.143 -}