Package org.mongounit
Class MongoUnit
java.lang.Object
org.mongounit.MongoUnit
MongoUnit class contains utilities for manually seeding and performing assertion
matches.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertMatchesDataset(String[] locations, Class<?> testClass) Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the JSON datasets contained in files pointed to by the provided 'locations' array of paths.static voidassertMatchesDataset(String[] locations, LocationType locationType, Class<?> relativePackageClass) Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the JSON datasets contained in files pointed to by the provided 'locations' array of paths.static voidassertMatchesDataset(String location, Class<?> testClass) Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the JSON datasets contained in files pointed to by the provided 'location' path.static voidassertMatchesDataset(List<MongoUnitCollection> expectedDatasets) Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the dataset collectively contained in the provided 'datasets'.static voidAssert database is empty.static voidFinds and drops all of the collections in the database that the MongoUnit framework is configured to automatically connect to.static List<MongoUnitCollection> loadDatasetFromLocation(String location, Class<?> testClass) Returns a list ofMongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths.static List<MongoUnitCollection> loadDatasetFromLocations(String[] locations, Class<?> testClass) Returns a list ofMongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths.static List<MongoUnitCollection> loadDatasetFromLocations(String[] locations, LocationType locationType, Class<?> relativePackageClass) Returns a list ofMongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths.static List<MongoUnitCollection> seedWithDataset(String[] locations, Class<?> testClass) Seeds the database with the JSON-based datasets pointed to by the provided 'locations' path array.static List<MongoUnitCollection> seedWithDataset(String[] locations, LocationType locationType, Class<?> relativePackageClass) Seeds the database with the JSON-based datasets pointed to by the provided 'locations' path array.static List<MongoUnitCollection> seedWithDataset(String location, Class<?> testClass) Seeds the database with the JSON-based datasets pointed to by the provided 'locations' path array.
-
Constructor Details
-
MongoUnit
public MongoUnit()
-
-
Method Details
-
dropAllCollectionsInDatabase
public static void dropAllCollectionsInDatabase()Finds and drops all of the collections in the database that the MongoUnit framework is configured to automatically connect to. -
seedWithDataset
public static List<MongoUnitCollection> seedWithDataset(String[] locations, LocationType locationType, Class<?> relativePackageClass) throws MongoUnitException Seeds the database with the JSON-based datasets pointed to by the provided 'locations' path array. Returns a list ofMongoUnitCollections that can optionally be reused for assertions in the 'assertMatches*' methods.- Parameters:
locations- Array paths to the files containing datasets.locationType- Type of location the provided 'locations' are.relativePackageClass- If 'locationType' is 'CLASS', this is the class type whose packaged location should be used for relativity of the 'location' path. Otherwise, it's ignored and can be null.- Returns:
- List of
MongoUnitCollections based on the data pointed to by provided 'locations'. - Throws:
MongoUnitException- If something goes wrong with loading datasets from the specified locations.
-
seedWithDataset
Seeds the database with the JSON-based datasets pointed to by the provided 'locations' path array. Returns a list ofMongoUnitCollections that can optionally be reused for assertions in the 'assertMatches*' methods.- Parameters:
locations- Array of paths to the files containing datasets. The locations type is 'CLASS'. See javadoc org.mongounit.LocationType#CLASS for more detail.testClass- Class instance of the test class.- Returns:
- List of
MongoUnitCollections based on the data pointed to by provided 'locations' and 'testClass'.
-
seedWithDataset
Seeds the database with the JSON-based datasets pointed to by the provided 'locations' path array. Returns a list ofMongoUnitCollections that can optionally be reused for assertions in the 'assertMatches*' methods.- Parameters:
location- Path to the file containing a dataset. The location type is 'CLASS'. See javadoc org.mongounit.LocationType#CLASS for more detail.testClass- Class instance of the test class.- Returns:
- List of
MongoUnitCollections based on the data pointed to by provided 'location' and 'testClass'.
-
assertMatchesDataset
public static void assertMatchesDataset(String[] locations, LocationType locationType, Class<?> relativePackageClass) throws MongoUnitException Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the JSON datasets contained in files pointed to by the provided 'locations' array of paths.- Parameters:
locations- Array paths to the files containing datasets.locationType- Type of location the provided 'locations' are.relativePackageClass- If 'locationType' is 'CLASS', this is the class type whose package should be used for package relative 'location' path. Otherwise, it's ignored and can be null.- Throws:
MongoUnitException- If something goes wrong with loading datasets from the specified locations.
-
assertMatchesDataset
public static void assertMatchesDataset(String[] locations, Class<?> testClass) throws MongoUnitException Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the JSON datasets contained in files pointed to by the provided 'locations' array of paths. The locations type is 'CLASS'. See javadoc org.mongounit.LocationType#CLASS for more detail.- Parameters:
locations- Array paths to the files containing datasets. The locations type is 'CLASS' . See javadoc org.mongounit.LocationType#CLASS for more detail.testClass- Class instance of the test class.- Throws:
MongoUnitException- If something goes wrong with loading datasets from the specified locations.
-
assertMatchesDataset
public static void assertMatchesDataset(String location, Class<?> testClass) throws MongoUnitException Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the JSON datasets contained in files pointed to by the provided 'location' path. The location type is 'CLASS'. See javadoc org.mongounit.LocationType#CLASS for more detail.- Parameters:
location- Path to the file containing a dataset. The location type is 'CLASS'. See javadoc org.mongounit.LocationType#CLASS for more detail.testClass- Class instance of the test class.- Throws:
MongoUnitException- If something goes wrong with loading the dataset from the specified location.
-
assertMatchesDataset
public static void assertMatchesDataset(List<MongoUnitCollection> expectedDatasets) throws MongoUnitException Asserts that whatever is currently in the database connected to by the MongoUnit framework matches the dataset collectively contained in the provided 'datasets'.- Parameters:
expectedDatasets- List ofMongoUnitCollections that collectively represent the dataset with which to compare the actual database state with. Note that theMongoUnitCollections can repeat the same-named collection more than once. This method will combine the documents in the same-named collections into 1 same-named collection while keeping the original order of the documents.- Throws:
MongoUnitException- If something goes wrong interpreting the comparisons contained in the provided 'datasets'.
-
assertMatchesEmptyDataset
Assert database is empty.- Throws:
MongoUnitException- If something goes wrong during the assertion.
-
loadDatasetFromLocations
public static List<MongoUnitCollection> loadDatasetFromLocations(String[] locations, LocationType locationType, Class<?> relativePackageClass) throws MongoUnitException Returns a list ofMongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths.- Parameters:
locations- Array paths to the files containing datasets.locationType- Type of location the provided 'locations' are.relativePackageClass- If 'locationType' is 'CLASS', this is the class type whose package should be used for package relative 'location' path. Otherwise, it's ignored and can be 'null'.- Returns:
- List of
MongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths. - Throws:
MongoUnitException- If something goes wrong with loading datasets from the specified 'locations'.
-
loadDatasetFromLocations
public static List<MongoUnitCollection> loadDatasetFromLocations(String[] locations, Class<?> testClass) throws MongoUnitException Returns a list ofMongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths. The locations type is 'CLASS'. See javadoc org .mongounit.LocationType#CLASS for more detail.- Parameters:
locations- Array paths to the files containing datasets. The locations type is 'CLASS' . See javadoc org.mongounit.LocationType#CLASS for more detail.testClass- Class instance of the test class.- Returns:
- List of
MongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths. - Throws:
MongoUnitException- If something goes wrong with loading datasets from the specified 'locations'.
-
loadDatasetFromLocation
public static List<MongoUnitCollection> loadDatasetFromLocation(String location, Class<?> testClass) throws MongoUnitException Returns a list ofMongoUnitCollections that represent the JSON-based data pointed to by the provided 'locations' array of paths. The location type is 'CLASS'. See javadoc org.mongounit.LocationType#CLASS for more detail.- Parameters:
location- Path to the file containing a dataset. The location type is 'CLASS'. See javadoc org.mongounit.LocationType#CLASS for more detail.testClass- Class instance of the test class.- Returns:
- List of
MongoUnitCollections that represent the JSON-based data pointed to by the provided 'location' path. - Throws:
MongoUnitException- If something goes wrong with loading dataset from the specified 'location'.
-