use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultBulkOperationsUnitTests method setUp.
@Before
public void setUp() {
mappingContext = new MongoMappingContext();
mappingContext.afterPropertiesSet();
converter = new MappingMongoConverter(dbRefResolver, mappingContext);
template = new MongoTemplate(factory, converter);
when(factory.getDb()).thenReturn(database);
when(database.getCollection(anyString(), eq(Document.class))).thenReturn(collection);
ops = new DefaultBulkOperations(template, "collection-1", new BulkOperationContext(BulkMode.ORDERED, Optional.of(mappingContext.getPersistentEntity(SomeDomainType.class)), new QueryMapper(converter), new UpdateMapper(converter)));
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultIndexOperationsIntegrationTests method shouldFavorExplicitMappingHintViaClass.
// DATAMONGO-1467
@Test
public void shouldFavorExplicitMappingHintViaClass() {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_TWO), is(true));
IndexDefinition id = new Index().named("partial-with-inheritance").on("k3y", Direction.ASC).partial(of(where("age").gte(10)));
indexOps = new DefaultIndexOperations(template.getMongoDbFactory(), this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class), new QueryMapper(template.getConverter()), MappingToSameCollection.class);
indexOps.ensureIndex(id);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "partial-with-inheritance");
assertThat(info.getPartialFilterExpression()).isEqualTo("{ \"a_g_e\" : { \"$gte\" : 10 } }");
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class DefaultIndexOperationsIntegrationTests method shouldCreateIndexWithCollationCorrectly.
// DATAMONGO-1518
@Test
public void shouldCreateIndexWithCollationCorrectly() {
assumeThat(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR), is(true));
IndexDefinition id = new Index().named("with-collation").on("xyz", Direction.ASC).collation(Collation.of("de_AT").caseFirst(CaseFirst.off()));
new DefaultIndexOperations(template.getMongoDbFactory(), this.template.getCollectionName(DefaultIndexOperationsIntegrationTestsSample.class), new QueryMapper(template.getConverter()), MappingToSameCollection.class);
indexOps.ensureIndex(id);
Document expected = //
new Document("locale", "de_AT").append("caseLevel", //
false).append("caseFirst", //
"off").append("strength", //
3).append("numericOrdering", //
false).append("alternate", //
"non-ignorable").append("maxVariable", //
"punct").append("normalization", //
false).append("backwards", false);
IndexInfo info = findAndReturnIndexInfo(indexOps.getIndexInfo(), "with-collation");
assertThat(info.getCollation()).isPresent();
// version is set by MongoDB server - we remove it to avoid errors when upgrading server version.
Document result = info.getCollation().get();
result.remove("version");
assertThat(result).isEqualTo(expected);
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method convertsUpdateConstraintsUsingConverters.
// DATAMONGO-374
@Test
public void convertsUpdateConstraintsUsingConverters() {
CustomConversions conversions = new MongoCustomConversions(Collections.singletonList(MyConverter.INSTANCE));
this.converter.setCustomConversions(conversions);
this.converter.afterPropertiesSet();
Query query = new Query();
Update update = new Update().set("foo", new AutogenerateableId());
template.updateFirst(query, update, Wrapper.class);
QueryMapper queryMapper = new QueryMapper(converter);
Document reference = queryMapper.getMappedObject(update.getUpdateObject(), Optional.empty());
verify(collection, times(1)).updateOne(Mockito.any(org.bson.Document.class), eq(reference), // .update(Mockito.any(Document.class), eq(reference), anyBoolean(),
Mockito.any(UpdateOptions.class));
// anyBoolean());
}
use of org.springframework.data.mongodb.core.convert.QueryMapper in project spring-data-mongodb by spring-projects.
the class TypeBasedAggregationOperationContextUnitTests method setUp.
@Before
public void setUp() {
this.context = new MongoMappingContext();
this.converter = new MappingMongoConverter(dbRefResolver, context);
this.mapper = new QueryMapper(converter);
}
Aggregations