INT-3301 Polishing
* Close Context After JDBC Tests * Fix SFTP Mock Tests JIRA: https://jira.springsource.org/browse/INT-3301
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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. You may obtain a copy of the License at
|
||||
@@ -28,11 +28,13 @@ import org.hamcrest.Matchers;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.Repeat;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -53,6 +55,7 @@ import org.springframework.util.StopWatch;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class JdbcMessageStoreChannelIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@@ -94,6 +97,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
|
||||
// appear empty....
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
|
||||
|
||||
@Override
|
||||
public Void doInTransaction(TransactionStatus status) {
|
||||
|
||||
synchronized (storeLock) {
|
||||
@@ -114,6 +118,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
|
||||
|
||||
boolean result = new TransactionTemplate(transactionManager).execute(new TransactionCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean doInTransaction(TransactionStatus status) {
|
||||
|
||||
synchronized (storeLock) {
|
||||
@@ -177,6 +182,7 @@ public class JdbcMessageStoreChannelIntegrationTests {
|
||||
boolean result = new TransactionTemplate(transactionManager, transactionDefinition)
|
||||
.execute(new TransactionCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean doInTransaction(TransactionStatus status) {
|
||||
|
||||
synchronized (storeLock) {
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
*
|
||||
* Copyright 2002-2014 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. You may obtain a copy of the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
@@ -26,11 +26,13 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.PlatformTransactionManager;
|
||||
@@ -41,6 +43,7 @@ import org.springframework.util.StopWatch;
|
||||
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class JdbcMessageStoreChannelOnePollerIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@@ -77,6 +80,7 @@ public class JdbcMessageStoreChannelOnePollerIntegrationTests {
|
||||
|
||||
boolean result = new TransactionTemplate(transactionManager).execute(new TransactionCallback<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean doInTransaction(TransactionStatus status) {
|
||||
|
||||
synchronized (storeLock) {
|
||||
@@ -115,14 +119,15 @@ public class JdbcMessageStoreChannelOnePollerIntegrationTests {
|
||||
|
||||
/*
|
||||
* Without the storeLock:
|
||||
*
|
||||
*
|
||||
* If we do this in a transaction it deadlocks occasionally. Without a transaction and it's pretty much every
|
||||
* time.
|
||||
*
|
||||
*
|
||||
* With the storeLock: It doesn't deadlock as long as the lock is injected into the poller as well.
|
||||
*/
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback<Void>() {
|
||||
|
||||
@Override
|
||||
public Void doInTransaction(TransactionStatus status) {
|
||||
synchronized (storeLock) {
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -40,13 +40,13 @@ import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.serializer.Deserializer;
|
||||
import org.springframework.core.serializer.Serializer;
|
||||
import org.springframework.integration.IntegrationMessageHeaderAccessor;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.history.MessageHistory;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
import org.springframework.integration.store.MessageGroupStore;
|
||||
import org.springframework.integration.store.MessageGroupStore.MessageGroupCallback;
|
||||
@@ -54,6 +54,8 @@ import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.util.UUIDConverter;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -69,6 +71,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class JdbcMessageStoreTests {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(JdbcMessageStoreTests.class);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -16,21 +16,23 @@
|
||||
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.jdbc.storedproc.User;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.integration.jdbc.storedproc.User;
|
||||
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.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
@@ -38,6 +40,7 @@ import static org.junit.Assert.assertEquals;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class StoredProcOutboundChannelAdapterWithinChainTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -41,6 +41,7 @@ import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -50,6 +51,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class StoredProcOutboundGatewayWithNamespaceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -37,12 +37,10 @@ import org.mockito.Mockito;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.jdbc.config.JdbcTypesEnum;
|
||||
import org.springframework.integration.jdbc.storedproc.User;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.support.json.Jackson2JsonMessageParser;
|
||||
import org.springframework.integration.support.json.JsonInboundMessageMapper;
|
||||
@@ -50,7 +48,9 @@ import org.springframework.integration.support.json.JsonOutboundMessageMapper;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.jdbc.core.SqlReturnType;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -62,6 +62,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class StoredProcOutboundGatewayWithSpelIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -29,21 +32,20 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.jdbc.storedproc.CreateUser;
|
||||
import org.springframework.integration.jdbc.storedproc.User;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class StoredProcOutboundGatewayWithSpringContextIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@@ -54,12 +56,12 @@ public class StoredProcOutboundGatewayWithSpringContextIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
CreateUser createUser;
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws Exception {
|
||||
|
||||
|
||||
createUser.createUser(new User("myUsername", "myPassword", "myEmail"));
|
||||
|
||||
|
||||
List<Message<Collection<User>>> received = new ArrayList<Message<Collection<User>>>();
|
||||
|
||||
received.add(consumer.poll(2000));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
@@ -28,19 +31,18 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class StoredProcPollingChannelAdapterWithNamespace2IntegrationTests {
|
||||
|
||||
@Autowired
|
||||
@@ -49,7 +51,7 @@ public class StoredProcPollingChannelAdapterWithNamespace2IntegrationTests {
|
||||
@Autowired
|
||||
private Consumer consumer;
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void pollH2DatabaseUsingStoredProcedureCall() throws Exception {
|
||||
List<Message<List<Integer>>> received = new ArrayList<Message<List<Integer>>>();
|
||||
@@ -61,9 +63,9 @@ public class StoredProcPollingChannelAdapterWithNamespace2IntegrationTests {
|
||||
assertNotNull(message);
|
||||
assertNotNull(message.getPayload());
|
||||
assertTrue(message.getPayload() instanceof List<?>);
|
||||
|
||||
|
||||
List<Integer> resultList = message.getPayload();
|
||||
|
||||
|
||||
assertTrue(resultList.size() == 1);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -29,19 +32,18 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class StoredProcPollingChannelAdapterWithNamespaceIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2011 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -16,6 +16,9 @@
|
||||
|
||||
package org.springframework.integration.jdbc;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -29,19 +32,18 @@ import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.support.AbstractApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Gunnar Hillert
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class StoredProcPollingChannelAdapterWithSpringContextIntegrationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -13,8 +13,8 @@
|
||||
|
||||
package org.springframework.integration.jdbc.config;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
@@ -23,16 +23,16 @@ import javax.sql.DataSource;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.integration.handler.advice.AbstractRequestHandlerAdvice;
|
||||
import org.springframework.integration.jdbc.JdbcMessageHandler;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -111,12 +111,12 @@ public class JdbcMessageHandlerParserTests {
|
||||
|
||||
@Test
|
||||
public void testOutboundAdapterWithPoller() throws Exception{
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundAdapterWithPollerTest-context.xml", this.getClass());
|
||||
MessageChannel target = ac.getBean("target", MessageChannel.class);
|
||||
setUp("JdbcOutboundAdapterWithPollerTest-context.xml", this.getClass());
|
||||
MessageChannel target = context.getBean("target", MessageChannel.class);
|
||||
Message<?> message = MessageBuilder.withPayload("foo").setHeader("business.key", "FOO").build();
|
||||
target.send(message);
|
||||
Thread.sleep(2000);
|
||||
Map<String, Object> map = (ac.getBean("jdbcTemplate", JdbcTemplate.class)).queryForMap("SELECT * from FOOW");
|
||||
Map<String, Object> map = (context.getBean("jdbcTemplate", JdbcTemplate.class)).queryForMap("SELECT * from FOOW");
|
||||
assertEquals("Wrong id", "FOO", map.get("ID"));
|
||||
assertEquals("Wrong id", "foo", map.get("name"));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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. You may obtain a copy of the License at
|
||||
@@ -113,13 +113,13 @@ public class JdbcOutboundGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testWithPoller() throws Exception{
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Collections.singletonMap("foo", "bar")).build();
|
||||
MessageChannel target = ac.getBean("target", MessageChannel.class);
|
||||
PollableChannel output = ac.getBean("output", PollableChannel.class);
|
||||
MessageChannel target = context.getBean("target", MessageChannel.class);
|
||||
PollableChannel output = context.getBean("output", PollableChannel.class);
|
||||
target.send(message);
|
||||
Thread.sleep(1000);
|
||||
Map<String, Object> map = (ac.getBean("jdbcTemplate", JdbcTemplate.class)).queryForMap("SELECT * from BAZZ");
|
||||
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);
|
||||
@@ -131,10 +131,10 @@ public class JdbcOutboundGatewayParserTests {
|
||||
|
||||
@Test
|
||||
public void testWithSelectQueryOnly() throws Exception{
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithSelectTest-context.xml", this.getClass());
|
||||
this.context = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithSelectTest-context.xml", this.getClass());
|
||||
Message<?> message = MessageBuilder.withPayload(Integer.valueOf(100)).build();
|
||||
MessageChannel requestChannel = ac.getBean("request", MessageChannel.class);
|
||||
PollableChannel replyChannel = ac.getBean("reply", PollableChannel.class);
|
||||
MessageChannel requestChannel = context.getBean("request", MessageChannel.class);
|
||||
PollableChannel replyChannel = context.getBean("reply", PollableChannel.class);
|
||||
|
||||
requestChannel.send(message);
|
||||
Thread.sleep(1000);
|
||||
@@ -145,69 +145,70 @@ public class JdbcOutboundGatewayParserTests {
|
||||
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);
|
||||
assertEquals("Cartman", name);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplyTimeoutIsSet() throws Exception {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", getClass());
|
||||
@Test
|
||||
public void testReplyTimeoutIsSet() throws Exception {
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", getClass());
|
||||
|
||||
PollingConsumer outboundGateway = this.context.getBean("jdbcOutboundGateway", PollingConsumer.class);
|
||||
PollingConsumer outboundGateway = this.context.getBean("jdbcOutboundGateway", PollingConsumer.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(outboundGateway);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
source = accessor.getPropertyValue("messagingTemplate");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(outboundGateway);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
source = accessor.getPropertyValue("messagingTemplate");
|
||||
|
||||
MessagingTemplate messagingTemplate = (MessagingTemplate) source;
|
||||
MessagingTemplate messagingTemplate = (MessagingTemplate) source;
|
||||
|
||||
accessor = new DirectFieldAccessor(messagingTemplate);
|
||||
accessor = new DirectFieldAccessor(messagingTemplate);
|
||||
|
||||
Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout");
|
||||
assertEquals("Wrong sendTimeout", Long.valueOf(444L), sendTimeout);
|
||||
Long sendTimeout = (Long) accessor.getPropertyValue("sendTimeout");
|
||||
assertEquals("Wrong sendTimeout", Long.valueOf(444L), sendTimeout);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultMaxMessagesPerPollIsSet() throws Exception {
|
||||
@Test
|
||||
public void testDefaultMaxMessagesPerPollIsSet() throws Exception {
|
||||
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
setUp("JdbcOutboundGatewayWithPollerTest-context.xml", this.getClass());
|
||||
|
||||
PollingConsumer pollingConsumer = ac.getBean(PollingConsumer.class);
|
||||
PollingConsumer pollingConsumer = context.getBean(PollingConsumer.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
source = accessor.getPropertyValue("poller"); //JdbcPollingChannelAdapter
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRowsPerPoll");
|
||||
assertEquals("maxRowsPerPoll should default to 1", Integer.valueOf(1), maxRowsPerPoll);
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
source = accessor.getPropertyValue("poller"); //JdbcPollingChannelAdapter
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRowsPerPoll");
|
||||
assertEquals("maxRowsPerPoll should default to 1", Integer.valueOf(1), maxRowsPerPoll);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMaxMessagesPerPollIsSet() throws Exception {
|
||||
@Test
|
||||
public void testMaxMessagesPerPollIsSet() throws Exception {
|
||||
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("JdbcOutboundGatewayWithPoller2Test-context.xml", this.getClass());
|
||||
setUp("JdbcOutboundGatewayWithPoller2Test-context.xml", this.getClass());
|
||||
|
||||
PollingConsumer pollingConsumer = ac.getBean(PollingConsumer.class);
|
||||
PollingConsumer pollingConsumer = context.getBean(PollingConsumer.class);
|
||||
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
source = accessor.getPropertyValue("poller"); //JdbcPollingChannelAdapter
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
Integer maxRowsPerPoll = (Integer) accessor.getPropertyValue("maxRowsPerPoll");
|
||||
assertEquals("maxRowsPerPoll should default to 10", Integer.valueOf(10), maxRowsPerPoll);
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(pollingConsumer);
|
||||
Object source = accessor.getPropertyValue("handler");
|
||||
accessor = new DirectFieldAccessor(source);
|
||||
source = accessor.getPropertyValue("poller"); //JdbcPollingChannelAdapter
|
||||
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() {
|
||||
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
|
||||
setUp("handlingMapPayloadJdbcOutboundGatewayTest.xml", getClass());
|
||||
|
||||
JdbcOutboundGateway jdbcMessageHandler =
|
||||
context.getBean("org.springframework.integration.handler.MessageHandlerChain#0$child.jdbc-outbound-gateway-within-chain.handler",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 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.
|
||||
@@ -19,6 +19,8 @@ package org.springframework.integration.jdbc.store.channel;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -27,6 +29,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class HsqlJdbcChannelMessageStoreTests extends AbstractJdbcChannelMessageStoreTests {
|
||||
|
||||
@Before
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 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. You may obtain a copy of the License at
|
||||
@@ -17,6 +17,7 @@ import java.util.concurrent.ExecutionException;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -27,6 +28,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
*/
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@DirtiesContext // close at the end after class
|
||||
public class HsqlTxTimeoutMessageStoreTests extends AbstractTxTimeoutMessageStoreTests {
|
||||
|
||||
@Test
|
||||
|
||||
@@ -37,6 +37,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
@@ -48,20 +49,20 @@ import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.expression.common.LiteralExpression;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.integration.file.DefaultFileNameGenerator;
|
||||
import org.springframework.integration.file.remote.FileInfo;
|
||||
import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler;
|
||||
import org.springframework.integration.file.remote.session.CachingSessionFactory;
|
||||
import org.springframework.integration.file.remote.session.Session;
|
||||
import org.springframework.integration.file.remote.session.SessionFactory;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.integration.sftp.session.DefaultSftpSessionFactory;
|
||||
import org.springframework.integration.sftp.session.SftpTestSessionFactory;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
|
||||
import com.jcraft.jsch.ChannelSftp;
|
||||
@@ -229,12 +230,21 @@ public class SftpOutboundTests {
|
||||
new DirectFieldAccessor(jschSession1).setPropertyValue("isConnected", true);
|
||||
new DirectFieldAccessor(jschSession2).setPropertyValue("isConnected", true);
|
||||
when(jsch.getSession("foo", "host", 22)).thenReturn(jschSession1, jschSession2);
|
||||
ChannelSftp channel1 = spy(new ChannelSftp());
|
||||
ChannelSftp channel2 = spy(new ChannelSftp());
|
||||
final ChannelSftp channel1 = spy(new ChannelSftp());
|
||||
doReturn("channel1").when(channel1).toString();
|
||||
final ChannelSftp channel2 = spy(new ChannelSftp());
|
||||
doReturn("channel2").when(channel2).toString();
|
||||
new DirectFieldAccessor(channel1).setPropertyValue("session", jschSession1);
|
||||
new DirectFieldAccessor(channel2).setPropertyValue("session", jschSession1);
|
||||
doReturn(channel1).when(jschSession1).openChannel("sftp");
|
||||
doReturn(channel2).when(jschSession1).openChannel("sftp");
|
||||
// Can't use when(session.open()) with a spy
|
||||
final AtomicInteger n = new AtomicInteger();
|
||||
doAnswer(new Answer<ChannelSftp>() {
|
||||
|
||||
@Override
|
||||
public ChannelSftp answer(InvocationOnMock invocation) throws Throwable {
|
||||
return n.getAndIncrement() == 0 ? channel1 : channel2;
|
||||
}
|
||||
}).when(jschSession1).openChannel("sftp");
|
||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(jsch, true);
|
||||
factory.setHost("host");
|
||||
factory.setUser("foo");
|
||||
@@ -244,6 +254,8 @@ public class SftpOutboundTests {
|
||||
Session<LsEntry> s1 = factory.getSession();
|
||||
Session<LsEntry> s2 = factory.getSession();
|
||||
assertSame(TestUtils.getPropertyValue(s1, "jschSession"), TestUtils.getPropertyValue(s2, "jschSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s1, "channel"));
|
||||
assertSame(channel2, TestUtils.getPropertyValue(s2, "channel"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -271,6 +283,8 @@ public class SftpOutboundTests {
|
||||
Session<LsEntry> s1 = factory.getSession();
|
||||
Session<LsEntry> s2 = factory.getSession();
|
||||
assertNotSame(TestUtils.getPropertyValue(s1, "jschSession"), TestUtils.getPropertyValue(s2, "jschSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s1, "channel"));
|
||||
assertSame(channel2, TestUtils.getPropertyValue(s2, "channel"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -283,16 +297,32 @@ public class SftpOutboundTests {
|
||||
new DirectFieldAccessor(jschSession1).setPropertyValue("isConnected", true);
|
||||
new DirectFieldAccessor(jschSession2).setPropertyValue("isConnected", true);
|
||||
when(jsch.getSession("foo", "host", 22)).thenReturn(jschSession1, jschSession2);
|
||||
ChannelSftp channel1 = spy(new ChannelSftp());
|
||||
ChannelSftp channel2 = spy(new ChannelSftp());
|
||||
ChannelSftp channel3 = spy(new ChannelSftp());
|
||||
ChannelSftp channel4 = spy(new ChannelSftp());
|
||||
final ChannelSftp channel1 = spy(new ChannelSftp());
|
||||
doReturn("channel1").when(channel1).toString();
|
||||
final ChannelSftp channel2 = spy(new ChannelSftp());
|
||||
doReturn("channel2").when(channel2).toString();
|
||||
final ChannelSftp channel3 = spy(new ChannelSftp());
|
||||
doReturn("channel3").when(channel3).toString();
|
||||
final ChannelSftp channel4 = spy(new ChannelSftp());
|
||||
doReturn("channel4").when(channel4).toString();
|
||||
new DirectFieldAccessor(channel1).setPropertyValue("session", jschSession1);
|
||||
new DirectFieldAccessor(channel2).setPropertyValue("session", jschSession1);
|
||||
doReturn(channel1).when(jschSession1).openChannel("sftp");
|
||||
doReturn(channel2).when(jschSession1).openChannel("sftp");
|
||||
doReturn(channel3).when(jschSession2).openChannel("sftp");
|
||||
doReturn(channel4).when(jschSession2).openChannel("sftp");
|
||||
// Can't use when(session.open()) with a spy
|
||||
final AtomicInteger n = new AtomicInteger();
|
||||
doAnswer(new Answer<ChannelSftp>() {
|
||||
|
||||
@Override
|
||||
public ChannelSftp answer(InvocationOnMock invocation) throws Throwable {
|
||||
return n.getAndIncrement() == 0 ? channel1 : channel2;
|
||||
}
|
||||
}).when(jschSession1).openChannel("sftp");
|
||||
doAnswer(new Answer<ChannelSftp>() {
|
||||
|
||||
@Override
|
||||
public ChannelSftp answer(InvocationOnMock invocation) throws Throwable {
|
||||
return n.getAndIncrement() < 3 ? channel3 : channel4;
|
||||
}
|
||||
}).when(jschSession2).openChannel("sftp");
|
||||
DefaultSftpSessionFactory factory = new DefaultSftpSessionFactory(jsch, true);
|
||||
factory.setHost("host");
|
||||
factory.setUser("foo");
|
||||
@@ -305,21 +335,26 @@ public class SftpOutboundTests {
|
||||
Session<LsEntry> s1 = cachedFactory.getSession();
|
||||
Session<LsEntry> s2 = cachedFactory.getSession();
|
||||
assertSame(jschSession1, TestUtils.getPropertyValue(s2, "targetSession.jschSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s1, "targetSession.channel"));
|
||||
assertSame(channel2, TestUtils.getPropertyValue(s2, "targetSession.channel"));
|
||||
assertSame(TestUtils.getPropertyValue(s1, "targetSession.jschSession"), TestUtils.getPropertyValue(s2, "targetSession.jschSession"));
|
||||
s1.close();
|
||||
Session<LsEntry> s3 = cachedFactory.getSession();
|
||||
assertSame(TestUtils.getPropertyValue(s1, "targetSession"), TestUtils.getPropertyValue(s3, "targetSession"));
|
||||
assertSame(channel1, TestUtils.getPropertyValue(s3, "targetSession.channel"));
|
||||
s3.close();
|
||||
cachedFactory.resetCache();
|
||||
verify(jschSession1, never()).disconnect();
|
||||
s3 = cachedFactory.getSession();
|
||||
assertSame(jschSession2, TestUtils.getPropertyValue(s3, "targetSession.jschSession"));
|
||||
assertNotSame(TestUtils.getPropertyValue(s1, "targetSession"), TestUtils.getPropertyValue(s3, "targetSession"));
|
||||
assertSame(channel3, TestUtils.getPropertyValue(s3, "targetSession.channel"));
|
||||
s2.close();
|
||||
verify(jschSession1).disconnect();
|
||||
s2 = cachedFactory.getSession();
|
||||
assertSame(jschSession2, TestUtils.getPropertyValue(s2, "targetSession.jschSession"));
|
||||
assertNotSame(TestUtils.getPropertyValue(s3, "targetSession"), TestUtils.getPropertyValue(s2, "targetSession"));
|
||||
assertSame(channel4, TestUtils.getPropertyValue(s2, "targetSession.channel"));
|
||||
s2.close();
|
||||
s3.close();
|
||||
verify(jschSession2, never()).disconnect();
|
||||
|
||||
Reference in New Issue
Block a user