jaroslav@1201
|
1 |
/**
|
jaroslav@1227
|
2 |
* Back 2 Browser Bytecode Translator
|
jaroslav@1227
|
3 |
* Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
|
jaroslav@1201
|
4 |
*
|
jaroslav@1201
|
5 |
* This program is free software: you can redistribute it and/or modify
|
jaroslav@1201
|
6 |
* it under the terms of the GNU General Public License as published by
|
jaroslav@1201
|
7 |
* the Free Software Foundation, version 2 of the License.
|
jaroslav@1201
|
8 |
*
|
jaroslav@1201
|
9 |
* This program is distributed in the hope that it will be useful,
|
jaroslav@1201
|
10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
jaroslav@1201
|
11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
jaroslav@1227
|
12 |
* GNU General Public License for more details.
|
jaroslav@1201
|
13 |
*
|
jaroslav@1201
|
14 |
* You should have received a copy of the GNU General Public License
|
jaroslav@1201
|
15 |
* along with this program. Look for COPYING file in the top folder.
|
jaroslav@1227
|
16 |
* If not, see http://opensource.org/licenses/GPL-2.0.
|
jaroslav@1201
|
17 |
*/
|
jaroslav@1228
|
18 |
package org.apidesign.bck2brwsr.ko.archetype.test;
|
jaroslav@1201
|
19 |
|
jaroslav@1202
|
20 |
import java.io.IOException;
|
jaroslav@1201
|
21 |
import java.net.URL;
|
jaroslav@1201
|
22 |
import javax.xml.XMLConstants;
|
jaroslav@1201
|
23 |
import javax.xml.parsers.DocumentBuilderFactory;
|
jaroslav@1202
|
24 |
import javax.xml.parsers.ParserConfigurationException;
|
jaroslav@1201
|
25 |
import javax.xml.xpath.XPathConstants;
|
jaroslav@1201
|
26 |
import javax.xml.xpath.XPathExpression;
|
jaroslav@1202
|
27 |
import javax.xml.xpath.XPathExpressionException;
|
jaroslav@1201
|
28 |
import javax.xml.xpath.XPathFactory;
|
jaroslav@1202
|
29 |
import javax.xml.xpath.XPathFactoryConfigurationException;
|
jaroslav@1201
|
30 |
import org.testng.annotations.Test;
|
jaroslav@1201
|
31 |
import static org.testng.Assert.*;
|
jaroslav@1201
|
32 |
import org.testng.annotations.BeforeClass;
|
jaroslav@1201
|
33 |
import org.w3c.dom.Document;
|
jaroslav@1201
|
34 |
import org.w3c.dom.NodeList;
|
jaroslav@1202
|
35 |
import org.xml.sax.SAXException;
|
jaroslav@1201
|
36 |
|
jaroslav@1201
|
37 |
/**
|
jaroslav@1201
|
38 |
*
|
jaroslav@1201
|
39 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@1201
|
40 |
*/
|
jaroslav@1201
|
41 |
public class ArchetypeVersionTest {
|
jaroslav@1201
|
42 |
private String version;
|
jaroslav@1201
|
43 |
|
jaroslav@1201
|
44 |
public ArchetypeVersionTest() {
|
jaroslav@1201
|
45 |
}
|
jaroslav@1201
|
46 |
|
jaroslav@1201
|
47 |
@BeforeClass public void readCurrentVersion() throws Exception {
|
jaroslav@1202
|
48 |
version = findCurrentVersion();
|
jaroslav@1201
|
49 |
assertFalse(version.isEmpty(), "There should be some version string");
|
jaroslav@1201
|
50 |
}
|
jaroslav@1201
|
51 |
|
jaroslav@1201
|
52 |
|
jaroslav@1201
|
53 |
@Test public void testComparePomDepsVersions() throws Exception {
|
jaroslav@1201
|
54 |
final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
|
jaroslav@1201
|
55 |
URL r = l.getResource("archetype-resources/pom.xml");
|
jaroslav@1201
|
56 |
assertNotNull(r, "Archetype pom found");
|
jaroslav@1201
|
57 |
|
jaroslav@1201
|
58 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@1201
|
59 |
XPathExpression xp2 = fact.newXPath().compile(
|
jaroslav@1201
|
60 |
"//properties/net.java.html.version/text()"
|
jaroslav@1201
|
61 |
);
|
jaroslav@1201
|
62 |
|
jaroslav@1201
|
63 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
|
jaroslav@1201
|
64 |
String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
|
jaroslav@1236
|
65 |
|
jaroslav@1236
|
66 |
int snapshot = arch.indexOf("-SNAPSHOT");
|
jaroslav@1261
|
67 |
if (snapshot >= 0) {
|
jaroslav@1261
|
68 |
arch = arch.substring(0, snapshot);
|
jaroslav@1261
|
69 |
}
|
jaroslav@1201
|
70 |
|
jaroslav@1236
|
71 |
assertTrue(arch.matches("[0-9\\.]+"), "net.java.html.json version seems valid: " + arch);
|
jaroslav@1201
|
72 |
}
|
jaroslav@1201
|
73 |
|
jaroslav@1210
|
74 |
@Test public void testCheckLauncher() throws Exception {
|
jaroslav@1210
|
75 |
final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
|
jaroslav@1210
|
76 |
URL r = l.getResource("archetype-resources/pom.xml");
|
jaroslav@1210
|
77 |
assertNotNull(r, "Archetype pom found");
|
jaroslav@1210
|
78 |
|
jaroslav@1210
|
79 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@1210
|
80 |
XPathExpression xp2 = fact.newXPath().compile(
|
jaroslav@1210
|
81 |
"//properties/bck2brwsr.launcher.version/text()"
|
jaroslav@1210
|
82 |
);
|
jaroslav@1210
|
83 |
|
jaroslav@1210
|
84 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
|
jaroslav@1210
|
85 |
String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
|
jaroslav@1210
|
86 |
|
jaroslav@1236
|
87 |
assertEquals(arch, version, "launcher dependency is on more recent version");
|
jaroslav@1210
|
88 |
}
|
jaroslav@1210
|
89 |
|
jaroslav@1210
|
90 |
@Test public void testCheckBck2Brwsr() throws Exception {
|
jaroslav@1210
|
91 |
final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
|
jaroslav@1210
|
92 |
URL r = l.getResource("archetype-resources/pom.xml");
|
jaroslav@1210
|
93 |
assertNotNull(r, "Archetype pom found");
|
jaroslav@1210
|
94 |
|
jaroslav@1210
|
95 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@1210
|
96 |
XPathExpression xp2 = fact.newXPath().compile(
|
jaroslav@1210
|
97 |
"//properties/bck2brwsr.version/text()"
|
jaroslav@1210
|
98 |
);
|
jaroslav@1210
|
99 |
|
jaroslav@1210
|
100 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
|
jaroslav@1210
|
101 |
String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
|
jaroslav@1210
|
102 |
|
jaroslav@1236
|
103 |
assertEquals(arch, version, "bck2brwsr dependency is on more recent version");
|
jaroslav@1210
|
104 |
}
|
jaroslav@1210
|
105 |
|
jaroslav@1201
|
106 |
@Test public void testNbActions() throws Exception {
|
jaroslav@1201
|
107 |
final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
|
jaroslav@1201
|
108 |
URL r = l.getResource("archetype-resources/nbactions.xml");
|
jaroslav@1201
|
109 |
assertNotNull(r, "Archetype nb file found");
|
jaroslav@1201
|
110 |
|
jaroslav@1201
|
111 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@1201
|
112 |
XPathExpression xp2 = fact.newXPath().compile(
|
jaroslav@1201
|
113 |
"//goal/text()"
|
jaroslav@1201
|
114 |
);
|
jaroslav@1201
|
115 |
|
jaroslav@1201
|
116 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
|
jaroslav@1201
|
117 |
NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
|
jaroslav@1201
|
118 |
|
jaroslav@1201
|
119 |
for (int i = 0; i < goals.getLength(); i++) {
|
jaroslav@1201
|
120 |
String s = goals.item(i).getTextContent();
|
jaroslav@1201
|
121 |
if (s.contains("apidesign")) {
|
jaroslav@1201
|
122 |
assertFalse(s.matches(".*apidesign.*[0-9].*"), "No numbers: " + s);
|
jaroslav@1201
|
123 |
}
|
jaroslav@1201
|
124 |
}
|
jaroslav@1201
|
125 |
}
|
jaroslav@1202
|
126 |
|
jaroslav@1202
|
127 |
static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
|
jaroslav@1202
|
128 |
final ClassLoader l = ArchetypeVersionTest.class.getClassLoader();
|
jaroslav@1236
|
129 |
URL u = l.getResource("META-INF/maven/org.apidesign.bck2brwsr/knockout4j-archetype/pom.xml");
|
jaroslav@1202
|
130 |
assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
|
jaroslav@1202
|
131 |
|
jaroslav@1202
|
132 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@1202
|
133 |
fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
jaroslav@1202
|
134 |
|
jaroslav@1202
|
135 |
XPathExpression xp = fact.newXPath().compile("project/version/text()");
|
jaroslav@1202
|
136 |
|
jaroslav@1202
|
137 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
|
jaroslav@1202
|
138 |
return xp.evaluate(dom);
|
jaroslav@1202
|
139 |
}
|
jaroslav@1201
|
140 |
}
|