Search in sources :

Example 1 with MongoPersistentEntityIndexCreator

use of org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator in project spring-data-mongodb by spring-projects.

the class MongoTemplateUnitTests method registersDefaultEntityIndexCreatorIfApplicationContextHasOneForDifferentMappingContext.

// DATAMONGO-533
@Test
void registersDefaultEntityIndexCreatorIfApplicationContextHasOneForDifferentMappingContext() {
    GenericApplicationContext applicationContext = new GenericApplicationContext();
    applicationContext.getBeanFactory().registerSingleton("foo", new MongoPersistentEntityIndexCreator(new MongoMappingContext(), template));
    applicationContext.refresh();
    GenericApplicationContext spy = spy(applicationContext);
    MongoTemplate mongoTemplate = new MongoTemplate(factory, converter);
    mongoTemplate.setApplicationContext(spy);
    verify(spy, times(1)).addApplicationListener(argThat(new ArgumentMatcher<MongoPersistentEntityIndexCreator>() {

        @Override
        public boolean matches(MongoPersistentEntityIndexCreator argument) {
            return argument.isIndexCreatorFor(mappingContext);
        }
    }));
}
Also used : MongoPersistentEntityIndexCreator(org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) ArgumentMatcher(org.mockito.ArgumentMatcher) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 ArgumentMatcher (org.mockito.ArgumentMatcher)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 MongoPersistentEntityIndexCreator (org.springframework.data.mongodb.core.index.MongoPersistentEntityIndexCreator)1 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)1