Example #1
0
  @Test
  public void testRetrieveJsonElementFromJsonObject2() {
    JsonArray arrayElement = new JsonArray().addString("foo");

    JsonObject tester = new JsonObject().putElement("elementField", arrayElement);

    JsonElement testElement = tester.getElement("elementField");

    assertEquals(arrayElement.get(0), testElement.asArray().get(0));
  }
Example #2
0
  @Test
  public void testRetrieveJsonElementFromJsonObject() {
    JsonObject objElement = new JsonObject().putString("foo", "bar");

    JsonObject tester = new JsonObject().putElement("elementField", objElement);

    JsonElement testElement = tester.getElement("elementField");

    assertEquals(objElement.getString("foo"), testElement.asObject().getString("foo"));
  }
Example #3
0
  @Test
  public void testRetrieveJsonElementFromJsonArray2() {
    JsonArray arrayElement = new JsonArray().addString("foo");

    /* Insert an Object */
    JsonArray tester = new JsonArray().addElement(arrayElement);

    JsonElement testElement = (JsonElement) tester.get(0);

    assertEquals(arrayElement.get(0), testElement.asArray().get(0));
  }
Example #4
0
  @Test
  public void testRetrieveJsonElementFromJsonArray() {
    JsonObject objElement = new JsonObject().putString("foo", "bar");

    /* Insert an Object */
    JsonArray tester = new JsonArray().addElement(objElement);

    JsonElement testElement = (JsonElement) tester.get(0);

    assertEquals(objElement.getString("foo"), testElement.asObject().getString("foo"));
  }
Example #5
0
  @Test
  public void testJsonElementConversionWithoutException() {
    JsonElement objElement = new JsonObject().putString("foo", "bar");
    JsonElement arrayElement = new JsonArray().addString("foo");

    JsonObject retrievedObject = objElement.asObject();
    JsonArray retrievedArray = arrayElement.asArray();

    log.debug(retrievedObject.encode());
    log.debug(retrievedArray.encode());
  }
Example #6
0
  @Test
  public void testJsonElementConversionWithException2() {
    JsonElement arrayElement = new JsonArray().addString("foo");

    try {
      arrayElement.asObject();
    } catch (ClassCastException e) {
      return;
    }

    fail("Coercing JsonElement(Array) into JsonObject did not throw a ClassCastException");
  }
Example #7
0
  @Test
  public void testJsonElementConversionWithException() {
    JsonElement objElement = new JsonObject().putString("foo", "bar");

    try {
      objElement.asArray();
    } catch (ClassCastException e) {
      return;
    }

    fail("Coercing JsonElement(Object) into JsonArray did not throw a ClassCastException");
  }
Example #8
0
  @Test
  public void testJsonElementTypeCheck() {
    JsonElement objElement = new JsonObject().putString("foo", "bar");
    JsonElement arrayElement = new JsonArray().addString("foo");

    assertTrue(objElement.isObject());
    assertFalse(objElement.isArray());

    assertFalse(arrayElement.isObject());
    assertTrue(arrayElement.isArray());
  }