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

Examples of com.gistlabs.mechanize.document.json.node.impl.ObjectNodeImpl


      JSONTokener jsonTokener = new JSONTokener(new InputStreamReader(getInputStream()));
      char nextClean = jsonTokener.nextClean(); jsonTokener.back();
     
      switch (nextClean) {
      case '{':
        this.json = new ObjectNodeImpl(new JSONObject(jsonTokener));
        break;
      case '[':
        this.json = new ArrayNodeImpl(new JSONArray(jsonTokener));
        break;
      default:
View Full Code Here


import com.gistlabs.mechanize.document.json.node.impl.TestElementBaseClass;

public abstract class JsonNodeTestCase extends TestElementBaseClass {

  public static JsonNode from(String json) {
    return new ObjectNodeImpl(parseJson(json));
  }
View Full Code Here

public class NestedElementsTest extends TestElementBaseClass {

  @Test
  public void testNestedElement() {
    ObjectNodeImpl element = new ObjectNodeImpl(parseJson("{ \"one\" : 2, \"b\" : { \"a\" : \"x\", \"c\" : 4 } }"));

    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

    assertEquals("x", nested.getAttribute("a"));
  }

  @Test
  public void testNullChild() {
    ObjectNodeImpl element = new ObjectNodeImpl(parseJson("{ \"one\" : 2, \"b\" : { \"a\" : \"x\", \"c\" : 4 } }"));

    assertNull(element.getChild("c"));
  }
View Full Code Here

public class ElementAttributesTest extends TestElementBaseClass {

  @Test
  public void testString() {
    JSONObject parsedJson = parseJson("{ \"one\" : \"two\", \"\" : \"four\", \"a:b\" : \"http://example.com\" }");
    ObjectNodeImpl element = new ObjectNodeImpl(parsedJson);

    assertEquals("two", element.getAttribute("one"));
    assertEquals("four", element.getAttribute(""));
    assertEquals("http://example.com", element.getAttribute("a:b"));
  }
View Full Code Here

    assertEquals("http://example.com", element.getAttribute("a:b"));
  }

  @Test
  public void testStringCasting() {
    ObjectNodeImpl element = new ObjectNodeImpl(parseJson("{ \"one\" : \"two\", \"\" : \"four\", \"a:b\" : \"http://example.com\" }"));

    assertEquals("four", element.getAttribute(""));
    assertEquals("two", element.getChild("one").getValue());
    assertEquals("four", element.getChild("").getValue());
  }
View Full Code Here

    assertEquals("four", element.getChild("").getValue());
  }

  @Test
  public void testNumber() {
    ObjectNodeImpl element = new ObjectNodeImpl(parseJson("{ \"one\" : 2, \"b\" : 2.2 }"));

    assertEquals("2", element.getAttribute("one"));
    assertEquals("2.2", element.getChild("b").getValue());
  }
View Full Code Here


public class AttributeNodeSelectorTest {

  protected NodeSelector<JsonNode> build(final String json) throws JSONException {
    ObjectNodeImpl node = new ObjectNodeImpl(new JSONObject(json));
    return node.buildNodeSelector();
  }
View Full Code Here

    assertEquals("2.2", element.getChild("b").getValue());
  }

  @Test
  public void testParentage() {
    ObjectNodeImpl element = new ObjectNodeImpl(parseJson("{ \"one\" : 2, \"b\" : 2.2 }"));

    assertNull(element.getParent());
    assertEquals(element, element.getChild("one").getParent());
  }
View Full Code Here

    assertEquals(element, element.getChild("one").getParent());
  }

  @Test
  public void testSetAttributes() {
    ObjectNodeImpl element = new ObjectNodeImpl(parseJson("{ \"one\" : 2, \"b\" : 2.2 }"));

    assertEquals("2", element.getAttribute("one"));
    element.setAttribute("one", "new");
    assertEquals("new", element.getAttribute("one"));

    assertEquals("2.2", element.getChild("b").getValue());
    element.getChild("b").setValue("maybe");
    assertEquals("maybe", element.getChild("b").getValue());
  }
View Full Code Here

TOP

Related Classes of com.gistlabs.mechanize.document.json.node.impl.ObjectNodeImpl

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.