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