public class WritingJsonValidator extends Object
| Modifier and Type | Class and Description |
|---|---|
static class |
WritingJsonValidator.JsonWrapper
A wrapper class for
Actions and Datasources |
| Modifier and Type | Field and Description |
|---|---|
static String |
controlFileSource
The default relative path to write control-files to when
writeJson is true (default:
src/test/resources/). |
static boolean |
logJson
Set to
true to log the actual JSON document (debug level) when validating (default false). |
static boolean |
sortPropertiesAlphabetically
Set to
true to let the object mapper sort the properties of an object alphabetically. |
static boolean |
writeJson
|
| Constructor and Description |
|---|
WritingJsonValidator() |
| Modifier and Type | Method and Description |
|---|---|
static File |
getControlFile(String controlFile)
Reads the given control file from the classpath
|
static String |
normalizeLines(String string)
Normalizes the line breaks of the string to use
System.lineSeparator(). |
static String |
toJSON(Object object)
Maps the given
object to a JSON string. |
static String |
toJSON(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
Object object)
Maps the given
object to a JSON string using the given ObjectMapper. |
static void |
validate(Action action,
String controlFile)
Validates that the JSON created from the
action is equal to the document parsed from the
controlFile. |
static void |
validate(Datasource datasource,
String controlFile)
Validates that the JSON created from the
datasource is equal to the document parsed from the
controlFile. |
static void |
validate(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
Object object,
String controlFile)
Validates that the JSON created from the
object is equal to the document parsed from the
controlFile. |
static void |
validate(Object object,
String controlFile)
Validates that the JSON created from the
object is equal to the document parsed from the
controlFile. |
static void |
validate(String json,
String controlFile)
Validates that
json-string is equal to the document parsed from the controlFile. |
static File |
writeToDisk(Object data,
String name)
Writes the document represented by
data to a File. |
static File |
writeToDiskPlain(String json,
String controlFile)
Writes the document represented by
json to a File. |
public static boolean writeJson
public static boolean logJson
true to log the actual JSON document (debug level) when validating (default false).public static boolean sortPropertiesAlphabetically
true to let the object mapper sort the properties of an object alphabetically. For further
information see MapperFeature.SORT_PROPERTIES_ALPHABETICALLYpublic static File writeToDisk(Object data, String name) throws IOException
data to a File.data - a WritingJsonValidator.JsonWrappername - the path to the file (relative to controlFileSource )FileIOException - if an I/O error occurs while writing the filepublic static File writeToDiskPlain(String json, String controlFile) throws IOException
json to a File.json - a JSON stringcontrolFile - the path to the file (relative to controlFileSource )FileIOException - if an I/O error occurs while writing the filepublic static void validate(Action action, String controlFile) throws IOException
action is equal to the document parsed from the
controlFile.action - the Action to create JSON fromcontrolFile - the path to the control file (relative to the classpath)IOException - if an error occurs while creating the JSON or while reading the control filepublic static void validate(Datasource datasource, String controlFile) throws IOException
datasource is equal to the document parsed from the
controlFile.datasource - the Datasource to create JSON fromcontrolFile - the path to the control file (relative to the classpath)IOException - if an error occurs while creating the JSON or while reading the control filepublic static void validate(Object object, String controlFile) throws IOException
object is equal to the document parsed from the
controlFile.object - the object to create JSON fromcontrolFile - the path to the control file (relative to the classpath)IOException - if an error occurs while creating the JSON or while reading the control filepublic static void validate(com.fasterxml.jackson.databind.ObjectMapper objectMapper,
Object object,
String controlFile)
throws IOException
object is equal to the document parsed from the
controlFile.objectMapper - the custom ObjectMapper to useobject - the object to create JSON fromcontrolFile - the path to the control file (relative to the classpath)IOException - if an error occurs while creating the JSON or while reading the control filepublic static void validate(String json, String controlFile) throws IOException
json-string is equal to the document parsed from the controlFile.json - the JSON stringcontrolFile - the path to the control file (relative to the classpath)IOException - if an error occurs while parsing the JSON string or while reading the control filepublic static String normalizeLines(String string)
System.lineSeparator().string - the string to normalizepublic static File getControlFile(String controlFile) throws IOException
controlFile - the path to the control file (relative to the classpath)IOException - if an error occurs while reading the control filepublic static String toJSON(Object object) throws IOException
object to a JSON string.object - the object to be mappedIOException - if an error occurs while mapping the object to JSONpublic static String toJSON(com.fasterxml.jackson.databind.ObjectMapper objectMapper, Object object) throws IOException
object to a JSON string using the given ObjectMapper.objectMapper - the the custom ObjectMapper to useobject - the object to be mappedIOException - if an error occurs while mapping the object to JSONCopyright © 2011–2023 aiticon GmbH. All rights reserved.