Class TestMongoConfig
java.lang.Object
org.springframework.data.mongodb.config.MongoConfigurationSupport
org.springframework.data.mongodb.config.AbstractMongoClientConfiguration
me.josephsf.jobportaljosephsfeirtest.config.TestMongoConfig
@Configuration
@Profile("test")
@EnableMongoRepositories(basePackages="me.josephsf.jobportaljosephsfeir.repository")
public class TestMongoConfig
extends org.springframework.data.mongodb.config.AbstractMongoClientConfiguration
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected StringSpecifies the name of the MongoDB database to use for tests.protected Collection<String> Defines the base packages to scan for MongoDB entity mappings.com.mongodb.client.MongoClientCreates and configures a MongoDB client for testing.org.springframework.data.mongodb.core.MongoTemplateCreates a MongoDB template for testing operations.Methods inherited from class org.springframework.data.mongodb.config.AbstractMongoClientConfiguration
createMongoClient, mappingMongoConverter, mongoDbFactory, mongoTemplateMethods inherited from class org.springframework.data.mongodb.config.MongoConfigurationSupport
abbreviateFieldNames, autoIndexCreation, configureClientSettings, configureConverters, customConversions, fieldNamingStrategy, getInitialEntitySet, mongoClientSettings, mongoManagedTypes, mongoMappingContext, scanForEntities
-
Constructor Details
-
TestMongoConfig
public TestMongoConfig()
-
-
Method Details
-
getDatabaseName
Specifies the name of the MongoDB database to use for tests.This method defines a separate database name for the testing environment to ensure that tests don't interfere with development or production data.
- Specified by:
getDatabaseNamein classorg.springframework.data.mongodb.config.MongoConfigurationSupport- Returns:
- the name of the test database
-
mongoClient
Creates and configures a MongoDB client for testing.This method sets up a MongoDB client that connects to a local MongoDB instance running on the default port. For integration tests, this is typically connected to an embedded MongoDB instance provided by libraries like Flapdoodle.
- Overrides:
mongoClientin classorg.springframework.data.mongodb.config.AbstractMongoClientConfiguration- Returns:
- a configured MongoDB client for testing
-
mongoTemplate
Creates a MongoDB template for testing operations.This template is configured to use the test database and client, providing a convenient way to perform MongoDB operations during tests.
- Returns:
- a MongoTemplate configured for the test environment
-
getMappingBasePackages
Defines the base packages to scan for MongoDB entity mappings.This method specifies which package contains the model classes that should be mapped to MongoDB collections.
- Overrides:
getMappingBasePackagesin classorg.springframework.data.mongodb.config.MongoConfigurationSupport- Returns:
- a collection of package names to scan for entity mappings
-