예제 #1
0
 @Test
 public void shouldDeserializeJsonObject() {
   String json = "{'name':'testName'}";
   Type type = new TypeToken<TestRecord>() {}.getType();
   final Object jsonObject =
       reader.readFromStream(new ByteArrayInputStream(json.getBytes()), type);
   assertTrue(jsonObject instanceof TestRecord);
   assertEquals("testName", ((TestRecord) jsonObject).name);
 }
예제 #2
0
  @Test
  public void shouldParseMotechProperties() {
    MotechProperties motechProperties =
        (MotechProperties) reader.readFromFile("/motech-properties.json", MotechProperties.class);

    assertThat(motechProperties.size(), IsEqual.equalTo(14));
    assertThat(motechProperties.get("case_name"), IsEqual.equalTo("Pankaja"));
    assertThat(motechProperties.get("family_number"), IsEqual.equalTo(""));
    assertThat(motechProperties.get("external_id"), IsNull.nullValue());
  }
예제 #3
0
  @Test
  public void shouldSkipMotechPropertyThatHasJsonObjectAsValue() {
    MotechProperties motechProperties =
        (MotechProperties)
            reader.readFromFile("/complex-motech-properties.json", MotechProperties.class);

    assertThat(motechProperties.size(), IsEqual.equalTo(5));
    assertThat(motechProperties, not(Matchers.hasKey("edd")));
    assertThat(motechProperties, not(Matchers.hasKey("next_due")));
    assertThat(motechProperties, not(Matchers.hasKey("next_form")));
    assertThat(motechProperties, not(Matchers.hasKey("partner_name")));
    assertThat(motechProperties, not(Matchers.hasKey("village")));
  }
예제 #4
0
 @Test(expected = MotechException.class)
 public void shouldFailGracefullyWhenJsonFileIsNotFound() {
   reader.readFromFile("this-file-does-not-exist.json", String.class);
 }