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
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@870
    18
package org.apidesign.bck2brwsr.archetype;
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 static org.testng.Assert.*;
jaroslav@823
    28
import org.testng.annotations.BeforeClass;
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@823
    37
    private String version;
jaroslav@817
    38
    
jaroslav@817
    39
    public ArchetypeVersionTest() {
jaroslav@817
    40
    }
jaroslav@823
    41
    
jaroslav@823
    42
    @BeforeClass public void readCurrentVersion() throws Exception {
jaroslav@817
    43
        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
jaroslav@870
    44
        URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/bck2brwsr-archetype-html-sample/pom.xml");
jaroslav@870
    45
        assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
jaroslav@823
    46
jaroslav@817
    47
        final XPathFactory fact = XPathFactory.newInstance();
jaroslav@817
    48
        fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
jaroslav@823
    49
jaroslav@870
    50
        XPathExpression xp = fact.newXPath().compile("project/version/text()");
jaroslav@870
    51
        
jaroslav@870
    52
        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
jaroslav@870
    53
        version = xp.evaluate(dom);
jaroslav@823
    54
jaroslav@817
    55
        assertFalse(version.isEmpty(), "There should be some version string");
jaroslav@823
    56
    }
jaroslav@823
    57
    
jaroslav@823
    58
jaroslav@823
    59
    @Test public void testComparePomDepsVersions() throws Exception {
jaroslav@823
    60
        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
jaroslav@817
    61
        URL r = l.getResource("archetype-resources/pom.xml");
jaroslav@817
    62
        assertNotNull(r, "Archetype pom found");
jaroslav@817
    63
        
jaroslav@823
    64
        final XPathFactory fact = XPathFactory.newInstance();
jaroslav@817
    65
        XPathExpression xp2 = fact.newXPath().compile(
jaroslav@817
    66
            "//version[../groupId/text() = 'org.apidesign.bck2brwsr']/text()"
jaroslav@817
    67
        );
jaroslav@817
    68
        
jaroslav@817
    69
        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
jaroslav@817
    70
        NodeList arch = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
jaroslav@817
    71
jaroslav@817
    72
        if (arch.getLength() < 3) {
jaroslav@817
    73
            fail("There should be at least three dependencies to bck2brwsr APIs: " + arch.getLength());
jaroslav@817
    74
        }
jaroslav@817
    75
        
jaroslav@817
    76
        for (int i = 0; i < arch.getLength(); i++) {
jaroslav@817
    77
            assertEquals(arch.item(i).getTextContent(), version, i + "th dependency needs to be on latest version of bck2brwsr");
jaroslav@817
    78
        }
jaroslav@817
    79
    }
jaroslav@823
    80
    
jaroslav@823
    81
    @Test public void testNbActions() throws Exception {
jaroslav@823
    82
        final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
jaroslav@823
    83
        URL r = l.getResource("archetype-resources/nbactions.xml");
jaroslav@823
    84
        assertNotNull(r, "Archetype nb file found");
jaroslav@823
    85
        
jaroslav@823
    86
        final XPathFactory fact = XPathFactory.newInstance();
jaroslav@823
    87
        XPathExpression xp2 = fact.newXPath().compile(
jaroslav@823
    88
            "//goal/text()"
jaroslav@823
    89
        );
jaroslav@823
    90
        
jaroslav@823
    91
        Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
jaroslav@823
    92
        NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
jaroslav@823
    93
        
jaroslav@823
    94
        for (int i = 0; i < goals.getLength(); i++) {
jaroslav@823
    95
            String s = goals.item(i).getTextContent();
jaroslav@823
    96
            if (s.contains("bck2brwsr")) {
jaroslav@823
    97
                String[] arr = s.split(":");
jaroslav@823
    98
                assertEquals(arr.length, 4, "Three :");
jaroslav@823
    99
                assertEquals(arr[2], version, "Proper version is used");
jaroslav@823
   100
            }
jaroslav@823
   101
        }
jaroslav@823
   102
    }
jaroslav@817
   103
}