use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method isIndexCreatorForMappingContextHandedIntoConstructor.
// DATAMONGO-530
@Test
void isIndexCreatorForMappingContextHandedIntoConstructor() {
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.initialize();
MongoPersistentEntityIndexCreator creator = new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
assertThat(creator.isIndexCreatorFor(mappingContext)).isTrue();
assertThat(creator.isIndexCreatorFor(new MongoMappingContext())).isFalse();
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method autoGeneratedIndexNameShouldGenerateNoName.
// DATAMONGO-827
@Test
void autoGeneratedIndexNameShouldGenerateNoName() {
MongoMappingContext mappingContext = prepareMappingContext(EntityWithGeneratedIndexName.class);
new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
assertThat(keysCaptor.getValue()).doesNotContainKey("name").containsKey("lastname");
assertThat(optionsCaptor.getValue().getName()).isNull();
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method expireAfterSecondsIfConfigured.
// DATAMONGO-544
@Test
void expireAfterSecondsIfConfigured() {
MongoMappingContext mappingContext = prepareMappingContext(Milk.class);
new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
assertThat(keysCaptor.getValue()).isNotNull().containsKey("expiry");
assertThat(optionsCaptor.getValue().getExpireAfter(TimeUnit.SECONDS)).isEqualTo(60);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoQueryCreatorUnitTests method assertBindsDistanceToQuery.
private void assertBindsDistanceToQuery(Point point, Distance distance, Query reference) throws Exception {
PartTree tree = new PartTree("findByLocationNearAndFirstname", org.springframework.data.mongodb.repository.Person.class);
Method method = PersonRepository.class.getMethod("findByLocationNearAndFirstname", Point.class, Distance.class, String.class);
MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(PersonRepository.class), new SpelAwareProxyProjectionFactory(), new MongoMappingContext());
MongoParameterAccessor accessor = new MongoParametersParameterAccessor(queryMethod, new Object[] { point, distance, "Dave" });
Query query = new MongoQueryCreator(tree, new ConvertingParameterAccessor(converter, accessor), context).createQuery();
assertThat(query).isEqualTo(query);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class SpringDataMongodbSerializerUnitTests method takesCustomConversionForEnumsIntoAccount.
// DATAMONGO-1485
@Test
public void takesCustomConversionForEnumsIntoAccount() {
MongoMappingContext context = new MongoMappingContext();
MappingMongoConverter converter = new MappingMongoConverter(dbFactory, context);
converter.setCustomConversions(new MongoCustomConversions(Collections.singletonList(new SexTypeWriteConverter())));
converter.afterPropertiesSet();
this.converter = converter;
this.serializer = new SpringDataMongodbSerializer(this.converter);
Object mappedPredicate = serializer.handle(QPerson.person.sex.eq(Sex.FEMALE));
assertThat(mappedPredicate).isInstanceOf(Document.class);
assertThat(((Document) mappedPredicate).get("sex")).isEqualTo("f");
}
Aggregations