INT-2557: chain with jpa:outbound-channel-adapter
Integration test for <jpa:outbound-channel-adapter> inside <chain>. Polishing JpaOutboundChannelAdapterTests for increase execution speed. Removal version from XDS URLs from the affected contexts.
This commit is contained in:
committed by
Oleg Zhurakousky
parent
030a53e6d5
commit
7e69921e13
@@ -6,13 +6,19 @@
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
xmlns:int="http://www.springframework.org/schema/integration"
|
||||
xsi:schemaLocation=
|
||||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
|
||||
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa-2.1.xsd
|
||||
"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/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd
|
||||
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
|
||||
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">
|
||||
|
||||
<import resource="BaseJpaPollingChannelAdapterTests-context.xml"/>
|
||||
|
||||
<int:chain input-channel="jpaOutboundChannelAdapterWithinChain">
|
||||
<jpa:outbound-channel-adapter entity-manager="entityManager" persist-mode="PERSIST">
|
||||
<jpa:transactional/>
|
||||
</jpa:outbound-channel-adapter>
|
||||
</int:chain>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -15,21 +15,21 @@ package org.springframework.integration.jpa.outbound;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageChannel;
|
||||
import org.springframework.integration.jpa.core.JpaExecutor;
|
||||
import org.springframework.integration.jpa.support.PersistMode;
|
||||
import org.springframework.integration.jpa.test.JpaTestUtils;
|
||||
import org.springframework.integration.jpa.test.entity.StudentDomain;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.transaction.TransactionConfiguration;
|
||||
@@ -41,6 +41,7 @@ import org.springframework.transaction.support.DefaultTransactionDefinition;
|
||||
/**
|
||||
*
|
||||
* @author Gunnar Hillert
|
||||
* @author Artem Bilan
|
||||
* @since 2.2
|
||||
*
|
||||
*/
|
||||
@@ -53,16 +54,23 @@ public class JpaOutboundChannelAdapterTests {
|
||||
private EntityManager entityManager;
|
||||
|
||||
@Autowired
|
||||
DataSource dataSource;
|
||||
JdbcTemplate jdbcTemplate;
|
||||
|
||||
@Autowired
|
||||
private PlatformTransactionManager transactionManager;
|
||||
|
||||
@Autowired
|
||||
private MessageChannel jpaOutboundChannelAdapterWithinChain;
|
||||
|
||||
@After
|
||||
public void cleanUp() {
|
||||
this.jdbcTemplate.execute("delete from Student where rollNumber > 1003");
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void saveEntityWithMerge() throws InterruptedException {
|
||||
|
||||
List<?> results1 = new JdbcTemplate(dataSource).queryForList("Select * from Student");
|
||||
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results1);
|
||||
Assert.assertTrue(results1.size() == 3);
|
||||
|
||||
@@ -85,7 +93,7 @@ public class JpaOutboundChannelAdapterTests {
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
transactionManager.commit(status);
|
||||
|
||||
List<?> results2 = new JdbcTemplate(dataSource).queryForList("Select * from Student");
|
||||
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results2);
|
||||
Assert.assertTrue(results2.size() == 4);
|
||||
|
||||
@@ -94,10 +102,9 @@ public class JpaOutboundChannelAdapterTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void saveEntityWithMergeWithoutSpecifyingEntityClass() throws InterruptedException {
|
||||
|
||||
List<?> results1 = new JdbcTemplate(dataSource).queryForList("Select * from Student");
|
||||
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results1);
|
||||
Assert.assertTrue(results1.size() == 3);
|
||||
|
||||
@@ -119,7 +126,7 @@ public class JpaOutboundChannelAdapterTests {
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
transactionManager.commit(status);
|
||||
|
||||
List<?> results2 = new JdbcTemplate(dataSource).queryForList("Select * from Student");
|
||||
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results2);
|
||||
Assert.assertTrue(results2.size() == 4);
|
||||
|
||||
@@ -130,7 +137,7 @@ public class JpaOutboundChannelAdapterTests {
|
||||
@Test
|
||||
public void saveEntityWithPersist() throws InterruptedException {
|
||||
|
||||
List<?> results1 = new JdbcTemplate(dataSource).queryForList("Select * from Student");
|
||||
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results1);
|
||||
Assert.assertTrue(results1.size() == 3);
|
||||
|
||||
@@ -159,7 +166,27 @@ public class JpaOutboundChannelAdapterTests {
|
||||
jpaOutboundChannelAdapter.handleMessage(message);
|
||||
transactionManager.commit(status);
|
||||
|
||||
List<?> results2 = new JdbcTemplate(dataSource).queryForList("Select * from Student");
|
||||
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results2);
|
||||
Assert.assertTrue(results2.size() == 4);
|
||||
|
||||
Assert.assertNotNull(testStudent.getRollNumber());
|
||||
}
|
||||
|
||||
@Test //INT-2557
|
||||
public void saveEntityWithPersistWithinChain() throws InterruptedException {
|
||||
|
||||
List<?> results1 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results1);
|
||||
Assert.assertTrue(results1.size() == 3);
|
||||
|
||||
StudentDomain testStudent = JpaTestUtils.getTestStudent();
|
||||
|
||||
Assert.assertNull(testStudent.getRollNumber());
|
||||
|
||||
this.jpaOutboundChannelAdapterWithinChain.send(MessageBuilder.withPayload(testStudent).build());
|
||||
|
||||
List<?> results2 = this.jdbcTemplate.queryForList("Select * from Student");
|
||||
Assert.assertNotNull(results2);
|
||||
Assert.assertTrue(results2.size() == 4);
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:c="http://www.springframework.org/schema/c"
|
||||
xmlns:jpa="http://www.springframework.org/schema/integration/jpa"
|
||||
xmlns:task="http://www.springframework.org/schema/task"
|
||||
xmlns:jdbc="http://www.springframework.org/schema/jdbc"
|
||||
@@ -8,12 +9,12 @@
|
||||
xmlns:tx="http://www.springframework.org/schema/tx"
|
||||
xmlns:context="http://www.springframework.org/schema/context"
|
||||
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-2.1.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
|
||||
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa-2.1.xsd">
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
|
||||
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
|
||||
http://www.springframework.org/schema/integration/jpa http://www.springframework.org/schema/integration/jpa/spring-integration-jpa.xsd">
|
||||
|
||||
<jdbc:embedded-database id="dataSource" type="H2"/>
|
||||
|
||||
@@ -22,7 +23,9 @@
|
||||
<jdbc:script location="classpath:H2-CreateTables.sql" />
|
||||
<jdbc:script location="classpath:H2-PopulateData.sql" />
|
||||
</jdbc:initialize-database>
|
||||
|
||||
|
||||
<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate" c:dataSource-ref="dataSource"/>
|
||||
|
||||
<tx:annotation-driven transaction-manager="transactionManager"/>
|
||||
<!-- <context:load-time-weaver />
|
||||
-->
|
||||
@@ -48,4 +51,4 @@
|
||||
<property name="entityManagerFactory" ref="entityManagerFactory"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
</beans>
|
||||
|
||||
Reference in New Issue
Block a user