コード例 #1
0
  // How many top-level sections are in Book1?
  public void test_tree_queries_results_q4() throws Exception {
    String inputFile = "/TestSources/book.xml";
    String xqFile = "/Queries/XQuery/UseCase/UseCaseTREE/tree-queries-results-q4.xq";
    String resultFile = "/ExpectedTestResults/UseCase/UseCaseTREE/tree-queries-results-q4.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 = "count($input-context/book/section)";
    String actual = null;
    try {
      compileXPath(xpath);
      ResultSequence rs = evaluate(domDoc);

      actual = "<top_section_count>" + buildResultString(rs) + "</top_section_count>";

    } 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);
  }
コード例 #2
0
  // Evaluates the "days-from-duration" function with the arguments set as follows: $arg =
  // xs:dayTimeDuration(upper bound).
  public void test_fn_days_from_duration1args_3() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile =
        "/Queries/XQuery/Functions/DurationDateTimeFunc/DaysFromDurationFunc/fn-days-from-duration1args-3.xq";
    String resultFile =
        "/ExpectedTestResults/Functions/DurationDateTimeFunc/DaysFromDurationFunc/fn-days-from-duration1args-3.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);
  }
コード例 #3
0
  // Simple evaluation of sequence type matching involving instance of and a sequence of decimal.
  public void test_sequence_type_3() throws Exception {
    String inputFile = "/TestSources/emptydoc.xml";
    String xqFile = "/Queries/XQuery/Basics/Types/SequenceTypeSyntax/sequence-type-3.xq";
    String resultFile = "/ExpectedTestResults/Basics/Types/SequenceTypeSyntax/truevalue.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);

      AnyType result = rs.first();

      actual = result.getStringValue();
    } catch (XPathParserException ex) {
      actual = ex.code();
    } catch (StaticError ex) {
      actual = ex.code();
    }

    assertEquals("XPath Result Error:", expectedResult, actual);
  }