Class MongoDBTestBase
java.lang.Object
org.mongojack.MongoDBTestBase
- Direct Known Subclasses:
TestAggregate, TestAggregationBuilder, TestBsonSerializers, TestCustomObjectMapper, TestDBCursor, TestDBProjection, TestDBQuery, TestDBRefHandling, TestDBSort, TestDBUpdate, TestDBUpdateSerialization, TestIdAnnotatedClass, TestJacksonCodecRegistry, TestJacksonMongoCollection, TestJacksonMongoCollectionCustomObjectMapper, TestJavaTimeHandling, TestJsonViews, TestMapReduce, TestObjectIdHandling, TestParsingAndGenerating, TestParsingAndGeneratingPolymorphicTypes, TestQuerySerialization, TestUUIDHandling
Base class for unit tests that run against MongoDB. Assumes there is a
MongoDB instance listening on the default port on localhost, and that we can
do whatever we want to a database called "unittest".
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected com.mongodb.client.MongoDatabaseprotected com.mongodb.client.MongoClientprotected org.bson.UuidRepresentation -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected <T> JacksonMongoCollection<T> configure(JacksonMongoCollection<T> collection) voidvoidprotected <T> JacksonMongoCollection<T> getCollection(Class<T> type) protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, String collectionName) protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, JacksonMongoCollection.JacksonMongoCollectionBuilder builder) protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, tools.jackson.databind.ObjectMapper mapper) protected <T> JacksonMongoCollection<T> getCollectionWithView(Class<T> type, Class<?> view) protected <T> com.mongodb.client.MongoCollection<T> getMongoCollection(Class<T> documentClass) Get a collection with a random name.protected <T> com.mongodb.client.MongoCollection<T> getMongoCollection(String name, Class<T> documentClass) Get a collection with the given name, and store it, so that it will be dropped in clean upprotected com.mongodb.client.MongoCollection<org.bson.Document> static voidstartDb()
-
Field Details
-
mongo
protected com.mongodb.client.MongoClient mongo -
db
protected com.mongodb.client.MongoDatabase db -
uuidRepresentation
protected org.bson.UuidRepresentation uuidRepresentation
-
-
Constructor Details
-
MongoDBTestBase
public MongoDBTestBase()
-
-
Method Details
-
startDb
@BeforeAll public static void startDb() -
connectToDb
@BeforeEach public void connectToDb() -
disconnectFromDb
@AfterEach public void disconnectFromDb() -
getMongoCollection
-
getMongoCollection
Get a collection with a random name. Should grant some degree of isolation from tests running in parallel.- Returns:
- The collection
-
configure
-
getCollection
-
getCollection
protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, JacksonMongoCollection.JacksonMongoCollectionBuilder builder) -
getCollectionWithView
-
getCollection
-
getCollection
protected <T> JacksonMongoCollection<T> getCollection(Class<T> type, tools.jackson.databind.ObjectMapper mapper) -
getUnderlyingCollection
protected com.mongodb.client.MongoCollection<org.bson.Document> getUnderlyingCollection(JacksonMongoCollection<?> coll)
-