rt/archetype/src/test/java/org/apidesign/bck2brwsr/archetype/ArchetypeVersionTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 18 Apr 2013 12:31:31 +0200
changeset 1008 ad7b9ae807a1
parent 870 448bed1f6d5a
child 1026 e18338d48ef5
permissions -rw-r--r--
Update the archetype to use 0.7 snapshot
     1 /**
     2  * Back 2 Browser Bytecode Translator
     3  * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
     4  *
     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.
     8  *
     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.
    13  *
    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.
    17  */
    18 package org.apidesign.bck2brwsr.archetype;
    19 
    20 import java.net.URL;
    21 import javax.xml.XMLConstants;
    22 import javax.xml.parsers.DocumentBuilderFactory;
    23 import javax.xml.xpath.XPathConstants;
    24 import javax.xml.xpath.XPathExpression;
    25 import javax.xml.xpath.XPathFactory;
    26 import org.testng.annotations.Test;
    27 import static org.testng.Assert.*;
    28 import org.testng.annotations.BeforeClass;
    29 import org.w3c.dom.Document;
    30 import org.w3c.dom.NodeList;
    31 
    32 /**
    33  *
    34  * @author Jaroslav Tulach <jtulach@netbeans.org>
    35  */
    36 public class ArchetypeVersionTest {
    37     private String version;
    38     
    39     public ArchetypeVersionTest() {
    40     }
    41     
    42     @BeforeClass public void readCurrentVersion() throws Exception {
    43         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    44         URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/bck2brwsr-archetype-html-sample/pom.xml");
    45         assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
    46 
    47         final XPathFactory fact = XPathFactory.newInstance();
    48         fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    49 
    50         XPathExpression xp = fact.newXPath().compile("project/version/text()");
    51         
    52         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
    53         version = xp.evaluate(dom);
    54 
    55         assertFalse(version.isEmpty(), "There should be some version string");
    56     }
    57     
    58 
    59     @Test public void testComparePomDepsVersions() throws Exception {
    60         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    61         URL r = l.getResource("archetype-resources/pom.xml");
    62         assertNotNull(r, "Archetype pom found");
    63         
    64         final XPathFactory fact = XPathFactory.newInstance();
    65         XPathExpression xp2 = fact.newXPath().compile(
    66             "//version[../groupId/text() = 'org.apidesign.bck2brwsr']/text()"
    67         );
    68         
    69         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    70         NodeList arch = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
    71 
    72         if (arch.getLength() < 3) {
    73             fail("There should be at least three dependencies to bck2brwsr APIs: " + arch.getLength());
    74         }
    75         
    76         for (int i = 0; i < arch.getLength(); i++) {
    77             assertEquals(arch.item(i).getTextContent(), version, i + "th dependency needs to be on latest version of bck2brwsr");
    78         }
    79     }
    80     
    81     @Test public void testNbActions() throws Exception {
    82         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    83         URL r = l.getResource("archetype-resources/nbactions.xml");
    84         assertNotNull(r, "Archetype nb file found");
    85         
    86         final XPathFactory fact = XPathFactory.newInstance();
    87         XPathExpression xp2 = fact.newXPath().compile(
    88             "//goal/text()"
    89         );
    90         
    91         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    92         NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
    93         
    94         for (int i = 0; i < goals.getLength(); i++) {
    95             String s = goals.item(i).getTextContent();
    96             if (s.contains("bck2brwsr")) {
    97                 String[] arr = s.split(":");
    98                 assertEquals(arr.length, 4, "Three :");
    99                 assertEquals(arr[2], version, "Proper version is used");
   100             }
   101         }
   102     }
   103 }