use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method prepareMappingContext.
private static MongoMappingContext prepareMappingContext(Class<?> type) {
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setInitialEntitySet(Collections.singleton(type));
mappingContext.initialize();
return mappingContext;
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method doesNotCreateIndexForEntityComingFromDifferentMappingContext.
@Test
void doesNotCreateIndexForEntityComingFromDifferentMappingContext() {
MongoMappingContext mappingContext = new MongoMappingContext();
MongoMappingContext personMappingContext = prepareMappingContext(Person.class);
MongoPersistentEntityIndexCreator creator = new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
MongoPersistentEntity<?> entity = personMappingContext.getRequiredPersistentEntity(Person.class);
MappingContextEvent<MongoPersistentEntity<?>, MongoPersistentProperty> event = new MappingContextEvent<MongoPersistentEntity<?>, MongoPersistentProperty>(personMappingContext, entity);
creator.onApplicationEvent(event);
verifyNoInteractions(collection);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method indexCreationShouldNotCreateNewCollectionForNestedIndexStructures.
// DATAMONGO-367
@Test
void indexCreationShouldNotCreateNewCollectionForNestedIndexStructures() {
MongoMappingContext mappingContext = prepareMappingContext(IndexedDocumentWrapper.class);
new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
ArgumentCaptor<String> collectionNameCapturer = ArgumentCaptor.forClass(String.class);
verify(db, times(1)).getCollection(collectionNameCapturer.capture(), any());
assertThat(collectionNameCapturer.getValue()).isEqualTo("indexedDocumentWrapper");
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method buildsIndexDefinitionUsingFieldName.
@Test
void buildsIndexDefinitionUsingFieldName() {
MongoMappingContext mappingContext = prepareMappingContext(Person.class);
new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
assertThat(keysCaptor.getValue()).isNotNull().containsKey("fieldname");
assertThat(optionsCaptor.getValue().getName()).isEqualTo("indexName");
assertThat(optionsCaptor.getValue().isBackground()).isFalse();
assertThat(optionsCaptor.getValue().getExpireAfter(TimeUnit.SECONDS)).isNull();
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method triggersBackgroundIndexingIfConfigured.
// DATAMONGO-554
@Test
void triggersBackgroundIndexingIfConfigured() {
MongoMappingContext mappingContext = prepareMappingContext(AnotherPerson.class);
new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
assertThat(keysCaptor.getValue()).isNotNull().containsKey("lastname");
assertThat(optionsCaptor.getValue().getName()).isEqualTo("lastname");
assertThat(optionsCaptor.getValue().isBackground()).isTrue();
assertThat(optionsCaptor.getValue().getExpireAfter(TimeUnit.SECONDS)).isNull();
}
Aggregations