Package com.gistlabs.mechanize.document.json.node

Examples of com.gistlabs.mechanize.document.json.node.JsonNode


   *
   * @param var maybe null if not found
   * @return
   */
  protected Object lookupWalkForVar(String var) {
    JsonNode current = node;
    while (current!=null) {
      Object result = lookupVar(current, var);
      if (result!=null) return result;
     
      if (current.hasAttribute("inheritProperties")) {
        current = current.getParent();       
      } else {
        current = null;
      }
    }
    return lookupVar(node, var);
View Full Code Here


  protected List<JsonNode> factory(final String key) {
    try {
      ArrayList<JsonNode> result = new ArrayList<JsonNode>();
      try {
        JsonNode n = factory(this.obj, key);
        if (n!=null)
          result.add(n);
      } catch(JsonArrayException e) {
        if (e.getArray()==null)
          throw e;
View Full Code Here

      for (JsonNode child : children) {
        result.add(child.getValue());
      }
      return result;
    } else if (children.size()==1) {
      JsonNode child = children.get(0);
      List<String> attributeNames = child.getAttributeNames();
      Collections.sort(attributeNames);

      if (attributeNames.size()==0) { // treat child as the attribute value
        return child.getValue();
      } else { // treat child as object with map values
        Map<String, String> result = new LinkedHashMap<String, String>();
        for (String attrName : attributeNames) {
          result.put(attrName, child.getAttribute(attrName));
        }
        return result;
      }
    } else { // return null
      return null;
View Full Code Here

public class MixedChildrenElementsTest extends TestElementBaseClass {
  ObjectNodeImpl element = new ObjectNodeImpl(parseJson("{ \"a\" : 2, \"b\" : { \"a\" : \"x\", \"c\" : 4 }, \"c\" : [ { \"a\" : 1 }, { \"b\" : 2 } ] }"));

  @Test
  public void testPrimitiveChild() {
    JsonNode nested = element.getChild("a");
    assertNotNull(nested);

    Collection<String> attributes = element.getAttributeNames();
    assertEquals(1, attributes.size());
    assertTrue(attributes.contains("a"));
View Full Code Here

    assertTrue(attributes.contains("a"));
  }

  @Test
  public void testElementChild() {
    JsonNode nested = element.getChild("b");
    assertNotNull(nested);
    assertTrue(nested instanceof ObjectNodeImpl);
    assertEquals("b", nested.getName());
    assertEquals(element, nested.getParent());
    assertEquals("x", nested.getAttribute("a"));
  }
View Full Code Here

    JsonDocument page = agent().get("http://test.com");
    assertNotNull(page.getRoot());

    assertEquals("US", page.getRoot().getAttribute("country"));

    JsonNode node = page.getRoot().find("quota_info");
    assertEquals("107374182400000", node.getAttribute("quota"));
  }
View Full Code Here

    json = from(jsonString);
  }
 
  @Test
  public void testFindingOneHref() {
    JsonNode one = json.find("one");
    List<JsonLink> links = finder.findOn(one);
    assertEquals(1, links.size());
   
    JsonLink hrefLink = links.get(0);
    assertEquals(hrefLink.node(), one);
View Full Code Here

    assertEquals(hrefLink.node(), one);
  }
 
  @Test
  public void testFindingTwoLinks() {
    JsonNode two = json.find("two");
    List<JsonLink> links = finder.findOn(two);
    assertEquals(2, links.size());
   
    // collect data from the json
    Map<String, String> data = new HashMap<String, String>();
    for (String name : two.getAttributeNames()) {
      data.put(name, two.getAttribute(name));
    }
   
    // make sure the values all match
    for (JsonLink link : links) {
      assertEquals(data.get(link.attrName()), link.uri());
View Full Code Here

    }
  }
 
  @Test
  public void testFindingThreeLinks() {
    JsonNode three = json.find("three");
    List<JsonLink> links = finder.findOn(three);
    assertEquals(3, links.size());
  }
View Full Code Here

    assertEquals(3, links.size());
  }
 
  @Test
  public void testLinkRelIsName() {
    JsonNode one = json.find("rel-is-name");
    List<JsonLink> links = finder.findOn(one);
    assertEquals(1, links.size());
   
    JsonLink hrefLink = links.get(0);
    assertEquals("rel-is-name", hrefLink.linkRel());
View Full Code Here

TOP

Related Classes of com.gistlabs.mechanize.document.json.node.JsonNode

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.