Package org.mongounit
Annotation Interface AssertMatchesDataset
@Retention(RUNTIME)
@Target({TYPE,METHOD})
@Repeatable(AssertMatchesDatasets.class)
public @interface AssertMatchesDataset
AssertMatchesDataset
annotation specifies location(s) of a JSON-based file(s) with data
to match the state of the database with.
It can be used on a class, on a method, or in combination of the two, which would have a
cumulative effect, i.e., the data pointed to by the method annotation would be added to the data
pointed to by the class annotation.
There is also an option to trigger assertion with no additional dataset by setting this
annotation's 'additionalDataset' to 'false'. In such a case, previously set assertion datasets
(if any at all) are used. This can be used to verify that nothing exists in the database or if
the dataset is coming from SeedWithDataset
annotation with the 'reuseForAssertion' set to
'true'.
If neither the target test method nor its containing target test class is annotated with this
annotation, no automatic assertion takes place.-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionboolean
Returns true to indicate additional assertion dataset should be used for this assertion based on the 'value' or 'locations' pointed to by this annotation, false if no additional dataset should be loaded.String[]
List of locations of JSON files that contain the dataset to match the state the database with.String[]
List of locations of JSON files that contain the dataset to match the state the database with.
-
Element Details
-
value
List of locations of JSON files that contain the dataset to match the state the database with. Specifying this annotation on a class or a method without providing at least a single location should cause the MongoUnit framework to look for a default file named 'ClassName-expected.json' or 'methodName-expected.json' (depending on the location of the annotation). The directory in which this file will be looked for depends on the provided 'locationType'. If 'locationType' is 'CLASSPATH_ROOT', the file will be looked for at the classpath root. If the 'locationType' is 'CLASS', the file will be looked for at theclasspath root plus the package structure along with class name (or 'name' specified byMongoUnitTest
), i.e., if the fully qualified name of the test class is 'com.mytest.MyIT' and this value is selected, the file will be searched for in the '/com/mytest/MyIT' folder relative to the root of the classpath. If 'com.mytest.MyIT' class'MongoUnitTest
annotation specifies 'name' of 'test1', the file will be searched for in the '/com/mytest/test1' folder relative to the root of the classpath. If the 'locationType' is 'ABSOLUTE', the file will be looked for in the root directory, i.e ., '/'. If the MongoUnit framework fails to find any of the dataset file(s), an exception will be thrown. If the desired assertion state is an empty dataset, set 'additionalDataset = false' and omit setting this property. Multiple locations have a cumulative effect on the data, i.e., the data is sequentially combined in the order specified in the 'locations' array before a match assertion is made.- Returns:
- List of locations of JSON files that contain the dataset to match the state the database with.
- Default:
{}
-
locations
List of locations of JSON files that contain the dataset to match the state the database with. Specifying this annotation on a class or a method without providing at least a single location should cause the MongoUnit framework to look for a default file named 'ClassName-expected.json' or 'methodName-expected.json' (depending on the location of the annotation). The directory in which this file will be looked for depends on the provided 'locationType'. If 'locationType' is 'CLASSPATH_ROOT', the file will be looked for at the classpath root. If the 'locationType' is 'CLASS', the file will be looked for at theclasspath root plus the package structure along with class name (or 'name' specified byMongoUnitTest
), i.e., if the fully qualified name of the test class is 'com.mytest.MyIT' and this value is selected, the file will be searched for in the '/com/mytest/MyIT' folder relative to the root of the classpath. If 'com.mytest.MyIT' class'MongoUnitTest
annotation specifies 'name' of 'test1', the file will be searched for in the '/com/mytest/test1' folder relative to the root of the classpath. If the 'locationType' is 'ABSOLUTE', the file will be looked for in the root directory, i.e ., '/'. If the MongoUnit framework fails to find any of the dataset file(s), an exception will be thrown. If the desired assertion state is an empty dataset, set 'additionalDataset = false' and omit setting this property. Multiple locations have a cumulative effect on the data, i.e., the data is sequentially combined in the order specified in the 'locations' array before a match assertion is made.- Returns:
- List of locations of JSON files that contain the dataset to match the state the database with.
- Default:
{}
-
locationType
LocationType locationType- Returns:
- Dictates how to treat paths specified in 'locations' or its alias 'value'.
- Default:
CLASS
-
additionalDataset
boolean additionalDatasetReturns true to indicate additional assertion dataset should be used for this assertion based on the 'value' or 'locations' pointed to by this annotation, false if no additional dataset should be loaded.- Returns:
- Flag to indicate if additional assertion dataset should be used for this assertion, i.e., if the datasets (or lack thereof) that have already been defined should be used to assert match without any additional datasets or if additional datasets, pointed to by this annotation, should be loaded. If the value of this property is set to 'false', neither the 'locations' nor 'value' properties can be set to anything other than their default, i.e., empty arrays. In other words, setting 'additionalDataset' to 'false' is mutually exclusive of 'locations' and 'value' properties.
- Default:
true
-