|
|
@ -57,13 +57,10 @@ import static org.junit.Assert.fail;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class JooqAutoConfigurationTests {
|
|
|
|
public class JooqAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
private static final String[] NO_BEANS = {};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
private ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
|
|
|
.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class))
|
|
|
|
.withConfiguration(AutoConfigurations.of(JooqAutoConfiguration.class))
|
|
|
|
.withPropertyValues("spring.datasource.name:jooqtest");
|
|
|
|
.withPropertyValues("spring.datasource.name:jooqtest");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
@Rule
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
|
|
|
|
|
|
|
@ -76,13 +73,10 @@ public class JooqAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void jooqWithoutTx() {
|
|
|
|
public void jooqWithoutTx() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class)
|
|
|
|
.withUserConfiguration(JooqDataSourceConfiguration.class)
|
|
|
|
|
|
|
|
.run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
assertThat(context.getBeanNamesForType(
|
|
|
|
assertThat(context).doesNotHaveBean(PlatformTransactionManager.class);
|
|
|
|
PlatformTransactionManager.class)).isEqualTo(NO_BEANS);
|
|
|
|
assertThat(context).doesNotHaveBean(SpringTransactionProvider.class);
|
|
|
|
assertThat(context.getBeanNamesForType(
|
|
|
|
|
|
|
|
SpringTransactionProvider.class)).isEqualTo(NO_BEANS);
|
|
|
|
|
|
|
|
DSLContext dsl = context.getBean(DSLContext.class);
|
|
|
|
DSLContext dsl = context.getBean(DSLContext.class);
|
|
|
|
dsl.execute("create table jooqtest (name varchar(255) primary key);");
|
|
|
|
dsl.execute("create table jooqtest (name varchar(255) primary key);");
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
@ -92,8 +86,7 @@ public class JooqAutoConfigurationTests {
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
"select count(*) as total from jooqtest;", "1"));
|
|
|
|
"select count(*) as total from jooqtest;", "1"));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dsl.transaction(
|
|
|
|
dsl.transaction(new ExecuteSql(dsl,
|
|
|
|
new ExecuteSql(dsl,
|
|
|
|
|
|
|
|
"insert into jooqtest (name) values ('bar');",
|
|
|
|
"insert into jooqtest (name) values ('bar');",
|
|
|
|
"insert into jooqtest (name) values ('foo');"));
|
|
|
|
"insert into jooqtest (name) values ('foo');"));
|
|
|
|
fail("An DataIntegrityViolationException should have been thrown.");
|
|
|
|
fail("An DataIntegrityViolationException should have been thrown.");
|
|
|
@ -101,22 +94,21 @@ public class JooqAutoConfigurationTests {
|
|
|
|
catch (DataIntegrityViolationException ex) {
|
|
|
|
catch (DataIntegrityViolationException ex) {
|
|
|
|
// Ignore
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dsl.transaction(
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
new AssertFetch(dsl,
|
|
|
|
|
|
|
|
"select count(*) as total from jooqtest;", "2"));
|
|
|
|
"select count(*) as total from jooqtest;", "2"));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void jooqWithTx() {
|
|
|
|
public void jooqWithTx() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
|
|
|
|
.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class)
|
|
|
|
TxManagerConfiguration.class).run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
assertThat(context).hasSingleBean(PlatformTransactionManager.class);
|
|
|
|
context.getBean(PlatformTransactionManager.class);
|
|
|
|
|
|
|
|
DSLContext dsl = context.getBean(DSLContext.class);
|
|
|
|
DSLContext dsl = context.getBean(DSLContext.class);
|
|
|
|
assertThat(dsl.configuration().dialect()).isEqualTo(SQLDialect.HSQLDB);
|
|
|
|
assertThat(dsl.configuration().dialect())
|
|
|
|
dsl.execute("create table jooqtest_tx (name varchar(255) primary key);");
|
|
|
|
.isEqualTo(SQLDialect.HSQLDB);
|
|
|
|
|
|
|
|
dsl.execute(
|
|
|
|
|
|
|
|
"create table jooqtest_tx (name varchar(255) primary key);");
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
"select count(*) as total from jooqtest_tx;", "0"));
|
|
|
|
"select count(*) as total from jooqtest_tx;", "0"));
|
|
|
|
dsl.transaction(new ExecuteSql(dsl,
|
|
|
|
dsl.transaction(new ExecuteSql(dsl,
|
|
|
@ -124,16 +116,15 @@ public class JooqAutoConfigurationTests {
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
"select count(*) as total from jooqtest_tx;", "1"));
|
|
|
|
"select count(*) as total from jooqtest_tx;", "1"));
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
dsl.transaction(
|
|
|
|
dsl.transaction(new ExecuteSql(dsl,
|
|
|
|
new ExecuteSql(dsl, "insert into jooqtest (name) values ('bar');",
|
|
|
|
"insert into jooqtest (name) values ('bar');",
|
|
|
|
"insert into jooqtest (name) values ('foo');"));
|
|
|
|
"insert into jooqtest (name) values ('foo');"));
|
|
|
|
fail("A DataIntegrityViolationException should have been thrown.");
|
|
|
|
fail("A DataIntegrityViolationException should have been thrown.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (DataIntegrityViolationException ex) {
|
|
|
|
catch (DataIntegrityViolationException ex) {
|
|
|
|
// Ignore
|
|
|
|
// Ignore
|
|
|
|
}
|
|
|
|
}
|
|
|
|
dsl.transaction(
|
|
|
|
dsl.transaction(new AssertFetch(dsl,
|
|
|
|
new AssertFetch(dsl,
|
|
|
|
|
|
|
|
"select count(*) as total from jooqtest_tx;", "1"));
|
|
|
|
"select count(*) as total from jooqtest_tx;", "1"));
|
|
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
@ -141,28 +132,28 @@ public class JooqAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void customProvidersArePickedUp() {
|
|
|
|
public void customProvidersArePickedUp() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class,
|
|
|
|
.withUserConfiguration(JooqDataSourceConfiguration.class, TxManagerConfiguration.class,
|
|
|
|
TxManagerConfiguration.class, TestRecordMapperProvider.class,
|
|
|
|
TestRecordMapperProvider.class, TestRecordListenerProvider.class,
|
|
|
|
TestRecordListenerProvider.class, TestExecuteListenerProvider.class,
|
|
|
|
TestExecuteListenerProvider.class, TestVisitListenerProvider.class)
|
|
|
|
TestVisitListenerProvider.class).run((context) -> {
|
|
|
|
.run((context) -> {
|
|
|
|
|
|
|
|
DSLContext dsl = context.getBean(DSLContext.class);
|
|
|
|
DSLContext dsl = context.getBean(DSLContext.class);
|
|
|
|
assertThat(dsl.configuration().recordMapperProvider().getClass())
|
|
|
|
assertThat(dsl.configuration().recordMapperProvider().getClass())
|
|
|
|
.isEqualTo(TestRecordMapperProvider.class);
|
|
|
|
.isEqualTo(TestRecordMapperProvider.class);
|
|
|
|
assertThat(dsl.configuration().recordListenerProviders().length).isEqualTo(1);
|
|
|
|
assertThat(dsl.configuration().recordListenerProviders().length)
|
|
|
|
assertThat(dsl.configuration().executeListenerProviders().length).isEqualTo(2);
|
|
|
|
.isEqualTo(1);
|
|
|
|
assertThat(dsl.configuration().visitListenerProviders().length).isEqualTo(1);
|
|
|
|
assertThat(dsl.configuration().executeListenerProviders().length)
|
|
|
|
|
|
|
|
.isEqualTo(2);
|
|
|
|
|
|
|
|
assertThat(dsl.configuration().visitListenerProviders().length)
|
|
|
|
|
|
|
|
.isEqualTo(1);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void relaxedBindingOfSqlDialect() {
|
|
|
|
public void relaxedBindingOfSqlDialect() {
|
|
|
|
this.contextRunner
|
|
|
|
this.contextRunner.withUserConfiguration(JooqDataSourceConfiguration.class)
|
|
|
|
.withUserConfiguration(JooqDataSourceConfiguration.class)
|
|
|
|
.withPropertyValues("spring.jooq.sql-dialect:PoSTGrES").run((context) -> {
|
|
|
|
.withPropertyValues("spring.jooq.sql-dialect:PoSTGrES")
|
|
|
|
assertThat(context.getBean(org.jooq.Configuration.class).dialect())
|
|
|
|
.run((context) -> {
|
|
|
|
.isEqualTo(SQLDialect.POSTGRES);
|
|
|
|
assertThat(context.getBean(org.jooq.Configuration.class)
|
|
|
|
|
|
|
|
.dialect()).isEqualTo(SQLDialect.POSTGRES);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|