From 171d1697482e7daa032b40d356de14d12fcec224 Mon Sep 17 00:00:00 2001 From: Artem Bilan Date: Fri, 23 Jun 2017 09:10:32 -0400 Subject: [PATCH] Fix JDBC tests to close embedded DB https://build.spring.io/browse/INT-MJATS41-1030 **Cherry-pick to 4.3.x** --- .../jdbc/JdbcOutboundGatewayTests.java | 41 ++++++++----------- .../jdbc/StoredProcJavaConfigTests.java | 6 ++- ...ChannelAdapterWithinChainTests-context.xml | 4 +- ...rWithNamespaceIntegrationTests-context.xml | 6 +-- 4 files changed, 23 insertions(+), 34 deletions(-) diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java index 4bccf86749..f4a2f3e86a 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcOutboundGatewayTests.java @@ -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(); } + } diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcJavaConfigTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcJavaConfigTests.java index 45cb288d44..404c8f8224 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcJavaConfigTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcJavaConfigTests.java @@ -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) diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests-context.xml index 037edc6342..46bb40ff26 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests-context.xml +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcOutboundChannelAdapterWithinChainTests-context.xml @@ -2,10 +2,8 @@ diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespaceIntegrationTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespaceIntegrationTests-context.xml index 4739fe0f4f..a01fc29091 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespaceIntegrationTests-context.xml +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/StoredProcPollingChannelAdapterWithNamespaceIntegrationTests-context.xml @@ -2,16 +2,12 @@ + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">