@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); }
@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()); }
@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"))); }
@Test(expected = MotechException.class) public void shouldFailGracefullyWhenJsonFileIsNotFound() { reader.readFromFile("this-file-does-not-exist.json", String.class); }