jaroslav@478
|
1 |
/**
|
jaroslav@478
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
jaroslav@478
|
3 |
*
|
jaroslav@551
|
4 |
* Copyright 2013-2014 Oracle and/or its affiliates. All rights reserved.
|
jaroslav@478
|
5 |
*
|
jaroslav@478
|
6 |
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
|
jaroslav@478
|
7 |
* Other names may be trademarks of their respective owners.
|
jaroslav@478
|
8 |
*
|
jaroslav@478
|
9 |
* The contents of this file are subject to the terms of either the GNU
|
jaroslav@478
|
10 |
* General Public License Version 2 only ("GPL") or the Common
|
jaroslav@478
|
11 |
* Development and Distribution License("CDDL") (collectively, the
|
jaroslav@478
|
12 |
* "License"). You may not use this file except in compliance with the
|
jaroslav@478
|
13 |
* License. You can obtain a copy of the License at
|
jaroslav@478
|
14 |
* http://www.netbeans.org/cddl-gplv2.html
|
jaroslav@478
|
15 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
|
jaroslav@478
|
16 |
* specific language governing permissions and limitations under the
|
jaroslav@478
|
17 |
* License. When distributing the software, include this License Header
|
jaroslav@478
|
18 |
* Notice in each file and include the License file at
|
jaroslav@478
|
19 |
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
|
jaroslav@478
|
20 |
* particular file as subject to the "Classpath" exception as provided
|
jaroslav@478
|
21 |
* by Oracle in the GPL Version 2 section of the License file that
|
jaroslav@478
|
22 |
* accompanied this code. If applicable, add the following below the
|
jaroslav@478
|
23 |
* License Header, with the fields enclosed by brackets [] replaced by
|
jaroslav@478
|
24 |
* your own identifying information:
|
jaroslav@478
|
25 |
* "Portions Copyrighted [year] [name of copyright owner]"
|
jaroslav@478
|
26 |
*
|
jaroslav@478
|
27 |
* Contributor(s):
|
jaroslav@478
|
28 |
*
|
jaroslav@478
|
29 |
* The Original Software is NetBeans. The Initial Developer of the Original
|
jaroslav@551
|
30 |
* Software is Oracle. Portions Copyright 2013-2014 Oracle. All Rights Reserved.
|
jaroslav@478
|
31 |
*
|
jaroslav@478
|
32 |
* If you wish your version of this file to be governed by only the CDDL
|
jaroslav@478
|
33 |
* or only the GPL Version 2, indicate your decision by adding
|
jaroslav@478
|
34 |
* "[Contributor] elects to include this software in this distribution
|
jaroslav@478
|
35 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a
|
jaroslav@478
|
36 |
* single choice of license, a recipient has the option to distribute
|
jaroslav@478
|
37 |
* your version of this file under either the CDDL, the GPL Version 2 or
|
jaroslav@478
|
38 |
* to extend the choice of license to its licensees as provided above.
|
jaroslav@478
|
39 |
* However, if you add GPL Version 2 code and therefore, elected the GPL
|
jaroslav@478
|
40 |
* Version 2 license, then the option applies only if the new code is
|
jaroslav@478
|
41 |
* made subject to such option by the copyright holder.
|
jaroslav@478
|
42 |
*/
|
jaroslav@478
|
43 |
package org.netbeans.html.archetype.test;
|
jaroslav@478
|
44 |
|
jaroslav@478
|
45 |
import java.io.IOException;
|
jaroslav@478
|
46 |
import java.net.URL;
|
jaroslav@478
|
47 |
import javax.xml.XMLConstants;
|
jaroslav@478
|
48 |
import javax.xml.parsers.DocumentBuilderFactory;
|
jaroslav@478
|
49 |
import javax.xml.parsers.ParserConfigurationException;
|
jaroslav@478
|
50 |
import javax.xml.xpath.XPathConstants;
|
jaroslav@478
|
51 |
import javax.xml.xpath.XPathExpression;
|
jaroslav@478
|
52 |
import javax.xml.xpath.XPathExpressionException;
|
jaroslav@478
|
53 |
import javax.xml.xpath.XPathFactory;
|
jaroslav@478
|
54 |
import javax.xml.xpath.XPathFactoryConfigurationException;
|
jaroslav@478
|
55 |
import org.testng.annotations.Test;
|
jaroslav@478
|
56 |
import static org.testng.Assert.*;
|
jaroslav@478
|
57 |
import org.testng.annotations.BeforeClass;
|
jaroslav@478
|
58 |
import org.w3c.dom.Document;
|
jaroslav@478
|
59 |
import org.w3c.dom.NodeList;
|
jaroslav@478
|
60 |
import org.xml.sax.SAXException;
|
jaroslav@478
|
61 |
|
jaroslav@478
|
62 |
/**
|
jaroslav@478
|
63 |
*
|
jaroslav@478
|
64 |
* @author Jaroslav Tulach <jtulach@netbeans.org>
|
jaroslav@478
|
65 |
*/
|
jaroslav@478
|
66 |
public class ArchetypeVersionIT {
|
jaroslav@478
|
67 |
private String version;
|
jaroslav@478
|
68 |
|
jaroslav@478
|
69 |
public ArchetypeVersionIT() {
|
jaroslav@478
|
70 |
}
|
jaroslav@478
|
71 |
|
jaroslav@478
|
72 |
@BeforeClass public void readCurrentVersion() throws Exception {
|
jaroslav@478
|
73 |
version = findCurrentVersion();
|
jaroslav@478
|
74 |
assertFalse(version.isEmpty(), "There should be some version string");
|
jaroslav@478
|
75 |
}
|
jaroslav@478
|
76 |
|
jaroslav@478
|
77 |
|
jaroslav@478
|
78 |
@Test public void testComparePomDepsVersions() throws Exception {
|
jaroslav@478
|
79 |
final ClassLoader l = ArchetypeVersionIT.class.getClassLoader();
|
jaroslav@478
|
80 |
URL r = l.getResource("archetype-resources/pom.xml");
|
jaroslav@478
|
81 |
assertNotNull(r, "Archetype pom found");
|
jaroslav@478
|
82 |
|
jaroslav@478
|
83 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@478
|
84 |
XPathExpression xp2 = fact.newXPath().compile(
|
jaroslav@478
|
85 |
"//properties/net.java.html.version/text()"
|
jaroslav@478
|
86 |
);
|
jaroslav@478
|
87 |
|
jaroslav@478
|
88 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
|
jaroslav@478
|
89 |
String arch = (String) xp2.evaluate(dom, XPathConstants.STRING);
|
jaroslav@478
|
90 |
|
jaroslav@478
|
91 |
assertEquals(arch, version, "net.java.html.json dependency needs to be on latest version");
|
jaroslav@478
|
92 |
}
|
jaroslav@478
|
93 |
|
jaroslav@478
|
94 |
@Test public void testNbActions() throws Exception {
|
jaroslav@478
|
95 |
final ClassLoader l = ArchetypeVersionIT.class.getClassLoader();
|
jaroslav@478
|
96 |
URL r = l.getResource("archetype-resources/nbactions.xml");
|
jaroslav@478
|
97 |
assertNotNull(r, "Archetype nb file found");
|
jaroslav@478
|
98 |
|
jaroslav@478
|
99 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@478
|
100 |
XPathExpression xp2 = fact.newXPath().compile(
|
jaroslav@478
|
101 |
"//goal/text()"
|
jaroslav@478
|
102 |
);
|
jaroslav@478
|
103 |
|
jaroslav@478
|
104 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(r.openStream());
|
jaroslav@478
|
105 |
NodeList goals = (NodeList) xp2.evaluate(dom, XPathConstants.NODESET);
|
jaroslav@478
|
106 |
|
jaroslav@478
|
107 |
for (int i = 0; i < goals.getLength(); i++) {
|
jaroslav@478
|
108 |
String s = goals.item(i).getTextContent();
|
jaroslav@478
|
109 |
if (s.contains("netbeans")) {
|
jaroslav@478
|
110 |
assertFalse(s.matches(".*netbeans.*[0-9].*"), "No numbers: " + s);
|
jaroslav@478
|
111 |
}
|
jaroslav@478
|
112 |
}
|
jaroslav@478
|
113 |
}
|
jaroslav@478
|
114 |
|
jaroslav@478
|
115 |
static String findCurrentVersion() throws XPathExpressionException, IOException, ParserConfigurationException, SAXException, XPathFactoryConfigurationException {
|
jaroslav@478
|
116 |
final ClassLoader l = ArchetypeVersionIT.class.getClassLoader();
|
jaroslav@478
|
117 |
URL u = l.getResource("META-INF/maven/org.apidesign.html/knockout4j-archetype/pom.xml");
|
jaroslav@478
|
118 |
assertNotNull(u, "Own pom found: " + System.getProperty("java.class.path"));
|
jaroslav@478
|
119 |
|
jaroslav@478
|
120 |
final XPathFactory fact = XPathFactory.newInstance();
|
jaroslav@478
|
121 |
fact.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
jaroslav@478
|
122 |
|
jaroslav@478
|
123 |
XPathExpression xp = fact.newXPath().compile("project/version/text()");
|
jaroslav@478
|
124 |
|
jaroslav@478
|
125 |
Document dom = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(u.openStream());
|
jaroslav@478
|
126 |
return xp.evaluate(dom);
|
jaroslav@478
|
127 |
}
|
jaroslav@478
|
128 |
}
|