Search in sources :

Example 6 with MongoJsonSchema

use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.

the class JsonSchemaQueryTests method usesMappedFieldNameForRequiredProperties.

// DATAMONGO-1835
@Test
public void usesMappedFieldNameForRequiredProperties() {
    MongoJsonSchema schema = MongoJsonSchema.builder().required("name").build();
    assertThat(template.find(query(matchingDocumentStructure(schema)), Person.class)).containsExactlyInAnyOrder(jellyBelly, roseSpringHeart, kazmardBoombub);
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 7 with MongoJsonSchema

use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.

the class JsonSchemaQueryTests method mapsEnumValuesCorrectly.

// DATAMONGO-1835
@Test
public void mapsEnumValuesCorrectly() {
    MongoJsonSchema schema = MongoJsonSchema.builder().property(untyped("gender").possibleValues(Gender.PIXY, Gender.GOBLIN)).build();
    assertThat(template.find(query(matchingDocumentStructure(schema)), Person.class)).containsExactlyInAnyOrder(jellyBelly, kazmardBoombub);
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 8 with MongoJsonSchema

use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.

the class JsonSchemaQueryTests method findsWithSchemaReturningRawDocument.

// DATAMONGO-1835
@Test
public void findsWithSchemaReturningRawDocument() {
    MongoJsonSchema schema = MongoJsonSchema.builder().required("address").build();
    assertThat(template.find(query(matchingDocumentStructure(schema)), Document.class, template.getCollectionName(Person.class))).hasSize(2);
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 9 with MongoJsonSchema

use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.

the class JsonSchemaQueryTests method usesMappedFieldNameForProperties.

// DATAMONGO-1835
@Test
public void usesMappedFieldNameForProperties() {
    MongoJsonSchema schema = MongoJsonSchema.builder().property(string("name").matching("^R.*")).build();
    assertThat(template.find(query(matchingDocumentStructure(schema)), Person.class)).containsExactlyInAnyOrder(roseSpringHeart);
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 10 with MongoJsonSchema

use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.

the class CriteriaUnitTests method extractsJsonSchemaInChainCorrectly.

// DATAMONGO-1835
@Test
public void extractsJsonSchemaInChainCorrectly() {
    MongoJsonSchema schema = MongoJsonSchema.builder().required("name").build();
    Criteria criteria = Criteria.where("foo").is("bar").andDocumentStructureMatches(schema);
    assertThat(criteria.getCriteriaObject()).isEqualTo(new Document("foo", "bar").append("$jsonSchema", new Document("type", "object").append("required", Collections.singletonList("name"))));
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Document(org.bson.Document) Test(org.junit.Test)

Aggregations

MongoJsonSchema (org.springframework.data.mongodb.core.schema.MongoJsonSchema)23 Test (org.junit.jupiter.api.Test)19 Document (org.bson.Document)6 Test (org.junit.Test)4 BsonDocument (org.bson.BsonDocument)2 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)2 MongoMappingContext (org.springframework.data.mongodb.core.mapping.MongoMappingContext)2 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)1 MongoCustomConversions (org.springframework.data.mongodb.core.convert.MongoCustomConversions)1 StepVerifier (reactor.test.StepVerifier)1