java.lang.Object
io.ebean.test.DbJson
Helper for testing to assert that the JSON form of an entity
or list of entities is as expected.
Using assertContains() we can match the JSON form of an entity against a subset of JSON content. Typically the subset of JSON excludes generated properties like id, when created and when modified properties.
Assert contains
DbJson.of(order)
.assertContains("/order-partial.json");
Assert content matches
Using assertContentMatches() we are doing an exact content match. We typically need to replace generated property values. This assert will start to fail if the model changes like adding a property to the entity so we should use it less widely due to the maintenance burden we have with it.
DbJson.of(order)
.replace("id", "whenCreated", "whenModified)
.assertContentMatches("/order-full.json");
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic DbJson.PrettyJsonCreate a PrettyJson object that has the JSON form of the entity bean or beans.static StringreadResource(String resourcePath) Read the content for the given resource path.
-
Constructor Details
-
DbJson
public DbJson()
-
-
Method Details
-
of
Create a PrettyJson object that has the JSON form of the entity bean or beans.Assert contains
DbJson.of(order) .assertContains("/order-partial.json");Assert content matches
DbJson.of(order) .replace("id", "whenCreated", "whenModified) .assertContentMatches("/order-full.json"); -
readResource
Read the content for the given resource path.
-