diff -r f9c73ee49287 -r ead6a0d4e022 java/alt2xml-out-xpath/test/cz/frantovo/alt2xml/out/xpath/XPathActionNGTest.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/java/alt2xml-out-xpath/test/cz/frantovo/alt2xml/out/xpath/XPathActionNGTest.java Thu Sep 04 17:56:58 2014 +0200
@@ -0,0 +1,96 @@
+/**
+ * Alt2XML
+ * Copyright © 2014 František Kučera (frantovo.cz)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package cz.frantovo.alt2xml.out.xpath;
+
+import cz.frantovo.alt2xml.out.ActionContext;
+import java.io.ByteArrayOutputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.dom.DOMResult;
+import static org.testng.Assert.*;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+/**
+ *
+ * @author Ing. František Kučera (frantovo.cz)
+ */
+public class XPathActionNGTest {
+
+ private final DocumentBuilderFactory documentBuilderFactory;
+ private final DocumentBuilder documentBuilder;
+ private Properties actionProperties;
+ private List actionData;
+
+ public XPathActionNGTest() throws ParserConfigurationException {
+ documentBuilderFactory = DocumentBuilderFactory.newInstance();
+ documentBuilder = documentBuilderFactory.newDocumentBuilder();
+ }
+
+ private DOMResult generateEmptyResult() {
+ return new DOMResult(documentBuilder.newDocument());
+ }
+
+ private static byte[] generateStringResult(String value) {
+ return (value + "\n").getBytes();
+ }
+
+ @BeforeMethod
+ public void setupMethod() {
+ actionProperties = new Properties();
+ actionData = new ArrayList<>();
+ System.out.println("\n--- Output: --------");
+ }
+
+ @Test
+ public void testRun_simple() throws Exception {
+ actionData.add("1+1");
+
+ doTest(generateEmptyResult(), actionData, actionProperties, generateStringResult("2"));
+ }
+
+ @Test
+ public void testRun_simpleParameters() throws Exception {
+ actionProperties.put(XPathAction.PARAMETER_TYPED_PARAMETERS, Boolean.FALSE);
+
+ actionData.add("1+$a");
+ actionData.add("a");
+ actionData.add("2");
+
+ doTest(generateEmptyResult(), actionData, actionProperties, generateStringResult("3"));
+ }
+
+ private void doTest(DOMResult domResult, List actionData, Properties actionProperties, byte[] expectedResult) throws Exception {
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ActionContext actionContext = new ActionContext(baos);
+
+ actionContext.setActionProperties(actionProperties);
+ actionContext.setActionData(actionData);
+
+ XPathAction instance = new XPathAction(actionContext);
+ instance.run(domResult);
+ System.out.write(baos.toByteArray());
+
+ assertEquals(baos.toByteArray(), expectedResult);
+ }
+}