Search in sources :

Example 6 with QueryMapper

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)));
}
Also used : BulkOperationContext(org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) Document(org.bson.Document) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) UpdateMapper(org.springframework.data.mongodb.core.convert.UpdateMapper) Before(org.junit.Before)

Example 7 with QueryMapper

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 } }");
}
Also used : IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Test(org.junit.Test)

Example 8 with QueryMapper

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);
}
Also used : IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Document(org.bson.Document) Test(org.junit.Test)

Example 9 with QueryMapper

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());
}
Also used : BasicQuery(org.springframework.data.mongodb.core.query.BasicQuery) NearQuery(org.springframework.data.mongodb.core.query.NearQuery) Query(org.springframework.data.mongodb.core.query.Query) CustomConversions(org.springframework.data.convert.CustomConversions) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) MongoCustomConversions(org.springframework.data.mongodb.core.convert.MongoCustomConversions) Update(org.springframework.data.mongodb.core.query.Update) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Document(org.bson.Document) UpdateOptions(com.mongodb.client.model.UpdateOptions) FindOneAndUpdateOptions(com.mongodb.client.model.FindOneAndUpdateOptions) Test(org.junit.Test)

Example 10 with QueryMapper

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);
}
Also used : MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MappingMongoConverter(org.springframework.data.mongodb.core.convert.MappingMongoConverter) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Before(org.junit.Before)

Aggregations

QueryMapper (org.springframework.data.mongodb.core.convert.QueryMapper)10 Test (org.junit.Test)6 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)5 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)5 Document (org.bson.Document)4 Before (org.junit.Before)4 Index (org.springframework.data.mongodb.core.index.Index)3 IndexDefinition (org.springframework.data.mongodb.core.index.IndexDefinition)3 IndexInfo (org.springframework.data.mongodb.core.index.IndexInfo)3 BulkOperationContext (org.springframework.data.mongodb.core.DefaultBulkOperations.BulkOperationContext)2 UpdateMapper (org.springframework.data.mongodb.core.convert.UpdateMapper)2 FindOneAndUpdateOptions (com.mongodb.client.model.FindOneAndUpdateOptions)1 UpdateOptions (com.mongodb.client.model.UpdateOptions)1 MongoClient (com.mongodb.reactivestreams.client.MongoClient)1 MongoClients (com.mongodb.reactivestreams.client.MongoClients)1 MongoCollection (com.mongodb.reactivestreams.client.MongoCollection)1 Predicate (java.util.function.Predicate)1 Assertions (org.assertj.core.api.Assertions)1 Assume (org.junit.Assume)1 RunWith (org.junit.runner.RunWith)1