Java Examples for com.revinate.assertj.json.JsonPathAssert

The following java examples will help you to understand the usage of com.revinate.assertj.json.JsonPathAssert. These source code samples are taken from different open source projects.

Example 1
Project: iiif-presentation-api-master  File: IiifPresentationApiObjectMapperTest.java View source code
@Test
public void testCollectionToJson() throws JsonProcessingException {
    PropertyValue labelProp = new PropertyValueSimpleImpl("some label");
    List<Metadata> metadata = new ArrayList<>();
    metadata.add(new MetadataImpl(new PropertyValueSimpleImpl("some key"), new PropertyValueSimpleImpl("some value")));
    Collection coll = new CollectionImpl(URI.create("http://example.com/collection/some-collection"), labelProp, metadata);
    List<ManifestReference> manifests = new ArrayList<>();
    manifests.add(new ManifestReferenceImpl(URI.create("http://example.com/manifest/some-manifest"), new PropertyValueSimpleImpl("some label")));
    manifests.add(new ManifestReferenceImpl(URI.create("http://example.com/manifest/some-other-manifest")));
    coll.setManifests(manifests);
    List<CollectionReference> subColls = new ArrayList<>();
    subColls.add(new CollectionReferenceImpl(URI.create("http://example.com/collection/some-other-collection"), new PropertyValueSimpleImpl("some label")));
    subColls.add(new CollectionReferenceImpl(URI.create("http://example.com/collection/yet-another-collection")));
    coll.setSubCollections(subColls);
    String jsonString = objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(coll);
    DocumentContext ctx = JsonPath.parse(jsonString);
    JsonPathAssert.assertThat(ctx).jsonPathAsInteger("$.collections.length()").isEqualTo(2);
    JsonPathAssert.assertThat(ctx).jsonPathAsInteger("$.manifests.length()").isEqualTo(2);
    JsonPathAssert.assertThat(ctx).jsonPathAsString("$.label").isEqualTo("some label");
    JsonPathAssert.assertThat(ctx).jsonPathAsString("$.metadata[0].label").isEqualTo("some key");
    JsonPathAssert.assertThat(ctx).jsonPathAsString("$.manifests[0]['@type']").isEqualTo("sc:Manifest");
    JsonPathAssert.assertThat(ctx).jsonPathAsString("$.collections[0]['@type']").isEqualTo("sc:Collection");
}