rt/mojo/src/test/java/org/apidesign/bck2brwsr/mojo/ArchetypeVersionTest.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Thu, 07 Mar 2013 22:35:15 +0100
changeset 817 d87558f94d92
child 823 1e9d34a337f2
permissions -rw-r--r--
Making sure the archetype always uses current version of bck2brwsr
jaroslav@817
     1
/**
jaroslav@817
     2
 * Back 2 Browser Bytecode Translator
jaroslav@817
     3
 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
jaroslav@817
     4
 *
jaroslav@817
     5
 * This program is free software: you can redistribute it and/or modify
jaroslav@817
     6
 * it under the terms of the GNU General Public License as published by
jaroslav@817
     7
 * the Free Software Foundation, version 2 of the License.
jaroslav@817
     8
 *
jaroslav@817
     9
 * This program is distributed in the hope that it will be useful,
jaroslav@817
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
jaroslav@817
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
jaroslav@817
    12
 * GNU General Public License for more details.
jaroslav@817
    13
 *
jaroslav@817
    14
 * You should have received a copy of the GNU General Public License
jaroslav@817
    15
 * along with this program. Look for COPYING file in the top folder.
jaroslav@817
    16
 * If not, see http://opensource.org/licenses/GPL-2.0.
jaroslav@817
    17
 */
jaroslav@817
    18
package org.apidesign.bck2brwsr.mojo;
jaroslav@817
    19
jaroslav@817
    20
import java.net.URL;
jaroslav@817
    21
import javax.xml.XMLConstants;
jaroslav@817
    22
import javax.xml.parsers.DocumentBuilderFactory;
jaroslav@817
    23
import javax.xml.xpath.XPathConstants;
jaroslav@817
    24
import javax.xml.xpath.XPathExpression;
jaroslav@817
    25
import javax.xml.xpath.XPathFactory;
jaroslav@817
    26
import org.testng.annotations.Test;
jaroslav@817
    27
import org.xml.sax.InputSource;
jaroslav@817
    28
import static org.testng.Assert.*;
jaroslav@817
    29
import org.w3c.dom.Document;
jaroslav@817
    30
import org.w3c.dom.NodeList;
jaroslav@817
    31
jaroslav@817
    32
/**
jaroslav@817
    33
 *
jaroslav@817
    34
 * @author Jaroslav Tulach <jtulach@netbeans.org>
jaroslav@817
    35
 */
jaroslav@817
    36
public class ArchetypeVersionTest {
jaroslav@817
    37
    
jaroslav@817
    38
    public ArchetypeVersionTest() {
jaroslav@817
    39
    }
jaroslav@817
    40
jaroslav@817
    41
    @Test public void testCompareOwnAndArchtetypeVersion() throws Exception {
jaroslav@817
    42
        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
jaroslav@817
    43
        URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/mojo/plugin-help.xml");
jaroslav@817
    44
        assertNotNull(u, "Own pom found");
jaroslav@817
    45
        
jaroslav@817
    46
        final XPathFactory fact = XPathFactory.newInstance();
jaroslav@817
    47
        fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
jaroslav@817
    48
        
jaroslav@817
    49
        XPathExpression xp = fact.newXPath().compile("plugin/version/text()");
jaroslav@817
    50
        String version = xp.evaluate(new InputSource(u.openStream()));
jaroslav@817
    51
        
jaroslav@817
    52
        assertFalse(version.isEmpty(), "There should be some version string");
jaroslav@817
    53
        
jaroslav@817
    54
        URL r = l.getResource("archetype-resources/pom.xml");
jaroslav@817
    55
        assertNotNull(r, "Archetype pom found");
jaroslav@817
    56
        
jaroslav@817
    57
        XPathExpression xp2 = fact.newXPath().compile(
jaroslav@817
    58
            "//version[../groupId/text() = 'org.apidesign.bck2brwsr']/text()"
jaroslav@817
    59
        );
jaroslav@817
    60
        
jaroslav@817
    61
        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
jaroslav@817
    62
        NodeList arch = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
jaroslav@817
    63
jaroslav@817
    64
        if (arch.getLength() < 3) {
jaroslav@817
    65
            fail("There should be at least three dependencies to bck2brwsr APIs: " + arch.getLength());
jaroslav@817
    66
        }
jaroslav@817
    67
        
jaroslav@817
    68
        for (int i = 0; i < arch.getLength(); i++) {
jaroslav@817
    69
            assertEquals(arch.item(i).getTextContent(), version, i + "th dependency needs to be on latest version of bck2brwsr");
jaroslav@817
    70
        }
jaroslav@817
    71
    }
jaroslav@817
    72
}