Package com.alexgilleran.icesoap.xpath.elements

Examples of com.alexgilleran.icesoap.xpath.elements.XPathElement


  public void testXPathUnion() throws XPathParsingException {
    // Test two xpaths linked by a pipe
    XPathRepository<XPathElement> xpaths = factory.compile("/this/is/a/test | hello//everybody");

    XPathRepository<XPathElement> manualXPaths = new XPathRepository<XPathElement>();
    XPathElement firstXPath = factory.compile("/this/is/a/test").keySet().iterator().next();
    XPathElement secondXPath = factory.compile("hello//everybody").keySet().iterator().next();
    manualXPaths.put(firstXPath, firstXPath);
    manualXPaths.put(secondXPath, secondXPath);

    assertEquals(manualXPaths, xpaths);

    // Test three xpaths linked by a pipe.
    xpaths = factory.compile("/this/is/a/test | hello//everybody | //la/de/da");

    XPathElement thirdXPath = factory.compile("//la/de/da").keySet().iterator().next();
    manualXPaths.put(thirdXPath, thirdXPath);

    assertEquals(manualXPaths, xpaths);
  }
View Full Code Here


    assertEquals(manualXPaths, xpaths);
  }

  @Test
  public void testRelativeXPath() throws XPathParsingException {
    XPathElement relativeElement = factory
        .compile("this[@pred3=\"value3\"]/is[@pred=\"value\"]/relative[@pred2=\"value2\"]").keySet().iterator()
        .next();

    assertEquals("relative", relativeElement.getName());
    assertEquals("value2", relativeElement.getPredicate("pred2"));

    XPathElement isElement = relativeElement.getPreviousElement();
    assertEquals("is", isElement.getName());
    assertEquals("value", isElement.getPredicate("pred"));

    XPathElement thisElement = isElement.getPreviousElement();
    assertEquals("this", thisElement.getName());
    assertEquals("value3", thisElement.getPredicate("pred3"));
  }
View Full Code Here

    // 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

        attributeXPath);
  }

  @Test
  public void testRemove() throws XPathParsingException {
    XPathElement xpath1 = XPathFactory.getInstance().compile("//this/is/a/test").keySet().iterator().next();
    XPathElement xpath2 = XPathFactory.getInstance().compile("/blah/herp").keySet().iterator().next();
    XPathElement xpath3 = XPathFactory.getInstance().compile("//test").keySet().iterator().next();

    repo.put(xpath1, xpath1.toString());
    repo.put(xpath2, xpath2.toString());
    repo.put(xpath3, xpath3.toString());

    assertEquals(3, repo.size());

    repo.remove(xpath2);

    assertEquals(2, repo.size());

    assertEquals(xpath1.toString(), repo.get(xpath1));
    assertNull(repo.get(xpath2));
    assertEquals(xpath3.toString(), repo.get(xpath3));
  }
View Full Code Here

    assertEquals(xpath3.toString(), repo.get(xpath3));
  }

  private void testPut(String xpathToGet, String xpathToPut) throws XPathParsingException {
    repo = new XPathRepository<String>();
    XPathElement xpathElementToPut = XPathFactory.getInstance().compile(xpathToPut).keySet().iterator().next();
    XPathElement xpathElementToGet = XPathFactory.getInstance().compile(xpathToGet).keySet().iterator().next();

    assertNull(repo.get(xpathElementToGet));
    repo.put(xpathElementToPut, xpathToGet);

    assertEquals(xpathToGet, repo.get(xpathElementToPut));
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

        "/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));

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

    assertFalse(xpathToNotMatch.matches(complexXPath3));
  }
View Full Code Here

    // Make a copy of the repo keyset, as we may need to concurrently remove
    // xpaths from the repo while looping through.
    Set<XPathElement> xpathsSet = new HashSet<XPathElement>(xpaths.keySet());

    for (XPathElement thisXPath : xpathsSet) {
      XPathElement firstXPathElement = thisXPath.getFirstElement();

      if (firstXPathElement.isRelative()) {
        // If the xpath is relative, we want to add the root xpath(s) of
        // the object to the start of it.

        if (getRootXPaths().keySet().size() == 1) {
          thisXPath.getFirstElement().setPreviousElement(getRootXPaths().keySet().iterator().next());
        } else {
          // As there are multiple root xpaths, we need to create an
          // new instance of this field xpath for each root xpath
          // (using the existing field xpath object as a prototype)
          // and add the enclosing xpath to the start of each.

          // Remove the existing xpath from the repo (we'll add a
          // modified clone of it later)
          xpaths.remove(thisXPath);

          for (XPathElement rootXPath : getRootXPaths().keySet()) {
            // Copy the relative xpath for the field
            XPathElement element = thisXPath.clone();

            // Append the new xpath to this root xpath.
            element.getFirstElement().setPreviousElement(rootXPath);

            // Put the new element in the xpaths repository.
            xpaths.put(element, element);
          }
        }
View Full Code Here

TOP

Related Classes of com.alexgilleran.icesoap.xpath.elements.XPathElement

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.