use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class CriteriaTests method extractsJsonSchemaInChainCorrectly.
// DATAMONGO-1835
@Test
public void extractsJsonSchemaInChainCorrectly() {
MongoJsonSchema schema = MongoJsonSchema.builder().required("name").build();
Criteria critera = Criteria.where("foo").is("bar").andDocumentStructureMatches(schema);
assertThat(critera.getCriteriaObject(), is(equalTo(new Document("foo", "bar").append("$jsonSchema", new Document("type", "object").append("required", Collections.singletonList("name"))))));
}
use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method converterRegistered.
// DATAMONGO-1849
@Test
public void converterRegistered() {
MappingMongoConverter converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
MongoCustomConversions mcc = new MongoCustomConversions(Collections.singletonList(SimpleToDocumentConverter.INSTANCE));
converter.setCustomConversions(mcc);
converter.afterPropertiesSet();
schemaCreator = new MappingMongoJsonSchemaCreator(converter);
MongoJsonSchema schema = schemaCreator.createSchemaFor(WithNestedDomainType.class);
assertThat(schema.toDocument().get("$jsonSchema", Document.class)).isEqualTo("{ 'type' : 'object', 'properties' : { '_id' : { 'type' : 'object' }, 'nested' : { 'type' : 'object' } } }");
}
use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method csfleCyclic.
// GH-3800
@Test
public void csfleCyclic() /*encryptedFieldsOnly*/
{
MongoJsonSchema schema = //
MongoJsonSchemaCreator.create().filter(// filter non encrypted fields
MongoJsonSchemaCreator.encryptedOnly()).createSchemaFor(Cyclic.class);
Document targetSchema = schema.schemaDocument();
assertThat(targetSchema).isNotNull();
}
use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method withRemappedIdType.
// DATAMONGO-1849
@Test
public void withRemappedIdType() {
MongoJsonSchema schema = schemaCreator.createSchemaFor(WithExplicitMongoIdTypeMapping.class);
assertThat(schema.toDocument().get("$jsonSchema", Document.class)).isEqualTo(WITH_EXPLICIT_MONGO_ID_TYPE_MAPPING);
}
use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class JsonSchemaQueryTests method combineSchemaWithOtherCriteria.
// DATAMONGO-1835
@Test
public void combineSchemaWithOtherCriteria() {
MongoJsonSchema schema = MongoJsonSchema.builder().property(number("value")).build();
assertThat(template.find(query(matchingDocumentStructure(schema).and("name").is(roseSpringHeart.name)), Person.class)).containsExactlyInAnyOrder(roseSpringHeart);
}
Aggregations