Class MongoFlexibleComparisonStrategy
- java.lang.Object
-
- com.lordofthejars.nosqlunit.mongodb.MongoFlexibleComparisonStrategy
-
- All Implemented Interfaces:
com.lordofthejars.nosqlunit.core.ComparisonStrategy<MongoDbConnectionCallback>,MongoComparisonStrategy
public class MongoFlexibleComparisonStrategy extends java.lang.Object implements MongoComparisonStrategy
Comparison strategy that checks that all the expected data exists in the Mongo database. It doesn't compare that all the data stored in the database is included in the expected file, so other data not defined in the expected resource could exist in Mongo. It just assure that the expected data exists.Checks the following assertions:
The annotation '@IgnorePropertyValue(properties = {String...})' allows the user define the properties that should be ignored when checking the expected objects. It accepts two formats for property definition:-
Checks that all the expected collections are present in Mongo DB, but accepts
other collections stored in the database that are not defined in the expected
file.
-
Checks that all the expected objects are present in Mongo DB, but accepts
other objects stored in the same collections that are not defined as expected.
-
For each object checks that all properties set to be ignored its value
exist in the object stored in the database, but it accepts any saved value.
The values of the properties to be ignored should be named following the rules for valid collection and property names defined in document. When more than one object stored in the database matches the expected object after ignoring properties a warning is shown notifying the number of objects that were found.-
collection.property : When are defined both collection and property name
the exclusion will only affect to the indicated collection.
e.g: With @IgnorePropertyValue(properties = {"book.date"}), the property date
will be ignored in each object of the 'book' collection. If other objects in
different collections have the property 'date' it won't be ignored.
-
property : When only is defined the property name it will be excluded
from all objects in any expected collection.
e.g: With @IgnorePropertyValue(properties = {"date"}), the property 'date'
will be ignored in each object, no matter the collection.
- Author:
- Víctor Hernández
-
-
Constructor Summary
Constructors Constructor Description MongoFlexibleComparisonStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancompare(MongoDbConnectionCallback connection, java.io.InputStream dataset)voidsetIgnoreProperties(java.lang.String[] ignorePropertyValues)
-
-
-
Method Detail
-
compare
public boolean compare(MongoDbConnectionCallback connection, java.io.InputStream dataset) throws java.io.IOException
- Specified by:
comparein interfacecom.lordofthejars.nosqlunit.core.ComparisonStrategy<MongoDbConnectionCallback>- Throws:
java.io.IOException
-
setIgnoreProperties
public void setIgnoreProperties(java.lang.String[] ignorePropertyValues)
- Specified by:
setIgnorePropertiesin interfacecom.lordofthejars.nosqlunit.core.ComparisonStrategy<MongoDbConnectionCallback>
-
-