- java.lang.Object
-
- io.ebean.test.DbJson
-
public class DbJson extends Object
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 Modifier and Type Class Description static classDbJson.PrettyJsonContains the JSON of beans(s).
-
Constructor Summary
Constructors Constructor Description DbJson()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static DbJson.PrettyJsonof(Object bean)Create 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.
-
-
-
Method Detail
-
of
public static DbJson.PrettyJson of(Object bean)
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");
-
-