Search in sources :

Example 1 with ObjectProvider

use of org.springframework.beans.factory.ObjectProvider in project cas by apereo.

the class CasCoreUtilSerializationConfiguration method componentSerializationPlan.

@ConditionalOnMissingBean(name = "componentSerializationPlan")
@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public ComponentSerializationPlan componentSerializationPlan(final ObjectProvider<List<ComponentSerializationPlanConfigurer>> configurers) {
    val plan = new DefaultComponentSerializationPlan();
    plan.registerSerializableClass(TriStateBoolean.class);
    configurers.ifAvailable(cfgs -> cfgs.forEach(c -> {
        LOGGER.trace("Configuring component serialization plan [{}]", c.getName());
        c.configureComponentSerializationPlan(plan);
    }));
    return plan;
}
Also used : lombok.val(lombok.val) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) ComponentSerializationPlan(org.apereo.cas.util.serialization.ComponentSerializationPlan) DefaultComponentSerializationPlan(org.apereo.cas.util.serialization.DefaultComponentSerializationPlan) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) ObjectProvider(org.springframework.beans.factory.ObjectProvider) List(java.util.List) TriStateBoolean(org.apereo.cas.util.model.TriStateBoolean) Bean(org.springframework.context.annotation.Bean) ComponentSerializationPlanConfigurer(org.apereo.cas.util.serialization.ComponentSerializationPlanConfigurer) DefaultComponentSerializationPlan(org.apereo.cas.util.serialization.DefaultComponentSerializationPlan) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with ObjectProvider

use of org.springframework.beans.factory.ObjectProvider in project cas by apereo.

the class CasCoreTicketIdGeneratorsConfiguration method uniqueIdGeneratorsMap.

@Bean
@RefreshScope(proxyMode = ScopedProxyMode.DEFAULT)
public Map<String, UniqueTicketIdGenerator> uniqueIdGeneratorsMap(final ObjectProvider<List<UniqueTicketIdGeneratorConfigurer>> configurers) {
    val map = new HashMap<String, UniqueTicketIdGenerator>();
    configurers.ifAvailable(cfgs -> cfgs.forEach(c -> {
        val pair = c.buildUniqueTicketIdGenerators();
        pair.forEach(p -> map.put(p.getKey(), p.getValue()));
    }));
    return map;
}
Also used : lombok.val(lombok.val) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) UniqueTicketIdGeneratorConfigurer(org.apereo.cas.ticket.UniqueTicketIdGeneratorConfigurer) lombok.val(lombok.val) ScopedProxyMode(org.springframework.context.annotation.ScopedProxyMode) UniqueTicketIdGenerator(org.apereo.cas.ticket.UniqueTicketIdGenerator) HashMap(java.util.HashMap) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Configuration(org.springframework.context.annotation.Configuration) ObjectProvider(org.springframework.beans.factory.ObjectProvider) List(java.util.List) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Map(java.util.Map) Bean(org.springframework.context.annotation.Bean) HashMap(java.util.HashMap) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 3 with ObjectProvider

use of org.springframework.beans.factory.ObjectProvider in project spring-data-jdbc by spring-projects.

the class JdbcRepositoryFactoryBeanUnitTests method setUp.

@BeforeEach
public void setUp() {
    this.mappingContext = new JdbcMappingContext();
    // Setup standard configuration
    factoryBean = new JdbcRepositoryFactoryBean<>(DummyEntityRepository.class);
    when(beanFactory.getBean(NamedParameterJdbcOperations.class)).thenReturn(mock(NamedParameterJdbcOperations.class));
    ObjectProvider<DataAccessStrategy> provider = mock(ObjectProvider.class);
    when(beanFactory.getBeanProvider(DataAccessStrategy.class)).thenReturn(provider);
    when(provider.getIfAvailable(any())).then((Answer<?>) invocation -> ((Supplier<?>) invocation.getArgument(0)).get());
}
Also used : Strictness(org.mockito.quality.Strictness) BeforeEach(org.junit.jupiter.api.BeforeEach) BasicJdbcConverter(org.springframework.data.jdbc.core.convert.BasicJdbcConverter) MockitoSettings(org.mockito.junit.jupiter.MockitoSettings) Dialect(org.springframework.data.relational.core.dialect.Dialect) Mock(org.mockito.Mock) RelationalMappingContext(org.springframework.data.relational.core.mapping.RelationalMappingContext) CrudRepository(org.springframework.data.repository.CrudRepository) Supplier(java.util.function.Supplier) Answer(org.mockito.stubbing.Answer) ObjectProvider(org.springframework.beans.factory.ObjectProvider) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) QueryMappingConfiguration(org.springframework.data.jdbc.repository.QueryMappingConfiguration) Assertions(org.assertj.core.api.Assertions) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Answers(org.mockito.Answers) DataAccessStrategy(org.springframework.data.jdbc.core.convert.DataAccessStrategy) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) BeanFactory(org.springframework.beans.factory.BeanFactory) Id(org.springframework.data.annotation.Id) ListableBeanFactory(org.springframework.beans.factory.ListableBeanFactory) JdbcMappingContext(org.springframework.data.jdbc.core.mapping.JdbcMappingContext) DataAccessStrategy(org.springframework.data.jdbc.core.convert.DataAccessStrategy) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) Supplier(java.util.function.Supplier) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

ObjectProvider (org.springframework.beans.factory.ObjectProvider)3 List (java.util.List)2 lombok.val (lombok.val)2 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)2 Bean (org.springframework.context.annotation.Bean)2 Configuration (org.springframework.context.annotation.Configuration)2 ScopedProxyMode (org.springframework.context.annotation.ScopedProxyMode)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Supplier (java.util.function.Supplier)1 Slf4j (lombok.extern.slf4j.Slf4j)1 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)1 UniqueTicketIdGenerator (org.apereo.cas.ticket.UniqueTicketIdGenerator)1 UniqueTicketIdGeneratorConfigurer (org.apereo.cas.ticket.UniqueTicketIdGeneratorConfigurer)1 TriStateBoolean (org.apereo.cas.util.model.TriStateBoolean)1 ComponentSerializationPlan (org.apereo.cas.util.serialization.ComponentSerializationPlan)1 ComponentSerializationPlanConfigurer (org.apereo.cas.util.serialization.ComponentSerializationPlanConfigurer)1 DefaultComponentSerializationPlan (org.apereo.cas.util.serialization.DefaultComponentSerializationPlan)1 Assertions (org.assertj.core.api.Assertions)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1