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);
}
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));
}
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"))));
}
Aggregations