Search in sources :

Example 1 with MongoJsonSchema

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

Example 2 with MongoJsonSchema

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

Example 3 with MongoJsonSchema

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();
}
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 4 with MongoJsonSchema

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

Example 5 with MongoJsonSchema

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