Package com.alexgilleran.icesoap.xpath.elements.impl

Examples of com.alexgilleran.icesoap.xpath.elements.impl.SingleSlashXPathElement


    // Purchase Order sample XML
    XPathPullParser parser = new XPathPullParserImpl();
    parser.setInput(SampleXml.getPurchaseOrder(), null);

    // Purchase Order Node (root)
    XPathElement expectedXPathElement = new SingleSlashXPathElement(
        "PurchaseOrder", null);
    expectedXPathElement.addPredicate("PurchaseOrderNumber", "99503");
    expectedXPathElement.addPredicate("OrderDate", "1999-10-20");

    assertEquals(XPathPullParser.START_TAG, parser.next());
    assertEquals(expectedXPathElement, parser.getCurrentElement());

    // Purchase Order "PurchaseOrderNumber" Attribute
    assertAttribute(parser, expectedXPathElement, "PurchaseOrderNumber",
        "99503");

    // Purchase Order "OrderDate" Attribute
    assertAttribute(parser, expectedXPathElement, "OrderDate", "1999-10-20");

    // Address Node
    expectedXPathElement = new SingleSlashXPathElement("Address",
        expectedXPathElement);
    expectedXPathElement.addPredicate("Type", "Shipping");

    // Shipping Address
    assertEquals(XPathPullParser.START_TAG, parser.next());
    assertEquals(expectedXPathElement, parser.getCurrentElement());

    assertAttribute(parser, expectedXPathElement, "Type", "Shipping");
    assertTextElement(parser, expectedXPathElement, "Name", "Ellen Adams");
    assertTextElement(parser, expectedXPathElement, "Street",
        "123 Maple Street");
    assertTextElement(parser, expectedXPathElement, "City", "Mill Valley");
    assertTextElement(parser, expectedXPathElement, "State", "CA");
    assertTextElement(parser, expectedXPathElement, "Zip", "10999");
    assertTextElement(parser, expectedXPathElement, "Country", "USA");

    assertEquals(XPathPullParser.END_TAG, parser.next());
    assertEquals(expectedXPathElement, parser.getCurrentElement());

    assertEquals(XPathPullParser.START_TAG, parser.next());
    // Adding another type predicate will override the previous one
    expectedXPathElement.addPredicate("Type", "Billing");
    assertEquals(expectedXPathElement, parser.getCurrentElement());

    // Billing Address
    assertAttribute(parser, expectedXPathElement, "Type", "Billing");
    assertTextElement(parser, expectedXPathElement, "Name", "Tai Yee");
    assertTextElement(parser, expectedXPathElement, "Street",
        "8 Oak Avenue");
    assertTextElement(parser, expectedXPathElement, "City", "Old Town");
    assertTextElement(parser, expectedXPathElement, "State", "PA");
    assertTextElement(parser, expectedXPathElement, "Zip", "95819");
    assertTextElement(parser, expectedXPathElement, "Country", "USA");

    assertEquals(XPathPullParser.END_TAG, parser.next());
    assertEquals(expectedXPathElement, parser.getCurrentElement());

    expectedXPathElement = expectedXPathElement.getPreviousElement();

    assertTextElement(parser, expectedXPathElement, "DeliveryNotes",
        "Please leave packages in shed by driveway.");
  }
View Full Code Here


   */
  private void assertTextElement(XPathPullParser parser,
      XPathElement rootXPathElement, String name, String value)
      throws XMLParsingException {
    assertEquals(XPathPullParser.START_TAG, parser.next());
    XPathElement textXPath = new SingleSlashXPathElement(name,
        rootXPathElement);
    assertEquals(textXPath, parser.getCurrentElement());
    assertEquals(XPathPullParser.TEXT, parser.next());
    assertEquals(parser.getCurrentValue(), value);
    assertEquals(XPathPullParser.END_TAG, parser.next());
View Full Code Here

   * @throws XMLParsingException
   */
  private void assertAttribute(XPathPullParser parser, XPathElement node,
      String name, String value) throws XMLParsingException {
    assertEquals(XPathPullParser.ATTRIBUTE, parser.next());
    assertEquals(new AttributeXPathElement(new SingleSlashXPathElement(
        name, node)), parser.getCurrentElement());
    assertEquals(value, parser.getCurrentValue());
  }
View Full Code Here

        "/xpath[@predicate1=\"true1\"]/xpath2[@predicate2=\"true2\"]"));

    // Build up a multi-predicate xpath and check that it matches a
    // simpler one - do this programmatically seeing as parsing of multiple
    // predicate xpaths isn't yet supported, but can happen in the parser
    XPathElement complexXPath1 = new SingleSlashXPathElement("xpath1", null);
    complexXPath1.addPredicate("pred1", "value1");
    complexXPath1.addPredicate("pred2", "value2");
    XPathElement complexXPath2 = new SingleSlashXPathElement("xpath2", complexXPath1);
    complexXPath2.addPredicate("pred3", "value3");
    complexXPath2.addPredicate("pred4", "value4");
    XPathElement complexXPath3 = new SingleSlashXPathElement("xpath3", complexXPath2);
    complexXPath3.addPredicate("pred5", "value5");
    complexXPath3.addPredicate("pred6", "value6");

    // Check that it looks the way that it's supposed to
    assertEquals(
        "/xpath1[@pred1=\"value1\" and @pred2=\"value2\"]/xpath2[@pred3=\"value3\" and @pred4=\"value4\"]/xpath3[@pred5=\"value5\" and @pred6=\"value6\"]",
        complexXPath3.toString());

    XPathElement xpathToMatch = XPathFactory.getInstance().compile("/xpath1/xpath2[@pred3=\"value3\"]/xpath3")
        .keySet().iterator().next();

    assertTrue(xpathToMatch.matches(complexXPath3));
View Full Code Here

TOP

Related Classes of com.alexgilleran.icesoap.xpath.elements.impl.SingleSlashXPathElement

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.