public interface TestDataBuilder
fromProperties(String): data loading from java property file(s)fromJson(Class): data loading from JSON file(s)fromBinary(String): data loading from any kind of file(s)ibello/data
folder, but we can change this with the ibello.dir.data configuration parameter.| Modifier and Type | Method and Description |
|---|---|
TestDataExpressionEvaluator |
expression(String expression)
Creates an objects which can be used to evaluate a test data expression.
|
BinaryTestDataBuilder |
fromBinary(String fileName)
Returns an object which can be used to load test data from a binary file.
|
<T> CsvTestDataBuilder<T> |
fromCsv(Class<T> dataType)
Returns an object which can be used to load test data from a CSV file.
|
<T> JsonTestDataBuilder<T> |
fromJson(Class<T> dataType)
Returns an object which can be used to load test data from a JSON file.
|
PropertiesTestDataBuilder |
fromProperties(String fileNamePrefix)
Returns an object which can be used to load test data from a java property file.
|
TxtTestDataBuilder |
fromTxt(String fileNamePrefix)
Returns an object which can be used to load test data from a TXT file.
|
PropertiesTestDataBuilder fromProperties(String fileNamePrefix)
Returns an object which can be used to load test data from a java property file.
For that, we need to specify a file name prefix. The name of the loaded file
will start with that prefix, followed by a dot. The final extension of the file will
be .properties. Between the prefix and the extension the file name may contain
tags, separated by dashes. Examples:
prefix.propertiesprefix.tag1.propertiesprefix.tag1-tag2.propertiesDuring the loading process, the loader creates a list of available and matching files, then it sorts them by precedence. At first, the first file will be loaded. If they are other matching files, then the second one will be loaded, and it's properties will override the properties of the first file. Other matching files are loaded in that order, and also update the previously loaded properties.
Each loaded files should have the specified prefix. If a file name also have tags, then they will be validated against the current ibello tags. If a file has a tag which was not specified as an ibello tag, then that file will be not loaded. In other words, loaded files should not have unspecified tags.
The first loaded file will be the one without tags (if any). The remaining files will be sorted by the number of tags and the tags itself (in alphabetical order). Examples:
prefix.a.properties will be loaded before prefix.b.propertiesprefix.c.properties will be loaded before prefix.a-b.propertiesIf two loaded files have the same property, then the latest file's property will be in the final result.
The files can be placed into sub-directories, the loader will find them automatically.
fileNamePrefix - file name prefix, cannot be null<T> JsonTestDataBuilder<T> fromJson(Class<T> dataType)
Returns an object which can be used to load test data from a JSON file. For that we must specify a java class which will receive all data from the JSON file.
The name of the file starts with the lower-case name of the java class (without package name).
It may be followed by a dash sign and an identifier. Then comes a dot. At this position the file name may
contain tags, separated by dash signs. The extension of the file is always json. Examples:
myclass.jsonmyclass.tag1.jsonmyclass-id.tag1.jsonmyclass-id.tag1-tag2.jsonDuring the loading process, the loader creates a list of available and matching files, then it sorts them by precedence. At first, the first file will be loaded. If they are other matching files, then the second one will be loaded, and it's properties will override the properties of the first file. Other matching files are loaded in that order, and also update the previously loaded properties.
Each loaded files should have the class name prefix. If an identifier was specified, then the prefix should be followed by a dash sign and the identifier. If a file name also have tags, then it will be validated against the current ibello tags. If a file has a tag which was not specified as an ibello tag, then that file will be not loaded. In other words, loaded files should not have unspecified tags.
The first loaded file will be the one without identifier and tags (if any). Then comes the files without identifier but with one or more tags. The remaining files (with identifier) will be sorted by the number of tags and the tags itself (in alphabetical order). Examples:
myclass.json will be loaded before myclass.a.jsonmyclass.a.json will be loaded before myclass-id.jsonmyclass.a.json will be loaded before myclass.b.jsonmyclass.c.json will be loaded before myclass.a-b.jsonThe files can be placed into sub-directories, the loader will find them automatically.
By default, the objects loaded from the JSON files will be fully merged in the result. Element of arrays will be joined together. For example, the first two JSON object will result the third one:
{
"a": 1,
"b": {
"b1": 1, "b2": 1, "b3": {"b3_1": 1}
},
"c": [1]
}
{
"a": 2,
"b": {
"b1": 2, "b3": {"b3_2": 2}
},
"c": [2]
}
{
"a": 2,
"b": {
"b1": 2, "b2": 1, "b3": {"b3_1": 1, "b3_2": 2}
},
"c": [1,2]
}
We can change this behavior with the JsonTestDataBuilder.doNotMergeObjects() and JsonTestDataBuilder.doNotJoinArrays()
methods.
T - type of the result objectdataType - type of the result object<T> CsvTestDataBuilder<T> fromCsv(Class<T> dataType)
Returns an object which can be used to load test data from a CSV file. For that we must specify a java class which will be the type of the loaded items.
The name of the file starts with the lower-case name of the java class (without package name).
It may be followed by a dash sign and an identifier. Then comes a dot. At this position the file name may
contain tags, separated by dash signs. The extension of the file is always csv. Examples:
myclass.csvmyclass.tag1.csvmyclass-id.tag1.csvmyclass-id.tag1-tag2.csvDuring the loading process, the loader creates a list of available and matching files, then it sorts them by precedence. At first, the first file will be loaded. If they are other matching files, then the second one will be loaded, and it's content will be appended to the result. Other matching files are loaded in that order, and also are appended the result.
Each loaded files should have the class name prefix. If an identifier was specified, then the prefix should be followed by a dash sign and the identifier. If a file name also have tags, then it will be validated against the current ibello tags. If a file has a tag which was not specified as an ibello tag, then that file will be not loaded. In other words, loaded files should not have unspecified tags.
The first loaded file will be the one without identifier and tags (if any). Then comes the files without identifier but with one or more tags. The remaining files (with identifier) will be sorted by the number of tags and the tags itself (in alphabetical order). Examples:
myclass.csv will be loaded before myclass.a.csvmyclass.a.csv will be loaded before myclass-id.csvmyclass.a.csv will be loaded before myclass.b.csvmyclass.c.csv will be loaded before myclass.a-b.csvThe files can be placed into sub-directories, the loader will find them automatically.
The data values in the CSV file should be separated by comma (and not semicolon or tabulator).
Each CSV file should have a header - this is the first line in the file.
This line should contain the field names of the data type where we want to place the values. Complex field names are also
allowed - the field separator is the dot character. If a field has a SerializedName annotation, then - instead of the field name -
the value of that annotation should be in the header.
Let's say we have these java classes:
public class MyClass {
public int number;
@SerializedName("x-y")
public String xy;
public ChildClass child;
}
public class ChildClass {
public LocalDate date;
}
For that data structure we may have a CSV file with this content:
number,x-y,child.date 1,"test","2001-02-03"
T - type of the items in the result listdataType - type of the items in the result listTxtTestDataBuilder fromTxt(String fileNamePrefix)
Returns an object which can be used to load test data from a TXT file. For that, we must specify a prefix for the loaded file.
The name of the loaded file starts with the given prefix. Then comes a dot. Optionally, one or more tags can be
added to the name here, separated by dash signs. The extension of the file is always txt. Examples:
myprefix.txtmyprefix.tag1.txtmyprefix.tag1-tag2.txtDuring the loading process, the loader creates a list of available and matching files, then it sorts them by precedence. Only the last one will be loaded.
If a file name have tags, then it will be validated against the current ibello tags. If a file has a tag which was not specified as an ibello tag, then that file will be not selected. In other words, selected files should not have unspecified tags.
The first selected file will be the one without tags (if any). Then come the files with one or more tags (in alphabetical order). Examples:
myprefix.txt is before myprefix.a.txtmyprefix.a.txt is before myprefix-id.txtmyprefix.a.txt is before myprefix.b.txtmyprefix.c.txt is before myprefix.a-b.txtThe files can be placed into sub-directories, the loader will find them automatically.
fileNamePrefix - prefix of the file nameBinaryTestDataBuilder fromBinary(String fileName)
Returns an object which can be used to load test data from a binary file. For that, we must specify the name of the loaded file.
The loader uses the given file name as a template for the finally loaded file. Based on that, it creates a list of available and matching files, then it sorts them by precedence. Only the last one will be loaded.
The name of the selected files should have the same extension as the given file name, and should start with the first part
of that name. Between them, optionally, one or more tags can be included, separated by dash signs. Between the first part and the
tags there should be a dot. For example, if the given file name is myfile.dat, then these files can be selected:
myfile.datmyfile.tag1.datmyfile.tag1-tag2.datIf a file name have tags, then it will be validated against the current ibello tags. If a file has a tag which was not specified as an ibello tag, then that file will be not selected. In other words, selected files should not have unspecified tags.
The first selected file will be the one without tags (if any). Then come the files with one or more tags (in alphabetical order). Examples:
myfile.dat is before myfile.a.datmyfile.a.dat is before myfile-id.datmyfile.a.dat is before myfile.b.datmyfile.c.dat is before myfile.a-b.datThe files can be placed into sub-directories, the loader will find them automatically.
fileName - the name of the loaded file, with extensionTestDataExpressionEvaluator expression(String expression)
In the expression we can use references with the form: ${...}.
References can be even complex ones, for example: ${person.fullName}.
Complex references are using fields and not getter methods, so the previous example will return with the
content of the fullName field of the person object.
Referenced objects can be defined with the TestDataExpressionEvaluator.withReference(String, Object) method.
If a referenced object is not defined, then ibello tries to read the reference as a configuration property name. In this case, the value of the property will be used.
The result of the evaluation is a Value instance. Specific typed value can be accessed from that interface,
for example with the Value.toInteger() method.
Example:
Screenshot screenshot = new Screenshot("http://ibello.eu", "/var/log/screenshot.png", "12");
// result is 12.0
Double number = expression("${ref.label}")
.withReference("ref", object)
.evaluate()
.toDouble();
// result is "Screenshot path: /var/log/screenshot.png"
String text = expression("Screenshot path: ${ref.path}.")
.withReference("ref", object)
.evaluate()
.toString();
// result is the value of the ibello.report.name configuration property
String configValue = expression("${ibello.report.name}")
.evaluate()
.toString();
expression - the expression we want to evaluateCreated by Kornél Simon, 2022