jaroslav@1201: /** jaroslav@1227: * Back 2 Browser Bytecode Translator jaroslav@1227: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1201: * jaroslav@1201: * This program is free software: you can redistribute it and/or modify jaroslav@1201: * it under the terms of the GNU General Public License as published by jaroslav@1201: * the Free Software Foundation, version 2 of the License. jaroslav@1201: * jaroslav@1201: * This program is distributed in the hope that it will be useful, jaroslav@1201: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1201: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1227: * GNU General Public License for more details. jaroslav@1201: * jaroslav@1201: * You should have received a copy of the GNU General Public License jaroslav@1201: * along with this program. Look for COPYING file in the top folder. jaroslav@1227: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1201: */ jaroslav@1202: package org.apidesign.html.archetype.test; jaroslav@1201: jaroslav@1202: import java.io.IOException; jaroslav@1201: import java.net.URL; jaroslav@1201: import javax.xml.XMLConstants; jaroslav@1201: import javax.xml.parsers.DocumentBuilderFactory; jaroslav@1202: import javax.xml.parsers.ParserConfigurationException; jaroslav@1201: import javax.xml.xpath.XPathConstants; jaroslav@1201: import javax.xml.xpath.XPathExpression; jaroslav@1202: import javax.xml.xpath.XPathExpressionException; jaroslav@1201: import javax.xml.xpath.XPathFactory; jaroslav@1202: import javax.xml.xpath.XPathFactoryConfigurationException; jaroslav@1201: import org.testng.annotations.Test; jaroslav@1201: import static org.testng.Assert.*; jaroslav@1201: import org.testng.annotations.BeforeClass; jaroslav@1201: import org.w3c.dom.Document; jaroslav@1201: import org.w3c.dom.NodeList; jaroslav@1202: import org.xml.sax.SAXException; jaroslav@1201: jaroslav@1201: /** jaroslav@1201: * jaroslav@1201: * @author Jaroslav Tulach jaroslav@1201: */ jaroslav@1201: public class ArchetypeVersionTest { jaroslav@1201: private String version; jaroslav@1201: jaroslav@1201: public ArchetypeVersionTest() { jaroslav@1201: } jaroslav@1201: jaroslav@1201: @BeforeClass public void readCurrentVersion() throws Exception { jaroslav@1202: version = findCurrentVersion(); jaroslav@1201: assertFalse(version.isEmpty(), "There should be some version string"); jaroslav@1201: } jaroslav@1201: jaroslav@1201: jaroslav@1201: @Test public void testComparePomDepsVersions() throws Exception { jaroslav@1201: final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); jaroslav@1201: URL r = l.getResource("archetype-resources/pom.xml"); jaroslav@1201: assertNotNull(r, "Archetype pom found"); jaroslav@1201: jaroslav@1201: final XPathFactory fact = XPathFactory.newInstance(); jaroslav@1201: XPathExpression xp2 = fact.newXPath().compile( jaroslav@1201: "//properties/net.java.html.version/text()" jaroslav@1201: ); jaroslav@1201: jaroslav@1201: Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); jaroslav@1201: String arch = (String) xp2.evaluate(dom, XPathConstants.STRING); jaroslav@1201: jaroslav@1201: assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version"); jaroslav@1201: } jaroslav@1201: jaroslav@1210: @Test public void testCheckLauncher() throws Exception { jaroslav@1210: final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); jaroslav@1210: URL r = l.getResource("archetype-resources/pom.xml"); jaroslav@1210: assertNotNull(r, "Archetype pom found"); jaroslav@1210: jaroslav@1210: final XPathFactory fact = XPathFactory.newInstance(); jaroslav@1210: XPathExpression xp2 = fact.newXPath().compile( jaroslav@1210: "//properties/bck2brwsr.launcher.version/text()" jaroslav@1210: ); jaroslav@1210: jaroslav@1210: Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); jaroslav@1210: String arch = (String) xp2.evaluate(dom, XPathConstants.STRING); jaroslav@1210: jaroslav@1210: jaroslav@1210: assertTrue(arch.matches("[0-9\\.]+"), "launcher version seems valid: " + arch); jaroslav@1210: } jaroslav@1210: jaroslav@1210: @Test public void testCheckBck2Brwsr() throws Exception { jaroslav@1210: final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); jaroslav@1210: URL r = l.getResource("archetype-resources/pom.xml"); jaroslav@1210: assertNotNull(r, "Archetype pom found"); jaroslav@1210: jaroslav@1210: final XPathFactory fact = XPathFactory.newInstance(); jaroslav@1210: XPathExpression xp2 = fact.newXPath().compile( jaroslav@1210: "//properties/bck2brwsr.version/text()" jaroslav@1210: ); jaroslav@1210: jaroslav@1210: Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); jaroslav@1210: String arch = (String) xp2.evaluate(dom, XPathConstants.STRING); jaroslav@1210: jaroslav@1210: assertTrue(arch.matches("[0-9\\.]+"), "bck2brwsr version seems valid: " + arch); jaroslav@1210: } jaroslav@1210: jaroslav@1201: @Test public void testNbActions() throws Exception { jaroslav@1201: final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); jaroslav@1201: URL r = l.getResource("archetype-resources/nbactions.xml"); jaroslav@1201: assertNotNull(r, "Archetype nb file found"); jaroslav@1201: jaroslav@1201: final XPathFactory fact = XPathFactory.newInstance(); jaroslav@1201: XPathExpression xp2 = fact.newXPath().compile( jaroslav@1201: "//goal/text()" jaroslav@1201: ); jaroslav@1201: jaroslav@1201: Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream()); jaroslav@1201: NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET); jaroslav@1201: jaroslav@1201: for (int i = 0; i < goals.getLength(); i++) { jaroslav@1201: String s = goals.item(i).getTextContent(); jaroslav@1201: if (s.contains("apidesign")) { jaroslav@1201: assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s); jaroslav@1201: } jaroslav@1201: } jaroslav@1201: } jaroslav@1202: jaroslav@1202: static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException { jaroslav@1202: final ClassLoader l = ArchetypeVersionTest.class.getClassLoader(); jaroslav@1202: URL u = l.getResource("META-INF/maven/org.apidesign.html/knockout4j-archetype/pom.xml"); jaroslav@1202: assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path")); jaroslav@1202: jaroslav@1202: final XPathFactory fact = XPathFactory.newInstance(); jaroslav@1202: fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); jaroslav@1202: jaroslav@1202: XPathExpression xp = fact.newXPath().compile("project/version/text()"); jaroslav@1202: jaroslav@1202: Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream()); jaroslav@1202: return xp.evaluate(dom); jaroslav@1202: } jaroslav@1201: }