Fix JDBC tests to close embedded DB
https://build.spring.io/browse/INT-MJATS41-1030 **Cherry-pick to 4.3.x**
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2002-2016 the original author or authors.
|
* Copyright 2002-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -20,19 +20,20 @@ import static org.junit.Assert.assertEquals;
|
|||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.jdbc.core.JdbcOperations;
|
import org.springframework.jdbc.core.JdbcOperations;
|
||||||
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
|
||||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author Gunnar Hillert
|
* @author Gunnar Hillert
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
|
* @author Artem Bilan
|
||||||
|
*
|
||||||
* @since 2.1
|
* @since 2.1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -40,9 +41,7 @@ public class JdbcOutboundGatewayTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetMaxRowsPerPollWithoutSelectQuery() {
|
public void testSetMaxRowsPerPollWithoutSelectQuery() {
|
||||||
|
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
|
||||||
|
|
||||||
DataSource dataSource = new EmbeddedDatabaseBuilder().build();
|
|
||||||
|
|
||||||
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "update something");
|
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "update something");
|
||||||
|
|
||||||
@@ -51,18 +50,17 @@ public class JdbcOutboundGatewayTests {
|
|||||||
jdbcOutboundGateway.setBeanFactory(mock(BeanFactory.class));
|
jdbcOutboundGateway.setBeanFactory(mock(BeanFactory.class));
|
||||||
jdbcOutboundGateway.afterPropertiesSet();
|
jdbcOutboundGateway.afterPropertiesSet();
|
||||||
|
|
||||||
|
fail("Expected an IllegalArgumentException to be thrown.");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
assertEquals("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.", e.getMessage());
|
assertEquals("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.", e.getMessage());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fail("Expected an IllegalArgumentException to be thrown.");
|
dataSource.shutdown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithNulljdbcOperations() {
|
public void testConstructorWithNullJdbcOperations() {
|
||||||
|
|
||||||
JdbcOperations jdbcOperations = null;
|
JdbcOperations jdbcOperations = null;
|
||||||
|
|
||||||
@@ -79,44 +77,39 @@ public class JdbcOutboundGatewayTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testConstructorWithEmptyAndNullQueries() {
|
public void testConstructorWithEmptyAndNullQueries() {
|
||||||
|
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
|
||||||
final DataSource dataSource = new EmbeddedDatabaseBuilder().build();
|
|
||||||
|
|
||||||
final String selectQuery = " ";
|
final String selectQuery = " ";
|
||||||
final String updateQuery = null;
|
final String updateQuery = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new JdbcOutboundGateway(dataSource, updateQuery, selectQuery);
|
new JdbcOutboundGateway(dataSource, updateQuery, selectQuery);
|
||||||
|
|
||||||
|
fail("Expected an IllegalArgumentException to be thrown.");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
Assert.assertEquals("The 'updateQuery' and the 'selectQuery' must not both be null or empty.", e.getMessage());
|
Assert.assertEquals("The 'updateQuery' and the 'selectQuery' must not both be null or empty.", e.getMessage());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fail("Expected an IllegalArgumentException to be thrown.");
|
dataSource.shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test method for
|
|
||||||
* {@link org.springframework.integration.jdbc.JdbcOutboundGateway#setMaxRowsPerPoll(Integer)}.
|
|
||||||
*/
|
|
||||||
@Test
|
@Test
|
||||||
public void testSetMaxRowsPerPoll() {
|
public void testSetMaxRowsPerPoll() {
|
||||||
|
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
|
||||||
|
|
||||||
DataSource dataSource = new EmbeddedDatabaseBuilder().build();
|
|
||||||
|
|
||||||
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "select * from DOES_NOT_EXIST");
|
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "select * from DOES_NOT_EXIST");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
jdbcOutboundGateway.setMaxRowsPerPoll(null);
|
jdbcOutboundGateway.setMaxRowsPerPoll(null);
|
||||||
|
|
||||||
|
fail("Expected an IllegalArgumentException to be thrown.");
|
||||||
}
|
}
|
||||||
catch (IllegalArgumentException e) {
|
catch (IllegalArgumentException e) {
|
||||||
assertEquals("MaxRowsPerPoll must not be null.", e.getMessage());
|
assertEquals("MaxRowsPerPoll must not be null.", e.getMessage());
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fail("Expected an IllegalArgumentException to be thrown.");
|
dataSource.shutdown();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2015-2016 the original author or authors.
|
* Copyright 2015-2017 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -61,6 +61,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||||||
* Equivalent to {@link StoredProcPollingChannelAdapterWithNamespaceIntegrationTests}.
|
* Equivalent to {@link StoredProcPollingChannelAdapterWithNamespaceIntegrationTests}.
|
||||||
*
|
*
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
|
* @author Artem Bilan
|
||||||
|
*
|
||||||
* @since 4.2
|
* @since 4.2
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@@ -130,7 +132,7 @@ public class StoredProcJavaConfigTests {
|
|||||||
return executor;
|
return executor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean(destroyMethod = "shutdown")
|
||||||
public DataSource dataSource() {
|
public DataSource dataSource() {
|
||||||
return new EmbeddedDatabaseBuilder()
|
return new EmbeddedDatabaseBuilder()
|
||||||
.setType(EmbeddedDatabaseType.H2)
|
.setType(EmbeddedDatabaseType.H2)
|
||||||
|
|||||||
@@ -2,10 +2,8 @@
|
|||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:int="http://www.springframework.org/schema/integration"
|
xmlns:int="http://www.springframework.org/schema/integration"
|
||||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
|
||||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
|
||||||
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
|
|
||||||
|
|||||||
@@ -2,16 +2,12 @@
|
|||||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:int="http://www.springframework.org/schema/integration"
|
xmlns:int="http://www.springframework.org/schema/integration"
|
||||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
|
||||||
xmlns:util="http://www.springframework.org/schema/util"
|
|
||||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||||
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
||||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||||
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
|
||||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
|
||||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
|
|
||||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
|
|
||||||
|
|
||||||
<jdbc:embedded-database id="dataSource" type="H2">
|
<jdbc:embedded-database id="dataSource" type="H2">
|
||||||
<jdbc:script location="classpath:h2-stored-procedures.sql"/>
|
<jdbc:script location="classpath:h2-stored-procedures.sql"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user