| |
| /******************************************************************************* |
| * Copyright (c) 2009, 2017 Standards for Technology in Automotive Retail and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * David Carver - STAR - initial api and implementation bug 262765 |
| * Jesper Moller - bug 281159 - fix expectations and parameters |
| *******************************************************************************/ |
| package org.eclipse.wst.xml.xpath2.processor.testsuite.functions; |
| |
| import java.net.URL; |
| |
| import org.apache.xerces.xs.XSModel; |
| import org.eclipse.wst.xml.xpath2.processor.DynamicError; |
| import org.eclipse.wst.xml.xpath2.processor.ResultSequence; |
| import org.eclipse.wst.xml.xpath2.processor.StaticError; |
| import org.eclipse.wst.xml.xpath2.processor.XPathParserException; |
| import org.eclipse.wst.xml.xpath2.processor.internal.types.XSAnyURI; |
| import org.eclipse.wst.xml.xpath2.processor.test.AbstractPsychoPathTest; |
| |
| |
| public class DocumentURIFuncTest extends AbstractPsychoPathTest { |
| |
| //Evaluates the "document-uri" function with argument set to empty sequence. |
| public void test_fn_document_uri_2() throws Exception { |
| String inputFile = "/TestSources/emptydoc.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-2.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-2.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function with argument set to a document node from an XML file (Normal usage). |
| public void test_fn_document_uri_12() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-12.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-12.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| setVariable("input-context1",new XSAnyURI(inputFile)); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function with argument set to an element node from an XML file. |
| public void test_fn_document_uri_13() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-13.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-13.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function with argument set to an attribute node from an XML file. |
| public void test_fn_document_uri_14() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-14.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-14.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function as argument to fn:string-length function. |
| public void test_fn_document_uri_15() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-15.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-15.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| setVariable("input-context1",new XSAnyURI(inputFile)); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function as argument to fn:upper-case function. |
| public void test_fn_document_uri_16() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-16.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-16.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| setVariable("input-context1", new XSAnyURI(inputFile)); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function as argument to fn:lower-case function. |
| public void test_fn_document_uri_17() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-17.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-17.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| setVariable("input-context1",new XSAnyURI(inputFile)); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function as argument to fn:concat function. |
| public void test_fn_document_uri_18() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-18.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-18.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| setVariable("input-context1",new XSAnyURI(inputFile)); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function as argument to fn:string-join function. |
| public void test_fn_document_uri_19() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-19.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-19.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| setVariable("input-context1",new XSAnyURI(inputFile)); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function as argument to fn:substring-before function. |
| public void test_fn_document_uri_20() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-20.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-20.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| //Evaluates the "document-uri" function as argument to fn:substring-after function. |
| public void test_fn_document_uri_21() throws Exception { |
| String inputFile = "/TestSources/works-mod.xml"; |
| String xqFile = "/Queries/XQuery/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-21.xq"; |
| String resultFile = "/ExpectedTestResults/Functions/AccessorFunc/DocumentURIFunc/fn-document-uri-21.txt"; |
| String expectedResult = getExpectedResult(resultFile); |
| URL fileURL = bundle.getEntry(inputFile); |
| loadDOMDocument(fileURL); |
| |
| // Get XML Schema Information for the Document |
| XSModel schema = getGrammar(); |
| |
| setupDynamicContext(schema); |
| |
| String xpath = extractXPathExpression(xqFile, inputFile); |
| String actual = null; |
| try { |
| compileXPath(xpath); |
| ResultSequence rs = evaluate(domDoc); |
| |
| |
| actual = buildResultString(rs); |
| |
| } catch (XPathParserException ex) { |
| actual = ex.code(); |
| } catch (StaticError ex) { |
| actual = ex.code(); |
| } catch (DynamicError ex) { |
| actual = ex.code(); |
| } |
| |
| assertEquals("XPath Result Error " + xqFile + ":", expectedResult, actual); |
| |
| |
| } |
| |
| } |
| |