Upgrade to SD-Hopper and other fixes
Fixes https://build.spring.io/browse/INT-MJATS41-593 * Fix `LoggingHandler` JavaDoc * Fix `JdbcOutboundGatewayParserTests` timing and race condition issues * Add `mock(BeanFactory.class)` to the `JpaOutboundChannelAdapterTests` for `JpaExecutor` * Fix `JpaOutboundChannelAdapterTests` for the incorrect transaction usage
This commit is contained in:
committed by
Gary Russell
parent
ba2a713c75
commit
13d11e5035
26
build.gradle
26
build.gradle
@@ -97,7 +97,7 @@ subprojects { subproject ->
|
||||
|
||||
ext {
|
||||
activeMqVersion = '5.12.2'
|
||||
aspectjVersion = '1.8.7'
|
||||
aspectjVersion = '1.8.9'
|
||||
apacheSshdVersion = '0.14.0'
|
||||
boonVersion = '0.33'
|
||||
chronicleVersion = '3.5.3'
|
||||
@@ -106,30 +106,30 @@ subprojects { subproject ->
|
||||
commonsNetVersion = '3.4'
|
||||
curatorVersion = '2.8.0'
|
||||
derbyVersion = '10.11.1.1'
|
||||
eclipseLinkVersion = '2.4.2'
|
||||
eclipseLinkVersion = '2.5.2'
|
||||
ftpServerVersion = '1.0.6'
|
||||
groovyVersion = '2.4.5'
|
||||
guavaVersion = '19.0'
|
||||
hamcrestVersion = '1.3'
|
||||
hazelcastVersion = '3.5.1'
|
||||
hibernateVersion = '4.3.10.Final'
|
||||
hazelcastVersion = '3.6.1'
|
||||
hibernateVersion = '5.1.0.Final'
|
||||
hsqldbVersion = '2.3.3'
|
||||
h2Version = '1.4.180'
|
||||
jackson2Version = '2.5.4'
|
||||
jackson2Version = '2.7.3'
|
||||
javaxActivationVersion = '1.1.1'
|
||||
javaxMailVersion = '1.5.5'
|
||||
jedisVersion = '2.7.3'
|
||||
jmsApiVersion = '1.1-rev-1'
|
||||
jpa21ApiVersion = '1.0.0.Final'
|
||||
jpaApiVersion = '2.0.0'
|
||||
jpaApiVersion = '2.1.1'
|
||||
jrubyVersion = '1.7.23'
|
||||
jschVersion = '0.1.52'
|
||||
jsonpathVersion = '2.1.0'
|
||||
jsonpathVersion = '2.2.0'
|
||||
junitVersion = '4.12'
|
||||
jythonVersion = '2.5.3'
|
||||
kryoShadedVersion = '3.0.3'
|
||||
log4jVersion = '1.2.17'
|
||||
mockitoVersion = '1.9.5'
|
||||
mockitoVersion = '1.10.19'
|
||||
mysqlVersion = '5.1.34'
|
||||
nettyVersion = '4.0.27.Final'
|
||||
openJpaVersion = '2.4.0'
|
||||
@@ -140,16 +140,16 @@ subprojects { subproject ->
|
||||
saajApiVersion = '1.3.5'
|
||||
saajImplVersion = '1.3.23'
|
||||
servletApiVersion = '3.1.0'
|
||||
slf4jVersion = "1.7.13"
|
||||
slf4jVersion = "1.7.21"
|
||||
tomcatVersion = "8.0.30"
|
||||
smack3Version = '3.2.1'
|
||||
smackVersion = '4.1.6'
|
||||
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.6.0.BUILD-SNAPSHOT'
|
||||
// springCloudClusterVersion = '1.0.0.BUILD-SNAPSHOT'
|
||||
springDataJpaVersion = '1.10.0.M1'
|
||||
springDataMongoVersion = '1.9.0.M1'
|
||||
springDataRedisVersion = '1.7.0.M1'
|
||||
springGemfireVersion = '1.8.0.M1'
|
||||
springDataJpaVersion = '1.10.1.RELEASE'
|
||||
springDataMongoVersion = '1.9.1.RELEASE'
|
||||
springDataRedisVersion = '1.7.1.RELEASE'
|
||||
springGemfireVersion = '1.8.1.RELEASE'
|
||||
springSecurityVersion = project.hasProperty('springSecurityVersion') ? project.springSecurityVersion : '4.0.3.RELEASE'
|
||||
springSocialTwitterVersion = '1.1.1.RELEASE'
|
||||
springRetryVersion = '1.1.2.RELEASE'
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.expression.EvaluationContext;
|
||||
import org.springframework.expression.Expression;
|
||||
import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.integration.dispatcher.AggregateMessageDeliveryException;
|
||||
import org.springframework.integration.expression.ExpressionUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
@@ -47,9 +46,6 @@ public class LoggingHandler extends AbstractMessageHandler {
|
||||
FATAL, ERROR, WARN, INFO, DEBUG, TRACE
|
||||
}
|
||||
|
||||
private static final SpelExpressionParser EXPRESSION_PARSER = new SpelExpressionParser();
|
||||
|
||||
|
||||
private volatile Expression expression;
|
||||
|
||||
private volatile boolean expressionSet;
|
||||
@@ -69,7 +65,7 @@ public class LoggingHandler extends AbstractMessageHandler {
|
||||
* The valid levels are: FATAL, ERROR, WARN, INFO, DEBUG, or TRACE
|
||||
* </p>
|
||||
* @param level The level.
|
||||
* @see LoggingHandler(Level)
|
||||
* @see #LoggingHandler(Level)
|
||||
*/
|
||||
public LoggingHandler(String level) {
|
||||
Assert.hasText(level, "'level' cannot be empty");
|
||||
|
||||
@@ -33,7 +33,6 @@ import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
@@ -73,21 +72,23 @@ public class JdbcOutboundGatewayParserTests {
|
||||
@Test
|
||||
public void testMapPayloadMapReply() {
|
||||
setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
|
||||
assertTrue(context.containsBean("jdbcGateway"));
|
||||
assertTrue(this.context.containsBean("jdbcGateway"));
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
channel.send(message);
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
Message<?> reply = messagingTemplate.receive();
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
assertEquals("bar", payload.get("name"));
|
||||
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from FOOS");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
|
||||
JdbcOutboundGateway gateway = context.getBean("jdbcGateway.handler", JdbcOutboundGateway.class);
|
||||
assertEquals(23, TestUtils.getPropertyValue(gateway, "order"));
|
||||
Assert.assertTrue(TestUtils.getPropertyValue(gateway, "requiresReply", Boolean.class));
|
||||
Object gw = context.getBean("jdbcGateway");
|
||||
assertEquals(1, adviceCalled);
|
||||
}
|
||||
|
||||
@@ -96,12 +97,16 @@ public class JdbcOutboundGatewayParserTests {
|
||||
public void testKeyGeneration() {
|
||||
setUp("handlingKeyGenerationJdbcOutboundGatewayTest.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
channel.send(message);
|
||||
Message<?> reply = messagingTemplate.receive();
|
||||
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
Object id = payload.get("SCOPE_IDENTITY()");
|
||||
assertNotNull(id);
|
||||
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from BARS");
|
||||
assertEquals("Wrong id", id, map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
@@ -110,7 +115,7 @@ public class JdbcOutboundGatewayParserTests {
|
||||
|
||||
MessageChannel setterRequest = this.context.getBean("setterRequest", MessageChannel.class);
|
||||
setterRequest.send(new GenericMessage<String>("bar2"));
|
||||
reply = messagingTemplate.receive();
|
||||
reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
|
||||
payload = (Map<String, ?>) reply.getPayload();
|
||||
@@ -125,8 +130,10 @@ public class JdbcOutboundGatewayParserTests {
|
||||
public void testCountUpdates() {
|
||||
setUp("handlingCountUpdatesJdbcOutboundGatewayTest.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
channel.send(message);
|
||||
Message<?> reply = messagingTemplate.receive();
|
||||
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
@@ -137,37 +144,33 @@ public class JdbcOutboundGatewayParserTests {
|
||||
public void testWithPoller() throws Exception {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
MessageChannel target = context.getBean("target", MessageChannel.class);
|
||||
PollableChannel output = context.getBean("output", PollableChannel.class);
|
||||
target.send(message);
|
||||
Thread.sleep(1000);
|
||||
Map<String, Object> map = (context.getBean("jdbcTemplate", JdbcTemplate.class)).queryForMap("SELECT * from BAZZ");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
Message<?> reply = output.receive(1000);
|
||||
|
||||
this.channel.send(message);
|
||||
|
||||
Message<?> reply = this.messagingTemplate.receive();
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
assertEquals("bar", payload.get("name"));
|
||||
|
||||
Map<String, Object> map = this.jdbcTemplate.queryForMap("SELECT * from BAZZ");
|
||||
assertEquals("Wrong id", message.getHeaders().getId().toString(), map.get("ID"));
|
||||
assertEquals("Wrong name", "bar", map.get("name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithSelectQueryOnly() throws Exception {
|
||||
this.context = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithSelectTest-context.xml", this.getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Integer.valueOf(100)).build();
|
||||
MessageChannel requestChannel = context.getBean("request", MessageChannel.class);
|
||||
PollableChannel replyChannel = context.getBean("reply", PollableChannel.class);
|
||||
setUp("JdbcOutboundGatewayWithSelectTest-context.xml", getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(100).build();
|
||||
|
||||
requestChannel.send(message);
|
||||
Thread.sleep(1000);
|
||||
this.channel.send(message);
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
Message<Map<String, Object>> reply = (Message<Map<String, Object>>) replyChannel.receive(500);
|
||||
Message<Map<String, Object>> reply = (Message<Map<String, Object>>) this.messagingTemplate.receive();
|
||||
|
||||
String id = (String) reply.getPayload().get("id");
|
||||
Integer status = (Integer) reply.getPayload().get("status");
|
||||
String name = (String) reply.getPayload().get("name");
|
||||
ApplicationContext ac = this.context;
|
||||
|
||||
assertEquals("100", id);
|
||||
assertEquals(Integer.valueOf(3), status);
|
||||
@@ -175,7 +178,7 @@ public class JdbcOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplyTimeoutIsSet() throws Exception {
|
||||
public void testReplyTimeoutIsSet() {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", getClass());
|
||||
|
||||
PollingConsumer outboundGateway = this.context.getBean("jdbcOutboundGateway", PollingConsumer.class);
|
||||
@@ -195,11 +198,10 @@ public class JdbcOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultMaxMessagesPerPollIsSet() throws Exception {
|
||||
|
||||
public void testDefaultMaxMessagesPerPollIsSet() {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
|
||||
PollingConsumer pollingConsumer = context.getBean(PollingConsumer.class);
|
||||
PollingConsumer pollingConsumer = this.context.getBean(PollingConsumer.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
@@ -212,11 +214,10 @@ public class JdbcOutboundGatewayParserTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxMessagesPerPollIsSet() throws Exception {
|
||||
|
||||
public void testMaxMessagesPerPollIsSet() {
|
||||
setUp("JdbcOutboundGatewayWithPoller2Test-context.xml", this.getClass());
|
||||
|
||||
PollingConsumer pollingConsumer = context.getBean(PollingConsumer.class);
|
||||
PollingConsumer pollingConsumer = this.context.getBean(PollingConsumer.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
@@ -225,25 +226,24 @@ public class JdbcOutboundGatewayParserTests {
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRowsPerPoll");
|
||||
assertEquals("maxRowsPerPoll should default to 10", Integer.valueOf(10), maxRowsPerPoll);
|
||||
|
||||
}
|
||||
|
||||
@Test //INT-1029
|
||||
public void testOutboundGatewayInsideChain() {
|
||||
setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
|
||||
|
||||
JdbcOutboundGateway jdbcMessageHandler =
|
||||
context.getBean("org.springframework.integration.handler.MessageHandlerChain#0$child.jdbc-outbound-gateway-within-chain.handler",
|
||||
JdbcOutboundGateway.class);
|
||||
String beanName = "org.springframework.integration.handler.MessageHandlerChain#" +
|
||||
"0$child.jdbc-outbound-gateway-within-chain.handler";
|
||||
JdbcOutboundGateway jdbcMessageHandler = this.context.getBean(beanName, JdbcOutboundGateway.class);
|
||||
|
||||
MessageChannel channel = context.getBean("jdbcOutboundGatewayInsideChain", MessageChannel.class);
|
||||
MessageChannel channel = this.context.getBean("jdbcOutboundGatewayInsideChain", MessageChannel.class);
|
||||
|
||||
assertFalse(TestUtils.getPropertyValue(jdbcMessageHandler, "requiresReply", Boolean.class));
|
||||
|
||||
channel.send(MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build());
|
||||
|
||||
PollableChannel outbound = context.getBean("replyChannel", PollableChannel.class);
|
||||
Message<?> reply = outbound.receive();
|
||||
PollableChannel outbound = this.context.getBean("replyChannel", PollableChannel.class);
|
||||
Message<?> reply = outbound.receive(10000);
|
||||
assertNotNull(reply);
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, ?> payload = (Map<String, ?>) reply.getPayload();
|
||||
@@ -253,8 +253,8 @@ public class JdbcOutboundGatewayParserTests {
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
if (this.context != null) {
|
||||
this.context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,13 +262,13 @@ public class JdbcOutboundGatewayParserTests {
|
||||
PollableChannel pollableChannel = this.context.getBean("output", PollableChannel.class);
|
||||
this.messagingTemplate = new MessagingTemplate();
|
||||
this.messagingTemplate.setDefaultDestination(pollableChannel);
|
||||
this.messagingTemplate.setReceiveTimeout(500);
|
||||
this.messagingTemplate.setReceiveTimeout(10000);
|
||||
}
|
||||
|
||||
public void setUp(String name, Class<?> cls) {
|
||||
context = new ClassPathXmlApplicationContext(name, cls);
|
||||
jdbcTemplate = new JdbcTemplate(this.context.getBean("dataSource", DataSource.class));
|
||||
channel = this.context.getBean("target", MessageChannel.class);
|
||||
this.context = new ClassPathXmlApplicationContext(name, cls);
|
||||
this.jdbcTemplate = new JdbcTemplate(this.context.getBean("dataSource", DataSource.class));
|
||||
this.channel = this.context.getBean("target", MessageChannel.class);
|
||||
setupMessagingTemplate();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
|
||||
|
||||
<int:channel id="target">
|
||||
@@ -15,26 +15,28 @@
|
||||
</int:channel>
|
||||
|
||||
<int:channel id="output">
|
||||
<int:queue />
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway" query="select * from bazz where id=:headers[id]" update="insert into bazz (id, status, name) values (:headers[id], 0, :payload[foo])"
|
||||
request-channel="target" reply-channel="output" data-source="dataSource" auto-startup="true" reply-timeout="444">
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway"
|
||||
query="select * from bazz where id=:headers[id]"
|
||||
update="insert into bazz (id, status, name) values (:headers[id], 0, :payload[foo])"
|
||||
request-channel="target"
|
||||
reply-channel="output"
|
||||
data-source="dataSource"
|
||||
auto-startup="true"
|
||||
reply-timeout="444">
|
||||
<int:poller fixed-rate="1000"/>
|
||||
</int-jdbc:outbound-gateway>
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchema.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchema.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource" />
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,36 +1,42 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.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/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xmlns:int-jdbc="http://www.springframework.org/schema/integration/jdbc"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc">
|
||||
|
||||
|
||||
<int:channel id="request"/>
|
||||
<int:channel id="reply">
|
||||
<int:channel id="target"/>
|
||||
|
||||
<int:channel id="output">
|
||||
<int:queue/>
|
||||
</int:channel>
|
||||
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway" query="select * from bazz where id=:payload"
|
||||
request-channel="request" reply-channel="reply" data-source="dataSource" auto-startup="true" reply-timeout="444">
|
||||
<int-jdbc:outbound-gateway id="jdbcOutboundGateway"
|
||||
query="select * from bazz where id=:payload"
|
||||
request-channel="target"
|
||||
reply-channel="output"
|
||||
data-source="dataSource"
|
||||
auto-startup="true"
|
||||
reply-timeout="444">
|
||||
</int-jdbc:outbound-gateway>
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchemaWithData.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
<jdbc:initialize-database data-source="dataSource" ignore-failures="DROPS">
|
||||
<jdbc:script location="classpath:org/springframework/integration/jdbc/config/outboundPollerSchemaWithData.sql"/>
|
||||
</jdbc:initialize-database>
|
||||
|
||||
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
|
||||
<property name="dataSource" ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
|
||||
<constructor-arg ref="dataSource" />
|
||||
<constructor-arg ref="dataSource"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -19,10 +19,11 @@ package org.springframework.integration.jpa.outbound;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -36,14 +37,13 @@ import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.test.annotation.Rollback;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
import org.springframework.transaction.TransactionDefinition;
|
||||
import org.springframework.transaction.TransactionStatus;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
||||
import org.springframework.transaction.support.TransactionTemplate;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -55,8 +55,7 @@ import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@Rollback
|
||||
@Transactional("transactionManager")
|
||||
@DirtiesContext
|
||||
public class JpaOutboundChannelAdapterTests {
|
||||
|
||||
@Autowired
|
||||
@@ -71,9 +70,9 @@ public class JpaOutboundChannelAdapterTests {
|
||||
@Autowired
|
||||
private MessageChannel jpaOutboundChannelAdapterWithinChain;
|
||||
|
||||
@After
|
||||
@Before
|
||||
public void cleanUp() {
|
||||
this.jdbcTemplate.execute("delete from Student where rollNumber > 1003");
|
||||
this.jdbcTemplate.execute("delete from Student where rollNumber > 1003 or rollNumber < 1001");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,22 +84,24 @@ public class JpaOutboundChannelAdapterTests {
|
||||
|
||||
JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
|
||||
jpaExecutor.setEntityClass(StudentDomain.class);
|
||||
jpaExecutor.setBeanFactory(mock(BeanFactory.class));
|
||||
jpaExecutor.afterPropertiesSet();
|
||||
|
||||
JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
|
||||
final JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
|
||||
jpaOutboundChannelAdapter.setProducesReply(false);
|
||||
|
||||
StudentDomain testStudent = JpaTestUtils.getTestStudent();
|
||||
Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
|
||||
final Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
|
||||
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
// explicitly setting the transaction name is something that can only be done programmatically
|
||||
def.setName("SomeTxName");
|
||||
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
|
||||
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||
|
||||
TransactionStatus status = transactionManager.getTransaction(def);
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
transactionManager.commit(status);
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results2);
|
||||
@@ -118,22 +119,24 @@ public class JpaOutboundChannelAdapterTests {
|
||||
Assert.assertTrue(results1.size() == 3);
|
||||
|
||||
JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
|
||||
jpaExecutor.setBeanFactory(mock(BeanFactory.class));
|
||||
jpaExecutor.afterPropertiesSet();
|
||||
|
||||
JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
|
||||
final JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
|
||||
jpaOutboundChannelAdapter.setProducesReply(false);
|
||||
|
||||
StudentDomain testStudent = JpaTestUtils.getTestStudent();
|
||||
Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
|
||||
final Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
|
||||
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
// explicitly setting the transaction name is something that can only be done programmatically
|
||||
def.setName("SomeTxName");
|
||||
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
|
||||
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||
|
||||
TransactionStatus status = transactionManager.getTransaction(def);
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
transactionManager.commit(status);
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results2);
|
||||
@@ -153,28 +156,30 @@ public class JpaOutboundChannelAdapterTests {
|
||||
JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
|
||||
jpaExecutor.setEntityClass(StudentDomain.class);
|
||||
jpaExecutor.setPersistMode(PersistMode.PERSIST);
|
||||
jpaExecutor.setBeanFactory(mock(BeanFactory.class));
|
||||
jpaExecutor.afterPropertiesSet();
|
||||
|
||||
JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
|
||||
final JpaOutboundGateway jpaOutboundChannelAdapter = new JpaOutboundGateway(jpaExecutor);
|
||||
jpaOutboundChannelAdapter.setProducesReply(false);
|
||||
|
||||
StudentDomain testStudent = JpaTestUtils.getTestStudent();
|
||||
|
||||
Assert.assertNull(testStudent.getRollNumber());
|
||||
|
||||
Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
|
||||
final Message<StudentDomain> message = MessageBuilder.withPayload(testStudent).build();
|
||||
|
||||
jpaOutboundChannelAdapter.setBeanFactory(mock(BeanFactory.class));
|
||||
jpaOutboundChannelAdapter.afterPropertiesSet();
|
||||
|
||||
DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||
// explicitly setting the transaction name is something that can only be done programmatically
|
||||
def.setName("SomeTxName");
|
||||
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
|
||||
TransactionTemplate transactionTemplate = new TransactionTemplate(this.transactionManager);
|
||||
transactionTemplate.execute(new TransactionCallbackWithoutResult() {
|
||||
|
||||
TransactionStatus status = transactionManager.getTransaction(def);
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
transactionManager.commit(status);
|
||||
@Override
|
||||
protected void doInTransactionWithoutResult(TransactionStatus status) {
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results2);
|
||||
|
||||
Reference in New Issue
Block a user