Search in sources :

Example 11 with Collation

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

the class DefaultReactiveIndexOperationsTests method shouldCreateIndexWithCollationCorrectly.

// DATAMONGO-1518
@Test
public void shouldCreateIndexWithCollationCorrectly() {
    assumeTrue(mongoVersion.isGreaterThanOrEqualTo(THREE_DOT_FOUR));
    IndexDefinition id = new Index().named("with-collation").on("xyz", Direction.ASC).collation(Collation.of("de_AT").caseFirst(CaseFirst.off()));
    StepVerifier.create(indexOps.ensureIndex(id)).expectNextCount(1).verifyComplete();
    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);
    // 
    StepVerifier.create(indexOps.getIndexInfo().filter(this.indexByName("with-collation"))).consumeNextWith(indexInfo -> {
        assertThat(indexInfo.getCollation()).isPresent();
        // version is set by MongoDB server - we remove it to avoid errors when upgrading server version.
        Document result = indexInfo.getCollation().get();
        result.remove("version");
        assertThat(result).isEqualTo(expected);
    }).verifyComplete();
}
Also used : Document(org.bson.Document) StepVerifier(reactor.test.StepVerifier) AbstractReactiveMongoConfiguration(org.springframework.data.mongodb.config.AbstractReactiveMongoConfiguration) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) MongoClients(com.mongodb.reactivestreams.client.MongoClients) Collation(org.springframework.data.mongodb.core.query.Collation) MongoCollection(com.mongodb.reactivestreams.client.MongoCollection) Index(org.springframework.data.mongodb.core.index.Index) MongoClient(com.mongodb.reactivestreams.client.MongoClient) SpringJUnit4ClassRunner(org.springframework.test.context.junit4.SpringJUnit4ClassRunner) Assertions(org.assertj.core.api.Assertions) Version(org.springframework.data.util.Version) Assume(org.junit.Assume) Direction(org.springframework.data.domain.Sort.Direction) CaseFirst(org.springframework.data.mongodb.core.query.Collation.CaseFirst) IndexInfo(org.springframework.data.mongodb.core.index.IndexInfo) Before(org.junit.Before) QueryMapper(org.springframework.data.mongodb.core.convert.QueryMapper) Predicate(java.util.function.Predicate) Test(org.junit.Test) Criteria(org.springframework.data.mongodb.core.query.Criteria) Field(org.springframework.data.mongodb.core.mapping.Field) Configuration(org.springframework.context.annotation.Configuration) PartialIndexFilter(org.springframework.data.mongodb.core.index.PartialIndexFilter) ContextConfiguration(org.springframework.test.context.ContextConfiguration) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) IndexDefinition(org.springframework.data.mongodb.core.index.IndexDefinition) Index(org.springframework.data.mongodb.core.index.Index) Document(org.bson.Document) Test(org.junit.Test)

Aggregations

Document (org.bson.Document)11 Collation (org.springframework.data.mongodb.core.query.Collation)11 DataAccessException (org.springframework.dao.DataAccessException)8 DeleteResult (com.mongodb.client.result.DeleteResult)7 UpdateResult (com.mongodb.client.result.UpdateResult)7 ClientSession (com.mongodb.session.ClientSession)6 JSONParseException (com.mongodb.util.JSONParseException)6 java.util (java.util)6 Entry (java.util.Map.Entry)6 Collectors (java.util.stream.Collectors)6 NonNull (lombok.NonNull)6 RequiredArgsConstructor (lombok.RequiredArgsConstructor)6 BsonValue (org.bson.BsonValue)6 Codec (org.bson.codecs.Codec)6 Bson (org.bson.conversions.Bson)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 BeansException (org.springframework.beans.BeansException)6 ApplicationContext (org.springframework.context.ApplicationContext)6 ApplicationContextAware (org.springframework.context.ApplicationContextAware)6