1.1 --- a/rt/mojo/src/test/java/org/apidesign/bck2brwsr/mojo/ArchetypeVersionTest.java Thu Mar 07 22:35:15 2013 +0100
1.2 +++ b/rt/mojo/src/test/java/org/apidesign/bck2brwsr/mojo/ArchetypeVersionTest.java Mon Mar 25 13:29:42 2013 +0100
1.3 @@ -26,6 +26,7 @@
1.4 import org.testng.annotations.Test;
1.5 import org.xml.sax.InputSource;
1.6 import static org.testng.Assert.*;
1.7 +import org.testng.annotations.BeforeClass;
1.8 import org.w3c.dom.Document;
1.9 import org.w3c.dom.NodeList;
1.10
1.11 @@ -34,26 +35,32 @@
1.12 * @author Jaroslav Tulach <jtulach@netbeans.org>
1.13 */
1.14 public class ArchetypeVersionTest {
1.15 + private String version;
1.16
1.17 public ArchetypeVersionTest() {
1.18 }
1.19 -
1.20 - @Test public void testCompareOwnAndArchtetypeVersion() throws Exception {
1.21 +
1.22 + @BeforeClass public void readCurrentVersion() throws Exception {
1.23 final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.24 URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/mojo/plugin-help.xml");
1.25 assertNotNull(u, "Own pom found");
1.26 -
1.27 +
1.28 final XPathFactory fact = XPathFactory.newInstance();
1.29 fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
1.30 -
1.31 +
1.32 XPathExpression xp = fact.newXPath().compile("plugin/version/text()");
1.33 - String version = xp.evaluate(new InputSource(u.openStream()));
1.34 -
1.35 + version = xp.evaluate(new InputSource(u.openStream()));
1.36 +
1.37 assertFalse(version.isEmpty(), "There should be some version string");
1.38 -
1.39 + }
1.40 +
1.41 +
1.42 + @Test public void testComparePomDepsVersions() throws Exception {
1.43 + final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.44 URL r = l.getResource("archetype-resources/pom.xml");
1.45 assertNotNull(r, "Archetype pom found");
1.46
1.47 + final XPathFactory fact = XPathFactory.newInstance();
1.48 XPathExpression xp2 = fact.newXPath().compile(
1.49 "//version[../groupId/text() = 'org.apidesign.bck2brwsr']/text()"
1.50 );
1.51 @@ -69,4 +76,27 @@
1.52 assertEquals(arch.item(i).getTextContent(), version, i + "th dependency needs to be on latest version of bck2brwsr");
1.53 }
1.54 }
1.55 +
1.56 + @Test public void testNbActions() throws Exception {
1.57 + final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
1.58 + URL r = l.getResource("archetype-resources/nbactions.xml");
1.59 + assertNotNull(r, "Archetype nb file found");
1.60 +
1.61 + final XPathFactory fact = XPathFactory.newInstance();
1.62 + XPathExpression xp2 = fact.newXPath().compile(
1.63 + "//goal/text()"
1.64 + );
1.65 +
1.66 + Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
1.67 + NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
1.68 +
1.69 + for (int i = 0; i < goals.getLength(); i++) {
1.70 + String s = goals.item(i).getTextContent();
1.71 + if (s.contains("bck2brwsr")) {
1.72 + String[] arr = s.split(":");
1.73 + assertEquals(arr.length, 4, "Three :");
1.74 + assertEquals(arr[2], version, "Proper version is used");
1.75 + }
1.76 + }
1.77 + }
1.78 }