Search in sources :

Example 16 with MongoJsonSchema

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

the class MappingMongoJsonSchemaCreatorUnitTests method csfleWithKeyFromMethod.

// GH-3800
@Test
public void csfleWithKeyFromMethod() {
    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(EncryptionMetadataFromMethod.class);
    assertThat(schema.schemaDocument().toBsonDocument()).isEqualTo(BsonDocument.parse(ENC_FROM_METHOD_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)

Example 17 with MongoJsonSchema

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

the class JsonSchemaQueryTests method mapsNestedFieldName.

// DATAMONGO-1835
@Test
public void mapsNestedFieldName() {
    MongoJsonSchema schema = // 
    MongoJsonSchema.builder().required(// 
    "address").property(object("address").properties(string("street").matching("^Apple.*"))).build();
    assertThat(template.find(query(matchingDocumentStructure(schema)), Person.class)).containsExactlyInAnyOrder(jellyBelly);
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) Test(org.junit.jupiter.api.Test)

Example 18 with MongoJsonSchema

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

the class JsonSchemaQueryTests method findsDocumentsWithRequiredFieldsReactively.

// DATAMONGO-1835
@Test
public void findsDocumentsWithRequiredFieldsReactively() {
    MongoJsonSchema schema = MongoJsonSchema.builder().required("address").build();
    new ReactiveMongoTemplate(reactiveClient, DATABASE_NAME).find(query(matchingDocumentStructure(schema)), Person.class).as(StepVerifier::create).expectNextCount(2).verifyComplete();
}
Also used : MongoJsonSchema(org.springframework.data.mongodb.core.schema.MongoJsonSchema) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 19 with MongoJsonSchema

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

the class JsonSchemaQueryTests method findsDocumentsWithJsonFieldTypesCorrectly.

// DATAMONGO-1835
@Test
public void findsDocumentsWithJsonFieldTypesCorrectly() {
    MongoJsonSchema schema = MongoJsonSchema.builder().property(number("value")).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 20 with MongoJsonSchema

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

the class JsonSchemaQueryTests method findsDocumentsWithBsonFieldTypesCorrectly.

// DATAMONGO-1835
@Test
public void findsDocumentsWithBsonFieldTypesCorrectly() {
    MongoJsonSchema schema = MongoJsonSchema.builder().property(int32("value")).build();
    assertThat(template.find(query(matchingDocumentStructure(schema)), Person.class)).containsExactlyInAnyOrder(jellyBelly);
}
Also used : 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