rt/mojo/src/test/java/org/apidesign/bck2brwsr/mojo/ArchetypeVersionTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 08 Mar 2013 00:42:02 +0100
changeset 823 1e9d34a337f2
parent 817 d87558f94d92
permissions -rw-r--r--
Verify nbactions.xml have the right version. Update everything to 0.5-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.mojo;
    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 org.xml.sax.InputSource;
    28 import static org.testng.Assert.*;
    29 import org.testng.annotations.BeforeClass;
    30 import org.w3c.dom.Document;
    31 import org.w3c.dom.NodeList;
    32 
    33 /**
    34  *
    35  * @author Jaroslav Tulach <jtulach@netbeans.org>
    36  */
    37 public class ArchetypeVersionTest {
    38     private String version;
    39     
    40     public ArchetypeVersionTest() {
    41     }
    42     
    43     @BeforeClass public void readCurrentVersion() throws Exception {
    44         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    45         URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/mojo/plugin-help.xml");
    46         assertNotNull(u, "Own pom found");
    47 
    48         final XPathFactory fact = XPathFactory.newInstance();
    49         fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
    50 
    51         XPathExpression xp = fact.newXPath().compile("plugin/version/text()");
    52         version = xp.evaluate(new InputSource(u.openStream()));
    53 
    54         assertFalse(version.isEmpty(), "There should be some version string");
    55     }
    56     
    57 
    58     @Test public void testComparePomDepsVersions() throws Exception {
    59         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    60         URL r = l.getResource("archetype-resources/pom.xml");
    61         assertNotNull(r, "Archetype pom found");
    62         
    63         final XPathFactory fact = XPathFactory.newInstance();
    64         XPathExpression xp2 = fact.newXPath().compile(
    65             "//version[../groupId/text() = 'org.apidesign.bck2brwsr']/text()"
    66         );
    67         
    68         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    69         NodeList arch = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
    70 
    71         if (arch.getLength() < 3) {
    72             fail("There should be at least three dependencies to bck2brwsr APIs: " + arch.getLength());
    73         }
    74         
    75         for (int i = 0; i < arch.getLength(); i++) {
    76             assertEquals(arch.item(i).getTextContent(), version, i + "th dependency needs to be on latest version of bck2brwsr");
    77         }
    78     }
    79     
    80     @Test public void testNbActions() throws Exception {
    81         final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
    82         URL r = l.getResource("archetype-resources/nbactions.xml");
    83         assertNotNull(r, "Archetype nb file found");
    84         
    85         final XPathFactory fact = XPathFactory.newInstance();
    86         XPathExpression xp2 = fact.newXPath().compile(
    87             "//goal/text()"
    88         );
    89         
    90         Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
    91         NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
    92         
    93         for (int i = 0; i < goals.getLength(); i++) {
    94             String s = goals.item(i).getTextContent();
    95             if (s.contains("bck2brwsr")) {
    96                 String[] arr = s.split(":");
    97                 assertEquals(arr.length, 4, "Three :");
    98                 assertEquals(arr[2], version, "Proper version is used");
    99             }
   100         }
   101     }
   102 }