Search in sources :

Example 11 with MongoJsonSchema

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"))))));
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Document(org.bson.Document) Test(org.junit.Test)

Example 12 with MongoJsonSchema

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));
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 13 with MongoJsonSchema

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));
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Document(org.bson.Document) BsonDocument(org.bson.BsonDocument) Test(org.junit.jupiter.api.Test)

Example 14 with MongoJsonSchema

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);
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 15 with MongoJsonSchema

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));
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) MongoMappingContext(org.springframework.data.mongodb.core.mapping.MongoMappingContext) MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.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