use of org.springframework.data.mongodb.core.mapping.MongoMappingContext 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));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext 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));
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MappingMongoJsonSchemaCreatorUnitTests method setUp.
@BeforeEach
public void setUp() {
mappingContext = new MongoMappingContext();
converter = new MappingMongoConverter(NoOpDbRefResolver.INSTANCE, mappingContext);
schemaCreator = new MappingMongoJsonSchemaCreator(converter);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method createsNotNestedGeoSpatialIndexCorrectly.
// DATAMONGO-899
@Test
void createsNotNestedGeoSpatialIndexCorrectly() {
MongoMappingContext mappingContext = prepareMappingContext(Wrapper.class);
new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate);
assertThat(keysCaptor.getValue()).isEqualTo(new org.bson.Document("company.address.location", "2d"));
IndexOptions opts = optionsCaptor.getValue();
assertThat(opts.getName()).isEqualTo("company.address.location");
assertThat(opts.getMin()).isCloseTo(-180d, offset(0d));
assertThat(opts.getMax()).isCloseTo(180d, offset(0d));
assertThat(opts.getBits()).isEqualTo(26);
}
use of org.springframework.data.mongodb.core.mapping.MongoMappingContext in project spring-data-mongodb by spring-projects.
the class MongoPersistentEntityIndexCreatorUnitTests method createIndexShouldNotConvertUnknownExceptionTypes.
// DATAMONGO-1125
@Test
void createIndexShouldNotConvertUnknownExceptionTypes() {
doThrow(new ClassCastException("o_O")).when(collection).createIndex(any(org.bson.Document.class), any(IndexOptions.class));
MongoMappingContext mappingContext = prepareMappingContext(Person.class);
assertThatThrownBy(() -> new MongoPersistentEntityIndexCreator(mappingContext, mongoTemplate)).isInstanceOf(ClassCastException.class);
}
Aggregations