public interface JsonTestDataBuilder<T> extends StringBasedBuilder<JsonTestDataBuilder<T>>
This interface specifies a test data loader which loads data from JSON files. JSON files are describing a complex structure, therefore the loaded result is also a complex java object.
With the withId(String) method we can specify an optional identifier for the loaded JSON files.
The load() method returns the loaded instance.
The loadString() method returns the JSON content of the test data.
The StreamBasedBuilder.openStream() method opens a stream which contains this content.
By default, the file is loaded with UTF-8 character set. We can change this with the StringBasedBuilder.withCharset(java.nio.charset.Charset)
method.
TestDataBuilder.fromJson(Class)| Modifier and Type | Method and Description |
|---|---|
JsonTestDataBuilder<T> |
doNotJoinArrays()
After this method is called, this
JsonTestDataBuilder instance will not join arrays anymore. |
JsonTestDataBuilder<T> |
doNotMergeObjects()
After this method is called, this
JsonTestDataBuilder instance will not merge object properties. |
T |
load()
Loads the test data from JSON file(s), and convert it to a java object.
|
String |
loadString()
Loads the test data from JSON file(s).
|
JsonTestDataBuilder<T> |
withId(String testDataId)
With this method we can specify an optional identifier for the loaded JSON files.
|
withCharsetopenStreamJsonTestDataBuilder<T> withId(String testDataId)
testDataId - an identifier of the loaded JSON file(s)JsonTestDataBuilder<T> doNotJoinArrays()
After this method is called, this JsonTestDataBuilder instance will not join arrays anymore. Array properties
loaded from higher priority JSON files will fully replace properties loaded from lower priority files.
For example,
if two JSON files contains array property with the same name, the value of the lowest priority is [1, 2] and the highest
priority file contains [3, 4], then the value of this property in the result will be [3, 4].
JsonTestDataBuilder<T> doNotMergeObjects()
After this method is called, this JsonTestDataBuilder instance will not merge object properties. Every child object
loaded from higher priority JSON files will fully replace properties loaded from lower priority files.
For example,
if two JSON files contains an object property with the same name, the value of the lowest priority is {"b1": 1, "b2": 1} and the highest
priority file contains {"b1": 2}, then the value of this property in the result will be {"b1": 2}.
T load()
String loadString()
null.loadString in interface StringBasedBuilder<JsonTestDataBuilder<T>>StringCreated by Kornél Simon, 2022