use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class CriteriaTests method extractsJsonSchemaFromFactoryMethodCorrectly.
// DATAMONGO-1835
@Test
public void extractsJsonSchemaFromFactoryMethodCorrectly() {
MongoJsonSchema schema = MongoJsonSchema.builder().required("name").build();
Criteria critera = Criteria.matchingDocumentStructure(schema);
assertThat(critera.getCriteriaObject(), is(equalTo(new Document("$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 simpleTypes.
// DATAMONGO-1849
@Test
public void simpleTypes() {
MongoJsonSchema schema = schemaCreator.createSchemaFor(VariousFieldTypes.class);
assertThat(schema.toDocument().get("$jsonSchema", Document.class)).isEqualTo(Document.parse(VARIOUS_FIELD_TYPES));
}
use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method csfle.
// GH-3800
@Test
public void csfle() /*encryptedFieldsOnly*/
{
MongoJsonSchema schema = //
MongoJsonSchemaCreator.create().filter(// filter non encrypted fields
MongoJsonSchemaCreator.encryptedOnly()).createSchemaFor(Patient.class);
Document targetSchema = schema.schemaDocument();
assertThat(targetSchema.toBsonDocument()).isEqualTo(BsonDocument.parse(PATIENT));
}
use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method cyclic.
// DATAMONGO-1849
@Test
public void cyclic() {
MongoJsonSchema schema = schemaCreator.createSchemaFor(Cyclic.class);
assertThat(schema.toDocument().get("$jsonSchema", Document.class)).isEqualTo(CYCLIC);
}
use of org.springframework.data.mongodb.core.schema.MongoJsonSchema in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method csfleWithKeyFromProperties.
// GH-3800
@Test
public void csfleWithKeyFromProperties() {
GenericApplicationContext applicationContext = new GenericApplicationContext();
applicationContext.registerBean("encryptionExtension", EncryptionExtension.class, () -> new EncryptionExtension());
applicationContext.refresh();
MongoMappingContext mappingContext = new MongoMappingContext();
mappingContext.setApplicationContext(applicationContext);
mappingContext.afterPropertiesSet();
MongoJsonSchema schema = //
MongoJsonSchemaCreator.create(mappingContext).filter(//
MongoJsonSchemaCreator.encryptedOnly()).createSchemaFor(EncryptionMetadataFromProperty.class);
assertThat(schema.schemaDocument().toBsonDocument()).isEqualTo(BsonDocument.parse(ENC_FROM_PROPERTY_SCHEMA));
}
Aggregations