Search in sources :

Example 31 with Collation

use of org.springframework.data.mongodb.core.query.Collation in project spring-data-mongodb by spring-projects.

the class SimpleReactiveMongoRepositoryUnitTests method shouldAddDefaultCollationToCountForExampleIfPresent.

// DATAMONGO-1854
@Test
void shouldAddDefaultCollationToCountForExampleIfPresent() {
    when(mongoOperations.count(any(), any(), any())).thenReturn(mono);
    Collation collation = Collation.of("en_US");
    when(entityInformation.getCollation()).thenReturn(collation);
    repository.count(Example.of(new TestDummy())).subscribe();
    ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class);
    verify(mongoOperations).count(query.capture(), any(), any());
    assertThat(query.getValue().getCollation()).contains(collation);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Collation(org.springframework.data.mongodb.core.query.Collation) Test(org.junit.jupiter.api.Test)

Example 32 with Collation

use of org.springframework.data.mongodb.core.query.Collation in project spring-data-mongodb by spring-projects.

the class SimpleReactiveMongoRepositoryUnitTests method shouldAddDefaultCollationToFindForExampleIfPresent.

// DATAMONGO-1854
@Test
void shouldAddDefaultCollationToFindForExampleIfPresent() {
    when(mongoOperations.find(any(), any(), any())).thenReturn(flux);
    Collation collation = Collation.of("en_US");
    when(entityInformation.getCollation()).thenReturn(collation);
    repository.findAll(Example.of(new TestDummy())).subscribe();
    ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class);
    verify(mongoOperations).find(query.capture(), any(), any());
    assertThat(query.getValue().getCollation()).contains(collation);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Collation(org.springframework.data.mongodb.core.query.Collation) Test(org.junit.jupiter.api.Test)

Example 33 with Collation

use of org.springframework.data.mongodb.core.query.Collation in project spring-data-mongodb by spring-projects.

the class SimpleReactiveMongoRepositoryUnitTests method shouldAddDefaultCollationToFindWithSortForExampleIfPresent.

// DATAMONGO-1854
@Test
void shouldAddDefaultCollationToFindWithSortForExampleIfPresent() {
    when(mongoOperations.find(any(), any(), any())).thenReturn(flux);
    Collation collation = Collation.of("en_US");
    when(entityInformation.getCollation()).thenReturn(collation);
    repository.findAll(Example.of(new TestDummy()), Sort.by("nothing")).subscribe();
    ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class);
    verify(mongoOperations).find(query.capture(), any(), any());
    assertThat(query.getValue().getCollation()).contains(collation);
}
Also used : Query(org.springframework.data.mongodb.core.query.Query) Collation(org.springframework.data.mongodb.core.query.Collation) Test(org.junit.jupiter.api.Test)

Aggregations

Collation (org.springframework.data.mongodb.core.query.Collation)33 Query (org.springframework.data.mongodb.core.query.Query)24 Test (org.junit.jupiter.api.Test)19 Document (org.bson.Document)15 Collectors (java.util.stream.Collectors)7 DataAccessException (org.springframework.dao.DataAccessException)7 BasicQuery (org.springframework.data.mongodb.core.query.BasicQuery)7 MongoException (com.mongodb.MongoException)6 WriteConcern (com.mongodb.WriteConcern)6 DeleteResult (com.mongodb.client.result.DeleteResult)6 UpdateResult (com.mongodb.client.result.UpdateResult)6 AggregationOptions (org.springframework.data.mongodb.core.aggregation.AggregationOptions)6 TypedAggregation (org.springframework.data.mongodb.core.aggregation.TypedAggregation)6 Criteria (org.springframework.data.mongodb.core.query.Criteria)5 MongoPersistentEntity (org.springframework.data.mongodb.core.mapping.MongoPersistentEntity)4 FullDocument (com.mongodb.client.model.changestream.FullDocument)3 java.util (java.util)3 Collection (java.util.Collection)3 Bson (org.bson.conversions.Bson)3 BeansException (org.springframework.beans.BeansException)3