Search in sources :

Example 21 with MongoJsonSchema

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

the class JsonSchemaQueryTests method findsDocumentsWithRequiredFieldsCorrectly.

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

Example 22 with MongoJsonSchema

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

the class MongoJsonSchemaMapperUnitTests method constructReferenceSchemaCorrectly.

// DATAMONGO-1835
@Test
public void constructReferenceSchemaCorrectly() {
    MongoJsonSchema schema = // 
    MongoJsonSchema.builder().required("name", "year", "major", "gradePointAverage").description(// 
    "").properties(// 
    string("name").description("must be a string and is required"), // 
    string("gender").description("must be a string and is not required"), // 
    int32("year").description("must be an integer in [ 2017, 3017 ] and is required").gte(2017).lt(3017), string("major").description("can only be one of the enum values and is required").possibleValues("Math", "English", "Computer Science", "History", // 
    null), // 
    float64("gradePointAverage").description("must be a double and is required")).build();
    assertThat(mapper.mapSchema(schema.toDocument(), Student.class)).isEqualTo(Document.parse(complexSchemaJsonString));
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 23 with MongoJsonSchema

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

the class CriteriaUnitTests method extractsJsonSchemaFromFactoryMethodCorrectly.

// DATAMONGO-1835
@Test
public void extractsJsonSchemaFromFactoryMethodCorrectly() {
    MongoJsonSchema schema = MongoJsonSchema.builder().required("name").build();
    Criteria criteria = Criteria.matchingDocumentStructure(schema);
    assertThat(criteria.getCriteriaObject()).isEqualTo(new Document("$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