Skip to content

Commit 171d169

Browse files
committed
Fix JDBC tests to close embedded DB
https://build.spring.io/browse/INT-MJATS41-1030 **Cherry-pick to 4.3.x**
1 parent e16e81f commit 171d169

File tree

4 files changed

+23
-34
lines changed

4 files changed

+23
-34
lines changed
Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,29 +20,28 @@
2020
import static org.junit.Assert.fail;
2121
import static org.mockito.Mockito.mock;
2222

23-
import javax.sql.DataSource;
24-
2523
import org.junit.Assert;
2624
import org.junit.Test;
2725

2826
import org.springframework.beans.factory.BeanFactory;
2927
import org.springframework.jdbc.core.JdbcOperations;
28+
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
3029
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
3130

3231
/**
3332
*
3433
* @author Gunnar Hillert
3534
* @author Gary Russell
35+
* @author Artem Bilan
36+
*
3637
* @since 2.1
3738
*
3839
*/
3940
public class JdbcOutboundGatewayTests {
4041

4142
@Test
4243
public void testSetMaxRowsPerPollWithoutSelectQuery() {
43-
44-
45-
DataSource dataSource = new EmbeddedDatabaseBuilder().build();
44+
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
4645

4746
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "update something");
4847

@@ -51,18 +50,17 @@ public void testSetMaxRowsPerPollWithoutSelectQuery() {
5150
jdbcOutboundGateway.setBeanFactory(mock(BeanFactory.class));
5251
jdbcOutboundGateway.afterPropertiesSet();
5352

53+
fail("Expected an IllegalArgumentException to be thrown.");
5454
}
5555
catch (IllegalArgumentException e) {
5656
assertEquals("If you want to set 'maxRowsPerPoll', then you must provide a 'selectQuery'.", e.getMessage());
57-
return;
5857
}
5958

60-
fail("Expected an IllegalArgumentException to be thrown.");
61-
59+
dataSource.shutdown();
6260
}
6361

6462
@Test
65-
public void testConstructorWithNulljdbcOperations() {
63+
public void testConstructorWithNullJdbcOperations() {
6664

6765
JdbcOperations jdbcOperations = null;
6866

@@ -79,44 +77,39 @@ public void testConstructorWithNulljdbcOperations() {
7977

8078
@Test
8179
public void testConstructorWithEmptyAndNullQueries() {
82-
83-
final DataSource dataSource = new EmbeddedDatabaseBuilder().build();
80+
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
8481

8582
final String selectQuery = " ";
8683
final String updateQuery = null;
8784

8885
try {
8986
new JdbcOutboundGateway(dataSource, updateQuery, selectQuery);
87+
88+
fail("Expected an IllegalArgumentException to be thrown.");
9089
}
9190
catch (IllegalArgumentException e) {
9291
Assert.assertEquals("The 'updateQuery' and the 'selectQuery' must not both be null or empty.", e.getMessage());
93-
return;
9492
}
9593

96-
fail("Expected an IllegalArgumentException to be thrown.");
94+
dataSource.shutdown();
9795
}
9896

99-
/**
100-
* Test method for
101-
* {@link org.springframework.integration.jdbc.JdbcOutboundGateway#setMaxRowsPerPoll(Integer)}.
102-
*/
10397
@Test
10498
public void testSetMaxRowsPerPoll() {
105-
106-
107-
DataSource dataSource = new EmbeddedDatabaseBuilder().build();
99+
EmbeddedDatabase dataSource = new EmbeddedDatabaseBuilder().build();
108100

109101
JdbcOutboundGateway jdbcOutboundGateway = new JdbcOutboundGateway(dataSource, "select * from DOES_NOT_EXIST");
110102

111103
try {
112104
jdbcOutboundGateway.setMaxRowsPerPoll(null);
105+
106+
fail("Expected an IllegalArgumentException to be thrown.");
113107
}
114108
catch (IllegalArgumentException e) {
115109
assertEquals("MaxRowsPerPoll must not be null.", e.getMessage());
116-
return;
117110
}
118111

119-
fail("Expected an IllegalArgumentException to be thrown.");
120-
112+
dataSource.shutdown();
121113
}
114+
122115
}

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcJavaConfigTests.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2016 the original author or authors.
2+
* Copyright 2015-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -61,6 +61,8 @@
6161
* Equivalent to {@link StoredProcPollingChannelAdapterWithNamespaceIntegrationTests}.
6262
*
6363
* @author Gary Russell
64+
* @author Artem Bilan
65+
*
6466
* @since 4.2
6567
*
6668
*/
@@ -130,7 +132,7 @@ public StoredProcExecutor storedProcExecutor() {
130132
return executor;
131133
}
132134

133-
@Bean
135+
@Bean(destroyMethod = "shutdown")
134136
public DataSource dataSource() {
135137
return new EmbeddedDatabaseBuilder()
136138
.setType(EmbeddedDatabaseType.H2)

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests-context.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:int="http://www.springframework.org/schema/integration"
5-
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
65
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
7-
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
8-
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
6+
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
97
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
108
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
119

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespaceIntegrationTests-context.xml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,12 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:int="http://www.springframework.org/schema/integration"
5-
xmlns:tx="http://www.springframework.org/schema/tx"
6-
xmlns:util="http://www.springframework.org/schema/util"
75
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
86
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
97
xsi:schemaLocation="http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
108
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
119
http://www.springframework.org/schema/integration/jdbc http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc.xsd
12-
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
13-
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
14-
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd">
10+
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
1511

1612
<jdbc:embedded-database id="dataSource" type="H2">
1713
<jdbc:script location="classpath:h2-stored-procedures.sql"/>

0 commit comments

Comments
 (0)