Search in sources :

Example 1 with DataAccessStrategy

use of org.springframework.data.jdbc.core.convert.DataAccessStrategy in project spring-data-jdbc by spring-projects.

the class EnableJdbcRepositoriesIntegrationTests method jdbcOperationsRef.

// DATAJDBC-293
@Test
public void jdbcOperationsRef() {
    NamedParameterJdbcOperations operations = (NamedParameterJdbcOperations) ReflectionUtils.getField(OPERATIONS, factoryBean);
    assertThat(operations).isNotSameAs(defaultOperations).isSameAs(qualifierJdbcOperations);
    DataAccessStrategy dataAccessStrategy = (DataAccessStrategy) ReflectionUtils.getField(DATA_ACCESS_STRATEGY, factoryBean);
    assertThat(dataAccessStrategy).isNotSameAs(defaultDataAccessStrategy).isSameAs(qualifierDataAccessStrategy);
}
Also used : DataAccessStrategy(org.springframework.data.jdbc.core.convert.DataAccessStrategy) DefaultDataAccessStrategy(org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy) NamedParameterJdbcOperations(org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations) Test(org.junit.jupiter.api.Test)

Example 2 with DataAccessStrategy

use of org.springframework.data.jdbc.core.convert.DataAccessStrategy 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

Test (org.junit.jupiter.api.Test)2 DataAccessStrategy (org.springframework.data.jdbc.core.convert.DataAccessStrategy)2 DefaultDataAccessStrategy (org.springframework.data.jdbc.core.convert.DefaultDataAccessStrategy)2 NamedParameterJdbcOperations (org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations)2 Supplier (java.util.function.Supplier)1 Assertions (org.assertj.core.api.Assertions)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)1 Answers (org.mockito.Answers)1 Mock (org.mockito.Mock)1 Mockito (org.mockito.Mockito)1 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)1 MockitoSettings (org.mockito.junit.jupiter.MockitoSettings)1 Strictness (org.mockito.quality.Strictness)1 Answer (org.mockito.stubbing.Answer)1 BeanFactory (org.springframework.beans.factory.BeanFactory)1 ListableBeanFactory (org.springframework.beans.factory.ListableBeanFactory)1 ObjectProvider (org.springframework.beans.factory.ObjectProvider)1 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)1 Id (org.springframework.data.annotation.Id)1