|
|
|
@ -29,12 +29,15 @@ import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.Optional; |
|
|
|
import java.util.TreeMap; |
|
|
|
import java.util.TreeMap; |
|
|
|
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.bson.BsonRegularExpression; |
|
|
|
import org.bson.conversions.Bson; |
|
|
|
import org.bson.conversions.Bson; |
|
|
|
import org.bson.types.Code; |
|
|
|
import org.bson.types.Code; |
|
|
|
import org.bson.types.ObjectId; |
|
|
|
import org.bson.types.ObjectId; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.convert.converter.Converter; |
|
|
|
import org.springframework.core.convert.converter.Converter; |
|
|
|
import org.springframework.data.annotation.Id; |
|
|
|
import org.springframework.data.annotation.Id; |
|
|
|
import org.springframework.data.annotation.Transient; |
|
|
|
import org.springframework.data.annotation.Transient; |
|
|
|
@ -553,7 +556,7 @@ public class QueryMapperUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
org.bson.Document queryObject = query( |
|
|
|
org.bson.Document queryObject = query( |
|
|
|
where("referenceList").is(new org.bson.Document("$nested", new org.bson.Document("$keys", 0L)))) |
|
|
|
where("referenceList").is(new org.bson.Document("$nested", new org.bson.Document("$keys", 0L)))) |
|
|
|
.getQueryObject(); |
|
|
|
.getQueryObject(); |
|
|
|
|
|
|
|
|
|
|
|
org.bson.Document mappedObject = mapper.getMappedObject(queryObject, |
|
|
|
org.bson.Document mappedObject = mapper.getMappedObject(queryObject, |
|
|
|
context.getPersistentEntity(WithDBRefList.class)); |
|
|
|
context.getPersistentEntity(WithDBRefList.class)); |
|
|
|
@ -825,7 +828,7 @@ public class QueryMapperUnitTests { |
|
|
|
@Test // GH-3688
|
|
|
|
@Test // GH-3688
|
|
|
|
void mappingShouldAllowSettingEntireNestedNumericKeyedMapValue() { |
|
|
|
void mappingShouldAllowSettingEntireNestedNumericKeyedMapValue() { |
|
|
|
|
|
|
|
|
|
|
|
Query query = query(where("outerMap.1.map").is(null)); //newEntityWithComplexValueTypeMap()
|
|
|
|
Query query = query(where("outerMap.1.map").is(null)); // newEntityWithComplexValueTypeMap()
|
|
|
|
|
|
|
|
|
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
context.getPersistentEntity(EntityWithIntKeyedMapOfMap.class)); |
|
|
|
context.getPersistentEntity(EntityWithIntKeyedMapOfMap.class)); |
|
|
|
@ -997,6 +1000,22 @@ public class QueryMapperUnitTests { |
|
|
|
assertThat(document).isEqualTo(new org.bson.Document("scripts", new Code(script))); |
|
|
|
assertThat(document).isEqualTo(new org.bson.Document("scripts", new Code(script))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-4649
|
|
|
|
|
|
|
|
void shouldRetainRegexPattern() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Query query = new Query(where("text").regex("foo")); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
|
|
|
|
context.getPersistentEntity(WithExplicitTargetTypes.class)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(document.get("text")).isInstanceOf(Pattern.class); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
query = new Query(where("text").regex(new BsonRegularExpression("foo"))); |
|
|
|
|
|
|
|
document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
|
|
|
|
context.getPersistentEntity(WithExplicitTargetTypes.class)); |
|
|
|
|
|
|
|
assertThat(document.get("text")).isInstanceOf(BsonRegularExpression.class); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // DATAMONGO-2339
|
|
|
|
@Test // DATAMONGO-2339
|
|
|
|
void findByIdUsesMappedIdFieldNameWithUnderscoreCorrectly() { |
|
|
|
void findByIdUsesMappedIdFieldNameWithUnderscoreCorrectly() { |
|
|
|
|
|
|
|
|
|
|
|
@ -1300,7 +1319,8 @@ public class QueryMapperUnitTests { |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
context.getPersistentEntity(WithPropertyUsingUnderscoreInName.class)); |
|
|
|
context.getPersistentEntity(WithPropertyUsingUnderscoreInName.class)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(document).isEqualTo(new org.bson.Document("fieldname_with_underscores", new org.bson.Document("$exists", true))); |
|
|
|
assertThat(document) |
|
|
|
|
|
|
|
.isEqualTo(new org.bson.Document("fieldname_with_underscores", new org.bson.Document("$exists", true))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-3601
|
|
|
|
@Test // GH-3601
|
|
|
|
@ -1322,7 +1342,8 @@ public class QueryMapperUnitTests { |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class)); |
|
|
|
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(document).isEqualTo(new org.bson.Document("simple.fieldname_with_underscores", new org.bson.Document("$exists", true))); |
|
|
|
assertThat(document) |
|
|
|
|
|
|
|
.isEqualTo(new org.bson.Document("simple.fieldname_with_underscores", new org.bson.Document("$exists", true))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-3601
|
|
|
|
@Test // GH-3601
|
|
|
|
@ -1344,7 +1365,8 @@ public class QueryMapperUnitTests { |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class)); |
|
|
|
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(document).isEqualTo(new org.bson.Document("double_underscore.fieldname_with_underscores", new org.bson.Document("$exists", true))); |
|
|
|
assertThat(document).isEqualTo( |
|
|
|
|
|
|
|
new org.bson.Document("double_underscore.fieldname_with_underscores", new org.bson.Document("$exists", true))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-3601
|
|
|
|
@Test // GH-3601
|
|
|
|
@ -1355,7 +1377,8 @@ public class QueryMapperUnitTests { |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
org.bson.Document document = mapper.getMappedObject(query.getQueryObject(), |
|
|
|
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class)); |
|
|
|
context.getPersistentEntity(WrapperAroundWithPropertyUsingUnderscoreInName.class)); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(document).isEqualTo(new org.bson.Document("double_underscore.renamed", new org.bson.Document("$exists", true))); |
|
|
|
assertThat(document) |
|
|
|
|
|
|
|
.isEqualTo(new org.bson.Document("double_underscore.renamed", new org.bson.Document("$exists", true))); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-3633
|
|
|
|
@Test // GH-3633
|
|
|
|
@ -1393,7 +1416,8 @@ public class QueryMapperUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
Query query = query(where("address.street").is("1007 Mountain Drive")); |
|
|
|
Query query = query(where("address.street").is("1007 Mountain Drive")); |
|
|
|
|
|
|
|
|
|
|
|
MongoCustomConversions mongoCustomConversions = new MongoCustomConversions(Collections.singletonList(new MyAddressToDocumentConverter())); |
|
|
|
MongoCustomConversions mongoCustomConversions = new MongoCustomConversions( |
|
|
|
|
|
|
|
Collections.singletonList(new MyAddressToDocumentConverter())); |
|
|
|
|
|
|
|
|
|
|
|
this.context = new MongoMappingContext(); |
|
|
|
this.context = new MongoMappingContext(); |
|
|
|
this.context.setSimpleTypeHolder(mongoCustomConversions.getSimpleTypeHolder()); |
|
|
|
this.context.setSimpleTypeHolder(mongoCustomConversions.getSimpleTypeHolder()); |
|
|
|
@ -1405,7 +1429,8 @@ public class QueryMapperUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
this.mapper = new QueryMapper(converter); |
|
|
|
this.mapper = new QueryMapper(converter); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(mapper.getMappedSort(query.getQueryObject(), context.getPersistentEntity(Customer.class))).isEqualTo(new org.bson.Document("address.street", "1007 Mountain Drive")); |
|
|
|
assertThat(mapper.getMappedSort(query.getQueryObject(), context.getPersistentEntity(Customer.class))) |
|
|
|
|
|
|
|
.isEqualTo(new org.bson.Document("address.street", "1007 Mountain Drive")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-3790
|
|
|
|
@Test // GH-3790
|
|
|
|
@ -1426,7 +1451,8 @@ public class QueryMapperUnitTests { |
|
|
|
@Test // GH-3668
|
|
|
|
@Test // GH-3668
|
|
|
|
void mapStringIdFieldProjection() { |
|
|
|
void mapStringIdFieldProjection() { |
|
|
|
|
|
|
|
|
|
|
|
org.bson.Document mappedFields = mapper.getMappedFields(new org.bson.Document("id", 1), context.getPersistentEntity(WithStringId.class)); |
|
|
|
org.bson.Document mappedFields = mapper.getMappedFields(new org.bson.Document("id", 1), |
|
|
|
|
|
|
|
context.getPersistentEntity(WithStringId.class)); |
|
|
|
assertThat(mappedFields).containsEntry("_id", 1); |
|
|
|
assertThat(mappedFields).containsEntry("_id", 1); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1452,7 +1478,8 @@ public class QueryMapperUnitTests { |
|
|
|
@Test // GH-3596
|
|
|
|
@Test // GH-3596
|
|
|
|
void considersValueConverterWhenPresent() { |
|
|
|
void considersValueConverterWhenPresent() { |
|
|
|
|
|
|
|
|
|
|
|
org.bson.Document mappedObject = mapper.getMappedObject(new org.bson.Document("text", "value"), context.getPersistentEntity(WithPropertyValueConverter.class)); |
|
|
|
org.bson.Document mappedObject = mapper.getMappedObject(new org.bson.Document("text", "value"), |
|
|
|
|
|
|
|
context.getPersistentEntity(WithPropertyValueConverter.class)); |
|
|
|
assertThat(mappedObject).isEqualTo(new org.bson.Document("text", "eulav")); |
|
|
|
assertThat(mappedObject).isEqualTo(new org.bson.Document("text", "eulav")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1651,23 +1678,20 @@ public class QueryMapperUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
private String name; |
|
|
|
private String name; |
|
|
|
|
|
|
|
|
|
|
|
@DocumentReference(lookup = "{ 'name' : ?#{#target} }") |
|
|
|
@DocumentReference(lookup = "{ 'name' : ?#{#target} }") private Customer customer; |
|
|
|
private Customer customer; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DocumentReference(lookup = "{ 'name' : ?#{#target} }") |
|
|
|
@DocumentReference(lookup = "{ 'name' : ?#{#target} }") private List<Customer> customers; |
|
|
|
private List<Customer> customers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DocumentReference |
|
|
|
@DocumentReference private Sample sample; |
|
|
|
private Sample sample; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DocumentReference |
|
|
|
@DocumentReference private List<Sample> samples; |
|
|
|
private List<Sample> samples; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
class WithTextScoreProperty { |
|
|
|
class WithTextScoreProperty { |
|
|
|
|
|
|
|
|
|
|
|
@Id String id; |
|
|
|
@Id String id; |
|
|
|
@TextScore @Field("score") Float textScore; |
|
|
|
@TextScore |
|
|
|
|
|
|
|
@Field("score") Float textScore; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class RootForClassWithExplicitlyRenamedIdField { |
|
|
|
static class RootForClassWithExplicitlyRenamedIdField { |
|
|
|
@ -1704,7 +1728,7 @@ public class QueryMapperUnitTests { |
|
|
|
Map<Integer, SimpleEntityWithoutId> map; |
|
|
|
Map<Integer, SimpleEntityWithoutId> map; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static class EntityWithIntKeyedMapOfMap{ |
|
|
|
static class EntityWithIntKeyedMapOfMap { |
|
|
|
Map<Integer, EntityWithComplexValueTypeMap> outerMap; |
|
|
|
Map<Integer, EntityWithComplexValueTypeMap> outerMap; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1717,6 +1741,9 @@ public class QueryMapperUnitTests { |
|
|
|
@Field(targetType = FieldType.SCRIPT) //
|
|
|
|
@Field(targetType = FieldType.SCRIPT) //
|
|
|
|
String script; |
|
|
|
String script; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Field(targetType = FieldType.STRING) //
|
|
|
|
|
|
|
|
String text; |
|
|
|
|
|
|
|
|
|
|
|
@Field(targetType = FieldType.SCRIPT) //
|
|
|
|
@Field(targetType = FieldType.SCRIPT) //
|
|
|
|
List<String> scripts; |
|
|
|
List<String> scripts; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1786,15 +1813,13 @@ public class QueryMapperUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
String fieldname_with_underscores; |
|
|
|
String fieldname_with_underscores; |
|
|
|
|
|
|
|
|
|
|
|
@Field("renamed") |
|
|
|
@Field("renamed") String renamed_fieldname_with_underscores; |
|
|
|
String renamed_fieldname_with_underscores; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Document |
|
|
|
@Document |
|
|
|
static class Customer { |
|
|
|
static class Customer { |
|
|
|
|
|
|
|
|
|
|
|
@Id |
|
|
|
@Id private ObjectId id; |
|
|
|
private ObjectId id; |
|
|
|
|
|
|
|
private String name; |
|
|
|
private String name; |
|
|
|
private MyAddress address; |
|
|
|
private MyAddress address; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1805,8 +1830,7 @@ public class QueryMapperUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
static class WithPropertyValueConverter { |
|
|
|
static class WithPropertyValueConverter { |
|
|
|
|
|
|
|
|
|
|
|
@ValueConverter(ReversingValueConverter.class) |
|
|
|
@ValueConverter(ReversingValueConverter.class) String text; |
|
|
|
String text; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@WritingConverter |
|
|
|
@WritingConverter |
|
|
|
|