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
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    Specifies 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.MongoClient
    Creates and configures a MongoDB client for testing.
    org.springframework.data.mongodb.core.MongoTemplate
    Creates a MongoDB template for testing operations.

    Methods inherited from class org.springframework.data.mongodb.config.AbstractMongoClientConfiguration

    createMongoClient, mappingMongoConverter, mongoDbFactory, mongoTemplate

    Methods inherited from class org.springframework.data.mongodb.config.MongoConfigurationSupport

    abbreviateFieldNames, autoIndexCreation, configureClientSettings, configureConverters, customConversions, fieldNamingStrategy, getInitialEntitySet, mongoClientSettings, mongoManagedTypes, mongoMappingContext, scanForEntities

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TestMongoConfig

      public TestMongoConfig()
  • Method Details

    • getDatabaseName

      protected String 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:
      getDatabaseName in class org.springframework.data.mongodb.config.MongoConfigurationSupport
      Returns:
      the name of the test database
    • mongoClient

      @Bean @Primary public com.mongodb.client.MongoClient 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:
      mongoClient in class org.springframework.data.mongodb.config.AbstractMongoClientConfiguration
      Returns:
      a configured MongoDB client for testing
    • mongoTemplate

      @Bean public org.springframework.data.mongodb.core.MongoTemplate 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

      protected Collection<String> 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:
      getMappingBasePackages in class org.springframework.data.mongodb.config.MongoConfigurationSupport
      Returns:
      a collection of package names to scan for entity mappings