ko-archetype-test/src/test/java/org/apidesign/html/archetype/test/ArchetypeVersionTest.java
branchclassloader
changeset 1225 73c0973e8e0a
parent 1224 7189e9abb928
child 1226 e5b5c7af4f7f
     1.1 --- a/ko-archetype-test/src/test/java/org/apidesign/html/archetype/test/ArchetypeVersionTest.java	Mon Jun 24 17:49:27 2013 +0200
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,139 +0,0 @@
     1.4 -/**
     1.5 - * HTML via Java(tm) Language Bindings
     1.6 - * Copyright (C) 2013 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. apidesign.org
    1.16 - * designates this particular file as subject to the
    1.17 - * "Classpath" exception as provided by apidesign.org
    1.18 - * in the License file that accompanied this code.
    1.19 - *
    1.20 - * You should have received a copy of the GNU General Public License
    1.21 - * along with this program. Look for COPYING file in the top folder.
    1.22 - * If not, see http://wiki.apidesign.org/wiki/GPLwithClassPathException
    1.23 - */
    1.24 -package org.apidesign.html.archetype.test;
    1.25 -
    1.26 -import java.io.IOException;
    1.27 -import java.net.URL;
    1.28 -import javax.xml.XMLConstants;
    1.29 -import javax.xml.parsers.DocumentBuilderFactory;
    1.30 -import javax.xml.parsers.ParserConfigurationException;
    1.31 -import javax.xml.xpath.XPathConstants;
    1.32 -import javax.xml.xpath.XPathExpression;
    1.33 -import javax.xml.xpath.XPathExpressionException;
    1.34 -import javax.xml.xpath.XPathFactory;
    1.35 -import javax.xml.xpath.XPathFactoryConfigurationException;
    1.36 -import org.testng.annotations.Test;
    1.37 -import static org.testng.Assert.*;
    1.38 -import org.testng.annotations.BeforeClass;
    1.39 -import org.w3c.dom.Document;
    1.40 -import org.w3c.dom.NodeList;
    1.41 -import org.xml.sax.SAXException;
    1.42 -
    1.43 -/**
    1.44 - *
    1.45 - * @author Jaroslav Tulach <jtulach@netbeans.org>
    1.46 - */
    1.47 -public class ArchetypeVersionTest {
    1.48 -    private String version;
    1.49 -    
    1.50 -    public ArchetypeVersionTest() {
    1.51 -    }
    1.52 -    
    1.53 -    @BeforeClass public void readCurrentVersion() throws Exception {
    1.54 -        version = findCurrentVersion();
    1.55 -        assertFalse(version.isEmpty(), "There should be some version string");
    1.56 -    }
    1.57 -    
    1.58 -
    1.59 -    @Test public void testComparePomDepsVersions() throws Exception {
    1.60 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    1.61 -        URL r = l.getResource("archetype-resources/pom.xml");
    1.62 -        assertNotNull(r, "Archetype pom found");
    1.63 -        
    1.64 -        final XPathFactory fact = XPathFactory.newInstance();
    1.65 -        XPathExpression xp2 = fact.newXPath().compile(
    1.66 -            "//properties/net.java.html.version/text()"
    1.67 -        );
    1.68 -        
    1.69 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    1.70 -        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    1.71 -
    1.72 -        assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
    1.73 -    }
    1.74 -    
    1.75 -    @Test public void testCheckLauncher() throws Exception {
    1.76 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    1.77 -        URL r = l.getResource("archetype-resources/pom.xml");
    1.78 -        assertNotNull(r, "Archetype pom found");
    1.79 -        
    1.80 -        final XPathFactory fact = XPathFactory.newInstance();
    1.81 -        XPathExpression xp2 = fact.newXPath().compile(
    1.82 -            "//properties/bck2brwsr.launcher.version/text()"
    1.83 -        );
    1.84 -        
    1.85 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    1.86 -        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
    1.87 -
    1.88 -        
    1.89 -        assertTrue(arch.matches("[0-9\\.]+"), "launcher version seems valid: " + arch);
    1.90 -    }
    1.91 -    
    1.92 -    @Test public void testCheckBck2Brwsr() throws Exception {
    1.93 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    1.94 -        URL r = l.getResource("archetype-resources/pom.xml");
    1.95 -        assertNotNull(r, "Archetype pom found");
    1.96 -        
    1.97 -        final XPathFactory fact = XPathFactory.newInstance();
    1.98 -        XPathExpression xp2 = fact.newXPath().compile(
    1.99 -            "//properties/bck2brwsr.version/text()"
   1.100 -        );
   1.101 -        
   1.102 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
   1.103 -        String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
   1.104 -        
   1.105 -        assertTrue(arch.matches("[0-9\\.]+"), "bck2brwsr version seems valid: " + arch);
   1.106 -    }
   1.107 -    
   1.108 -    @Test public void testNbActions() throws Exception {
   1.109 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
   1.110 -        URL r = l.getResource("archetype-resources/nbactions.xml");
   1.111 -        assertNotNull(r, "Archetype nb file found");
   1.112 -        
   1.113 -        final XPathFactory fact = XPathFactory.newInstance();
   1.114 -        XPathExpression xp2 = fact.newXPath().compile(
   1.115 -            "//goal/text()"
   1.116 -        );
   1.117 -        
   1.118 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
   1.119 -        NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
   1.120 -        
   1.121 -        for (int i = 0; i < goals.getLength(); i++) {
   1.122 -            String s = goals.item(i).getTextContent();
   1.123 -            if (s.contains("apidesign")) {
   1.124 -                assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
   1.125 -            }
   1.126 -        }
   1.127 -    }
   1.128 -
   1.129 -    static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
   1.130 -        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
   1.131 -        URL u = l.getResource("META-INF/maven/org.apidesign.html/knockout4j-archetype/pom.xml");
   1.132 -        assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
   1.133 -
   1.134 -        final XPathFactory fact = XPathFactory.newInstance();
   1.135 -        fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
   1.136 -
   1.137 -        XPathExpression xp = fact.newXPath().compile("project/version/text()");
   1.138 -        
   1.139 -        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
   1.140 -        return xp.evaluate(dom);
   1.141 -    }
   1.142 -}