DATAJDBC-151 - Polishing.
Removed unused code. Moved more of the context configuration into the common TestConfiguration.
This commit is contained in:
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.core;
|
||||
|
||||
import static java.util.Collections.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.tuple;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@@ -32,7 +33,6 @@ import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
@@ -250,26 +250,8 @@ public class JdbcEntityTemplateIntegrationTests {
|
||||
}
|
||||
|
||||
@Bean
|
||||
JdbcEntityOperations operations(ApplicationEventPublisher publisher,
|
||||
NamedParameterJdbcOperations namedParameterJdbcOperations) {
|
||||
|
||||
final JdbcMappingContext context = new JdbcMappingContext();
|
||||
return new JdbcEntityTemplate(publisher, context, dataAccessStrategy(namedParameterJdbcOperations, context));
|
||||
}
|
||||
|
||||
private DelegatingDataAccessStrategy dataAccessStrategy(NamedParameterJdbcOperations namedParameterJdbcOperations,
|
||||
JdbcMappingContext context) {
|
||||
|
||||
DelegatingDataAccessStrategy accessStrategy = new DelegatingDataAccessStrategy();
|
||||
|
||||
accessStrategy.setDelegate(new DefaultDataAccessStrategy( //
|
||||
new SqlGeneratorSource(context), //
|
||||
namedParameterJdbcOperations, //
|
||||
context, //
|
||||
accessStrategy) //
|
||||
);
|
||||
|
||||
return accessStrategy;
|
||||
JdbcEntityOperations operations(ApplicationEventPublisher publisher, JdbcMappingContext context, DataAccessStrategy dataAccessStrategy) {
|
||||
return new JdbcEntityTemplate(publisher, context, dataAccessStrategy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.mybatis;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Value;
|
||||
@@ -26,21 +26,16 @@ import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.SqlGeneratorSource;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.NamingStrategy;
|
||||
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
@@ -65,12 +60,6 @@ public class JdbcRepositoryIdGenerationIntegrationTests {
|
||||
Class<?> testClass() {
|
||||
return JdbcRepositoryIdGenerationIntegrationTests.class;
|
||||
}
|
||||
|
||||
@Bean
|
||||
DefaultDataAccessStrategy defaultDataAccessStrategy(JdbcMappingContext context,
|
||||
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations operations) {
|
||||
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context), operations, context);
|
||||
}
|
||||
}
|
||||
|
||||
@ClassRule public static final SpringClassRule classRule = new SpringClassRule();
|
||||
|
||||
@@ -15,11 +15,10 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.repository;
|
||||
|
||||
import static java.util.Arrays.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import junit.framework.AssertionFailedError;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
@@ -32,23 +31,18 @@ import org.junit.ClassRule;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.annotation.PersistenceConstructor;
|
||||
import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.SqlGeneratorSource;
|
||||
import org.springframework.data.jdbc.core.conversion.DbAction;
|
||||
import org.springframework.data.jdbc.mapping.event.BeforeDelete;
|
||||
import org.springframework.data.jdbc.mapping.event.BeforeSave;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositories;
|
||||
import org.springframework.data.jdbc.testing.TestConfiguration;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.rules.SpringClassRule;
|
||||
import org.springframework.test.context.junit4.rules.SpringMethodRule;
|
||||
@@ -233,12 +227,5 @@ public class JdbcRepositoryManipulateDbActionsIntegrationTests {
|
||||
actions.add(DbAction.insert(log, null, null));
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
DefaultDataAccessStrategy defaultDataAccessStrategy(JdbcMappingContext context,
|
||||
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations operations) {
|
||||
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context), operations, context);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,23 +15,18 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.repository.config;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.SqlGeneratorSource;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.repository.config.EnableJdbcRepositoriesIntegrationTests.TestConfiguration;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -74,12 +69,5 @@ public class EnableJdbcRepositoriesIntegrationTests {
|
||||
Class<?> testClass() {
|
||||
return EnableJdbcRepositoriesIntegrationTests.class;
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
DefaultDataAccessStrategy defaultDataAccessStrategy(JdbcMappingContext context,
|
||||
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations operations) {
|
||||
return new DefaultDataAccessStrategy(new SqlGeneratorSource(context), operations, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
package org.springframework.data.jdbc.repository.support;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.ListableBeanFactory;
|
||||
@@ -16,11 +15,6 @@ import org.springframework.data.jdbc.core.DataAccessStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.repository.Repository;
|
||||
import org.springframework.data.repository.core.EntityInformation;
|
||||
import org.springframework.data.repository.core.RepositoryInformation;
|
||||
import org.springframework.data.repository.core.RepositoryMetadata;
|
||||
import org.springframework.data.repository.core.support.RepositoryComposition;
|
||||
import org.springframework.data.repository.core.support.RepositoryFactorySupport;
|
||||
|
||||
/**
|
||||
* Tests the dependency injection for {@link JdbcRepositoryFactoryBean}.
|
||||
@@ -33,7 +27,6 @@ public class JdbcRepositoryFactoryBeanUnitTests {
|
||||
|
||||
JdbcRepositoryFactoryBean<DummyEntityRepository, DummyEntity, Long> factoryBean;
|
||||
|
||||
StubRepositoryFactorySupport factory;
|
||||
@Mock ListableBeanFactory beanFactory;
|
||||
@Mock Repository<?, ?> repository;
|
||||
@Mock DataAccessStrategy dataAccessStrategy;
|
||||
@@ -42,8 +35,6 @@ public class JdbcRepositoryFactoryBeanUnitTests {
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
factory = Mockito.spy(new StubRepositoryFactorySupport(repository));
|
||||
|
||||
// Setup standard configuration
|
||||
factoryBean = new JdbcRepositoryFactoryBean<>(DummyEntityRepository.class);
|
||||
}
|
||||
@@ -64,39 +55,6 @@ public class JdbcRepositoryFactoryBeanUnitTests {
|
||||
factoryBean.setBeanFactory(mock(BeanFactory.class));
|
||||
}
|
||||
|
||||
/**
|
||||
* required to trick Mockito on invoking protected getRepository(Class<T> repositoryInterface, Optional<Object>
|
||||
* customImplementation
|
||||
*/
|
||||
private static class StubRepositoryFactorySupport extends RepositoryFactorySupport {
|
||||
|
||||
private final Repository<?, ?> repository;
|
||||
|
||||
private StubRepositoryFactorySupport(Repository<?, ?> repository) {
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getRepository(Class<T> repositoryInterface, RepositoryComposition.RepositoryFragments fragments) {
|
||||
return (T) repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T, ID> EntityInformation<T, ID> getEntityInformation(Class<T> domainClass) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object getTargetRepository(RepositoryInformation metadata) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static class DummyEntity {
|
||||
@Id private Long id;
|
||||
}
|
||||
|
||||
@@ -15,20 +15,24 @@
|
||||
*/
|
||||
package org.springframework.data.jdbc.testing;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.jdbc.core.DataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.DefaultDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.DelegatingDataAccessStrategy;
|
||||
import org.springframework.data.jdbc.core.SqlGeneratorSource;
|
||||
import org.springframework.data.jdbc.mapping.model.DefaultNamingStrategy;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcMappingContext;
|
||||
import org.springframework.data.jdbc.mapping.model.JdbcPersistentProperty;
|
||||
import org.springframework.data.jdbc.mapping.model.*;
|
||||
import org.springframework.data.jdbc.repository.support.JdbcRepositoryFactory;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -76,4 +80,29 @@ public class TestConfiguration {
|
||||
PlatformTransactionManager transactionManager() {
|
||||
return new DataSourceTransactionManager(dataSource);
|
||||
}
|
||||
|
||||
@Bean
|
||||
DataAccessStrategy defaultDataAccessStrategy(JdbcMappingContext context,
|
||||
@Qualifier("namedParameterJdbcTemplate") NamedParameterJdbcOperations operations) {
|
||||
|
||||
DelegatingDataAccessStrategy accessStrategy = new DelegatingDataAccessStrategy();
|
||||
|
||||
accessStrategy.setDelegate(new DefaultDataAccessStrategy( //
|
||||
new SqlGeneratorSource(context), //
|
||||
operations, //
|
||||
context, //
|
||||
accessStrategy) //
|
||||
);
|
||||
|
||||
return accessStrategy;
|
||||
}
|
||||
|
||||
@Bean
|
||||
JdbcMappingContext jdbcMappingContext(Optional<NamingStrategy> namingStrategy,
|
||||
Optional<ConversionCustomizer> conversionCustomizer) {
|
||||
|
||||
return new JdbcMappingContext(
|
||||
namingStrategy.orElse(new DefaultNamingStrategy()),
|
||||
conversionCustomizer.orElse(conversionService -> {}));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user