Search in sources :

Example 1 with ExtensionAwareEvaluationContextProvider

use of org.springframework.data.spel.ExtensionAwareEvaluationContextProvider in project spring-data-mongodb by spring-projects.

the class BasicMongoPersistentEntityUnitTests method collectionAllowsReferencingSpringBean.

// DATAMONGO-65, DATAMONGO-1108
@Test
void collectionAllowsReferencingSpringBean() {
    CollectionProvider provider = new CollectionProvider();
    provider.collectionName = "reference";
    when(context.getBean("myBean")).thenReturn(provider);
    BasicMongoPersistentEntity<DynamicallyMapped> entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(DynamicallyMapped.class));
    entity.setEvaluationContextProvider(new ExtensionAwareEvaluationContextProvider(context));
    assertThat(entity.getCollection()).isEqualTo("reference");
    provider.collectionName = "otherReference";
    assertThat(entity.getCollection()).isEqualTo("otherReference");
}
Also used : ExtensionAwareEvaluationContextProvider(org.springframework.data.spel.ExtensionAwareEvaluationContextProvider) Test(org.junit.jupiter.api.Test)

Example 2 with ExtensionAwareEvaluationContextProvider

use of org.springframework.data.spel.ExtensionAwareEvaluationContextProvider in project spring-data-mongodb by spring-projects.

the class BasicMongoPersistentEntityUnitTests method usesEvaluationContextExtensionInDynamicDocumentName.

// DATAMONGO-1874
@Test
void usesEvaluationContextExtensionInDynamicDocumentName() {
    BasicMongoPersistentEntity<MappedWithExtension> entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(MappedWithExtension.class));
    entity.setEvaluationContextProvider(new ExtensionAwareEvaluationContextProvider(Collections.singletonList(new SampleExtension())));
    assertThat(entity.getCollection()).isEqualTo("collectionName");
}
Also used : ExtensionAwareEvaluationContextProvider(org.springframework.data.spel.ExtensionAwareEvaluationContextProvider) Test(org.junit.jupiter.api.Test)

Example 3 with ExtensionAwareEvaluationContextProvider

use of org.springframework.data.spel.ExtensionAwareEvaluationContextProvider in project spring-data-mongodb by spring-projects.

the class BasicMongoPersistentEntityUnitTests method usesCorrectExpressionsForCollectionAndCollation.

// DATAMONGO-2565
@Test
void usesCorrectExpressionsForCollectionAndCollation() {
    BasicMongoPersistentEntity<WithCollectionAndCollationFromSpEL> entity = new BasicMongoPersistentEntity<>(ClassTypeInformation.from(WithCollectionAndCollationFromSpEL.class));
    entity.setEvaluationContextProvider(new ExtensionAwareEvaluationContextProvider(Collections.singletonList(new SampleExtension())));
    assertThat(entity.getCollection()).isEqualTo("collectionName");
    assertThat(entity.getCollation()).isEqualTo(Collation.of("en_US"));
}
Also used : ExtensionAwareEvaluationContextProvider(org.springframework.data.spel.ExtensionAwareEvaluationContextProvider) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 ExtensionAwareEvaluationContextProvider (org.springframework.data.spel.ExtensionAwareEvaluationContextProvider)3