Browse Source
The collation can now also be configured on entity level and gets applied via MongoTemplate. However one can alway override a default collation by adding the collation explicitly to either the Query or one of the Options available for various operations. When it comes to the repository level the hierarchy is method parameter over query annotation over entity metadata. Remove collation annotation in favor of attributes of Query / Document. Original pull request: #644.pull/743/head
28 changed files with 1681 additions and 150 deletions
@ -0,0 +1,121 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2019 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package org.springframework.data.mongodb.core; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.*; |
||||||
|
import static org.mockito.Mockito.*; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import org.bson.Document; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.ArgumentCaptor; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
import org.springframework.data.domain.Sort.Direction; |
||||||
|
import org.springframework.data.mongodb.MongoDbFactory; |
||||||
|
import org.springframework.data.mongodb.core.convert.DefaultDbRefResolver; |
||||||
|
import org.springframework.data.mongodb.core.convert.MappingMongoConverter; |
||||||
|
import org.springframework.data.mongodb.core.index.Index; |
||||||
|
import org.springframework.data.mongodb.core.mapping.Field; |
||||||
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; |
||||||
|
import org.springframework.data.mongodb.core.query.Collation; |
||||||
|
|
||||||
|
import com.mongodb.client.MongoCollection; |
||||||
|
import com.mongodb.client.MongoDatabase; |
||||||
|
import com.mongodb.client.model.IndexOptions; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Christoph Strobl |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.class) |
||||||
|
public class DefaultIndexOperationsUnitTests { |
||||||
|
|
||||||
|
MongoTemplate template; |
||||||
|
|
||||||
|
@Mock MongoDbFactory factory; |
||||||
|
@Mock MongoDatabase db; |
||||||
|
@Mock MongoCollection<Document> collection; |
||||||
|
|
||||||
|
MongoExceptionTranslator exceptionTranslator = new MongoExceptionTranslator(); |
||||||
|
MappingMongoConverter converter; |
||||||
|
MongoMappingContext mappingContext; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() { |
||||||
|
|
||||||
|
when(factory.getDb()).thenReturn(db); |
||||||
|
when(factory.getExceptionTranslator()).thenReturn(exceptionTranslator); |
||||||
|
when(db.getCollection(any(), any(Class.class))).thenReturn(collection); |
||||||
|
when(collection.createIndex(any(), any(IndexOptions.class))).thenReturn("OK"); |
||||||
|
|
||||||
|
this.mappingContext = new MongoMappingContext(); |
||||||
|
this.converter = spy(new MappingMongoConverter(new DefaultDbRefResolver(factory), mappingContext)); |
||||||
|
this.template = new MongoTemplate(factory, converter); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void ensureIndexDoesNotSetCollectionIfNoDefaultDefined() { |
||||||
|
|
||||||
|
indexOpsFor(Jedi.class).ensureIndex(new Index("firstname", Direction.DESC)); |
||||||
|
|
||||||
|
ArgumentCaptor<IndexOptions> options = ArgumentCaptor.forClass(IndexOptions.class); |
||||||
|
verify(collection).createIndex(any(), options.capture()); |
||||||
|
|
||||||
|
assertThat(options.getValue().getCollation()).isNull(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void ensureIndexUsesDefaultCollationIfNoneDefinedInOptions() { |
||||||
|
|
||||||
|
indexOpsFor(Sith.class).ensureIndex(new Index("firstname", Direction.DESC)); |
||||||
|
|
||||||
|
ArgumentCaptor<IndexOptions> options = ArgumentCaptor.forClass(IndexOptions.class); |
||||||
|
verify(collection).createIndex(any(), options.capture()); |
||||||
|
|
||||||
|
assertThat(options.getValue().getCollation()) |
||||||
|
.isEqualTo(com.mongodb.client.model.Collation.builder().locale("de_AT").build()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void ensureIndexDoesNotUseDefaultCollationIfExplicitlySpecifiedInTheIndex() { |
||||||
|
|
||||||
|
indexOpsFor(Sith.class).ensureIndex(new Index("firstname", Direction.DESC).collation(Collation.of("en_US"))); |
||||||
|
|
||||||
|
ArgumentCaptor<IndexOptions> options = ArgumentCaptor.forClass(IndexOptions.class); |
||||||
|
verify(collection).createIndex(any(), options.capture()); |
||||||
|
|
||||||
|
assertThat(options.getValue().getCollation()) |
||||||
|
.isEqualTo(com.mongodb.client.model.Collation.builder().locale("en_US").build()); |
||||||
|
} |
||||||
|
|
||||||
|
private DefaultIndexOperations indexOpsFor(Class<?> type) { |
||||||
|
return new DefaultIndexOperations(template, template.getCollectionName(type), type); |
||||||
|
} |
||||||
|
|
||||||
|
@Data |
||||||
|
static class Jedi { |
||||||
|
@Field("firstname") String name; |
||||||
|
} |
||||||
|
|
||||||
|
@org.springframework.data.mongodb.core.mapping.Document(collation = "de_AT") |
||||||
|
static class Sith { |
||||||
|
@Field("firstname") String name; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,126 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2019 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package org.springframework.data.mongodb.core; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.*; |
||||||
|
import static org.mockito.Mockito.*; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import org.bson.Document; |
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.ArgumentCaptor; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
import org.reactivestreams.Publisher; |
||||||
|
import org.springframework.data.domain.Sort.Direction; |
||||||
|
import org.springframework.data.mongodb.ReactiveMongoDatabaseFactory; |
||||||
|
import org.springframework.data.mongodb.core.convert.MappingMongoConverter; |
||||||
|
import org.springframework.data.mongodb.core.convert.NoOpDbRefResolver; |
||||||
|
import org.springframework.data.mongodb.core.convert.QueryMapper; |
||||||
|
import org.springframework.data.mongodb.core.index.Index; |
||||||
|
import org.springframework.data.mongodb.core.mapping.Field; |
||||||
|
import org.springframework.data.mongodb.core.mapping.MongoMappingContext; |
||||||
|
import org.springframework.data.mongodb.core.query.Collation; |
||||||
|
|
||||||
|
import com.mongodb.client.model.IndexOptions; |
||||||
|
import com.mongodb.reactivestreams.client.MongoCollection; |
||||||
|
import com.mongodb.reactivestreams.client.MongoDatabase; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Christoph Strobl |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.class) |
||||||
|
public class DefaultReactiveIndexOperationsUnitTests { |
||||||
|
|
||||||
|
ReactiveMongoTemplate template; |
||||||
|
|
||||||
|
@Mock ReactiveMongoDatabaseFactory factory; |
||||||
|
@Mock MongoDatabase db; |
||||||
|
@Mock MongoCollection<Document> collection; |
||||||
|
@Mock Publisher publisher; |
||||||
|
|
||||||
|
MongoExceptionTranslator exceptionTranslator = new MongoExceptionTranslator(); |
||||||
|
MappingMongoConverter converter; |
||||||
|
MongoMappingContext mappingContext; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() { |
||||||
|
|
||||||
|
when(factory.getMongoDatabase()).thenReturn(db); |
||||||
|
when(factory.getExceptionTranslator()).thenReturn(exceptionTranslator); |
||||||
|
when(db.getCollection(any(), any(Class.class))).thenReturn(collection); |
||||||
|
when(collection.createIndex(any(), any(IndexOptions.class))).thenReturn(publisher); |
||||||
|
|
||||||
|
this.mappingContext = new MongoMappingContext(); |
||||||
|
this.converter = spy(new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext)); |
||||||
|
this.template = new ReactiveMongoTemplate(factory, converter); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void ensureIndexDoesNotSetCollectionIfNoDefaultDefined() { |
||||||
|
|
||||||
|
indexOpsFor(Jedi.class).ensureIndex(new Index("firstname", Direction.DESC)).subscribe(); |
||||||
|
|
||||||
|
ArgumentCaptor<IndexOptions> options = ArgumentCaptor.forClass(IndexOptions.class); |
||||||
|
verify(collection).createIndex(any(), options.capture()); |
||||||
|
|
||||||
|
assertThat(options.getValue().getCollation()).isNull(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void ensureIndexUsesDefaultCollationIfNoneDefinedInOptions() { |
||||||
|
|
||||||
|
indexOpsFor(Sith.class).ensureIndex(new Index("firstname", Direction.DESC)).subscribe(); |
||||||
|
|
||||||
|
ArgumentCaptor<IndexOptions> options = ArgumentCaptor.forClass(IndexOptions.class); |
||||||
|
verify(collection).createIndex(any(), options.capture()); |
||||||
|
|
||||||
|
assertThat(options.getValue().getCollation()) |
||||||
|
.isEqualTo(com.mongodb.client.model.Collation.builder().locale("de_AT").build()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void ensureIndexDoesNotUseDefaultCollationIfExplicitlySpecifiedInTheIndex() { |
||||||
|
|
||||||
|
indexOpsFor(Sith.class).ensureIndex(new Index("firstname", Direction.DESC).collation(Collation.of("en_US"))) |
||||||
|
.subscribe(); |
||||||
|
|
||||||
|
ArgumentCaptor<IndexOptions> options = ArgumentCaptor.forClass(IndexOptions.class); |
||||||
|
verify(collection).createIndex(any(), options.capture()); |
||||||
|
|
||||||
|
assertThat(options.getValue().getCollation()) |
||||||
|
.isEqualTo(com.mongodb.client.model.Collation.builder().locale("en_US").build()); |
||||||
|
} |
||||||
|
|
||||||
|
private DefaultReactiveIndexOperations indexOpsFor(Class<?> type) { |
||||||
|
return new DefaultReactiveIndexOperations(template, template.getCollectionName(type), |
||||||
|
new QueryMapper(template.getConverter()), type); |
||||||
|
} |
||||||
|
|
||||||
|
@Data |
||||||
|
static class Jedi { |
||||||
|
@Field("firstname") String name; |
||||||
|
} |
||||||
|
|
||||||
|
@org.springframework.data.mongodb.core.mapping.Document(collation = "de_AT") |
||||||
|
static class Sith { |
||||||
|
@Field("firstname") String name; |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,139 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2019 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package org.springframework.data.mongodb.repository.support; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.*; |
||||||
|
import static org.mockito.ArgumentMatchers.any; |
||||||
|
import static org.mockito.Mockito.*; |
||||||
|
|
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.ArgumentCaptor; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
import org.springframework.data.domain.Example; |
||||||
|
import org.springframework.data.domain.PageRequest; |
||||||
|
import org.springframework.data.domain.Sort; |
||||||
|
import org.springframework.data.mongodb.core.MongoOperations; |
||||||
|
import org.springframework.data.mongodb.core.query.Collation; |
||||||
|
import org.springframework.data.mongodb.core.query.Query; |
||||||
|
import org.springframework.data.mongodb.repository.query.MongoEntityInformation; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Christoph Strobl |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.class) |
||||||
|
public class SimpleMongoRepositoryUnitTests { |
||||||
|
|
||||||
|
SimpleMongoRepository<Object, Object> repository; |
||||||
|
@Mock MongoOperations mongoOperations; |
||||||
|
@Mock MongoEntityInformation<Object, Object> entityInformation; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() { |
||||||
|
repository = new SimpleMongoRepository<>(entityInformation, mongoOperations); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToCountForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.count(Example.of(new TestDummy())); |
||||||
|
|
||||||
|
ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class); |
||||||
|
verify(mongoOperations).count(query.capture(), any(), any()); |
||||||
|
|
||||||
|
assertThat(query.getValue().getCollation()).contains(collation); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToExistsForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.exists(Example.of(new TestDummy())); |
||||||
|
|
||||||
|
ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class); |
||||||
|
verify(mongoOperations).exists(query.capture(), any(), any()); |
||||||
|
|
||||||
|
assertThat(query.getValue().getCollation()).contains(collation); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToFindForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.findAll(Example.of(new TestDummy())); |
||||||
|
|
||||||
|
ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class); |
||||||
|
verify(mongoOperations).find(query.capture(), any(), any()); |
||||||
|
|
||||||
|
assertThat(query.getValue().getCollation()).contains(collation); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToFindWithSortForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.findAll(Example.of(new TestDummy()), Sort.by("nothing")); |
||||||
|
|
||||||
|
ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class); |
||||||
|
verify(mongoOperations).find(query.capture(), any(), any()); |
||||||
|
|
||||||
|
assertThat(query.getValue().getCollation()).contains(collation); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToFindWithPageableForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.findAll(Example.of(new TestDummy()), PageRequest.of(1, 1, Sort.by("nothing"))); |
||||||
|
|
||||||
|
ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class); |
||||||
|
verify(mongoOperations).find(query.capture(), any(), any()); |
||||||
|
|
||||||
|
assertThat(query.getValue().getCollation()).contains(collation); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToFindOneForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.findOne(Example.of(new TestDummy())); |
||||||
|
|
||||||
|
ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class); |
||||||
|
verify(mongoOperations).findOne(query.capture(), any(), any()); |
||||||
|
|
||||||
|
assertThat(query.getValue().getCollation()).contains(collation); |
||||||
|
} |
||||||
|
|
||||||
|
static class TestDummy { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
@ -0,0 +1,150 @@ |
|||||||
|
/* |
||||||
|
* Copyright 2019. the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
|
||||||
|
/* |
||||||
|
* Copyright 2019 the original author or authors. |
||||||
|
* |
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
||||||
|
* you may not use this file except in compliance with the License. |
||||||
|
* You may obtain a copy of the License at |
||||||
|
* |
||||||
|
* https://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* |
||||||
|
* Unless required by applicable law or agreed to in writing, software |
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
* See the License for the specific language governing permissions and |
||||||
|
* limitations under the License. |
||||||
|
*/ |
||||||
|
package org.springframework.data.mongodb.repository.support; |
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.*; |
||||||
|
import static org.mockito.ArgumentMatchers.any; |
||||||
|
import static org.mockito.Mockito.*; |
||||||
|
|
||||||
|
import reactor.core.publisher.Flux; |
||||||
|
import reactor.core.publisher.Mono; |
||||||
|
|
||||||
|
import org.junit.Before; |
||||||
|
import org.junit.Test; |
||||||
|
import org.junit.runner.RunWith; |
||||||
|
import org.mockito.ArgumentCaptor; |
||||||
|
import org.mockito.Mock; |
||||||
|
import org.mockito.junit.MockitoJUnitRunner; |
||||||
|
import org.springframework.data.domain.Example; |
||||||
|
import org.springframework.data.domain.Sort; |
||||||
|
import org.springframework.data.mongodb.core.ReactiveMongoOperations; |
||||||
|
import org.springframework.data.mongodb.core.query.Collation; |
||||||
|
import org.springframework.data.mongodb.core.query.Query; |
||||||
|
import org.springframework.data.mongodb.repository.query.MongoEntityInformation; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author Christoph Strobl |
||||||
|
*/ |
||||||
|
@RunWith(MockitoJUnitRunner.class) |
||||||
|
public class SimpleReactiveMongoRepositoryUnitTests { |
||||||
|
|
||||||
|
SimpleReactiveMongoRepository<Object, String> repository; |
||||||
|
@Mock Mono mono; |
||||||
|
@Mock Flux flux; |
||||||
|
@Mock ReactiveMongoOperations mongoOperations; |
||||||
|
@Mock MongoEntityInformation<Object, String> entityInformation; |
||||||
|
|
||||||
|
@Before |
||||||
|
public void setUp() { |
||||||
|
|
||||||
|
when(mongoOperations.count(any(), any(), any())).thenReturn(mono); |
||||||
|
when(mongoOperations.exists(any(), any(), any())).thenReturn(mono); |
||||||
|
when(mongoOperations.find(any(), any(), any())).thenReturn(flux); |
||||||
|
|
||||||
|
repository = new SimpleReactiveMongoRepository<>(entityInformation, mongoOperations); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToCountForExampleIfPresent() { |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToExistsForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.exists(Example.of(new TestDummy())).subscribe(); |
||||||
|
|
||||||
|
ArgumentCaptor<Query> query = ArgumentCaptor.forClass(Query.class); |
||||||
|
verify(mongoOperations).exists(query.capture(), any(), any()); |
||||||
|
|
||||||
|
assertThat(query.getValue().getCollation()).contains(collation); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToFindForExampleIfPresent() { |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToFindWithSortForExampleIfPresent() { |
||||||
|
|
||||||
|
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); |
||||||
|
} |
||||||
|
|
||||||
|
@Test // DATAMONGO-1854
|
||||||
|
public void shouldAddDefaultCollationToFindOneForExampleIfPresent() { |
||||||
|
|
||||||
|
Collation collation = Collation.of("en_US"); |
||||||
|
|
||||||
|
when(entityInformation.getCollation()).thenReturn(collation); |
||||||
|
repository.findOne(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); |
||||||
|
} |
||||||
|
|
||||||
|
static class TestDummy { |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
Loading…
Reference in new issue