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:
Artem Bilan
2017-06-23 09:10:32 -04:00
parent e16e81f780
commit 171d169748
4 changed files with 23 additions and 34 deletions

View File

@@ -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");
* 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.mockito.Mockito.mock;
import javax.sql.DataSource;
import org.junit.Assert;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
/**
*
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.1
*
*/
@@ -40,9 +41,7 @@ public class JdbcOutboundGatewayTests {
@Test
public void testSetMaxRowsPerPollWithoutSelectQuery() {
DataSource dataSource = new EmbeddedDatabaseBuilder().build();
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "update something");
@@ -51,18 +50,17 @@ public class JdbcOutboundGatewayTests {
jdbcOutboundGateway.setBeanFactory(mock(BeanFactory.class));
jdbcOutboundGateway.afterPropertiesSet();
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
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
public void testConstructorWithNulljdbcOperations() {
public void testConstructorWithNullJdbcOperations() {
JdbcOperations jdbcOperations = null;
@@ -79,44 +77,39 @@ public class JdbcOutboundGatewayTests {
@Test
public void testConstructorWithEmptyAndNullQueries() {
final DataSource dataSource = new EmbeddedDatabaseBuilder().build();
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
final String selectQuery = " ";
final String updateQuery = null;
try {
new JdbcOutboundGateway(dataSource, updateQuery, selectQuery);
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
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
public void testSetMaxRowsPerPoll() {
DataSource dataSource = new EmbeddedDatabaseBuilder().build();
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "select * from DOES_NOT_EXIST");
try {
jdbcOutboundGateway.setMaxRowsPerPoll(null);
fail("Expected an IllegalArgumentException to be thrown.");
}
catch (IllegalArgumentException e) {
assertEquals("MaxRowsPerPoll must not be null.", e.getMessage());
return;
}
fail("Expected an IllegalArgumentException to be thrown.");
dataSource.shutdown();
}
}

View File

@@ -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");
* 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}.
*
* @author Gary Russell
* @author Artem Bilan
*
* @since 4.2
*
*/
@@ -130,7 +132,7 @@ public class StoredProcJavaConfigTests {
return executor;
}
@Bean
@Bean(destroyMethod = "shutdown")
public DataSource dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)

View File

@@ -2,10 +2,8 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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"
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
xsi:schemaLocation="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/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

View File

@@ -2,16 +2,12 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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: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
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/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">
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<jdbc:embedded-database id="dataSource" type="H2">
<jdbc:script location="classpath:h2-stored-procedures.sql"/>