INT-2916 - Upgrade to JUnit 4.11 in support of JDK7

For reference see: https://jira.springsource.org/browse/INT-2916

Changes:

* INT-2919 - Upgrade Spring Data Gemfire to 1.2.2.RELEASE
* Exclude Hamcrest transitive dependency from JUnit (as already explicitly declared)
* Set sourceCompatibility in build.gradle to 1.6
* Set targetCompatibility in build.gradle to 1.6
* Upgrade Hamcrest to 1.3 and fix deprications
  - Corematcher is(*class) change to is(instanceOf(*class))
  - Change org.junit.internal.matchers.TypeSafeMatcher to org.hamcrest.TypeSafeMatcher
  - Change import org.junit.matchers.JUnitMatchers.containsString to org.hamcrest.CoreMatchers.containsString
  - Change import org.junit.matchers.JUnitMatchers.both to org.hamcrest.CoreMatchers.both
  - Change import org.junit.matchers.JUnitMatchers.containsString to org.hamcrest.CoreMatchers.containsString
* Fix JUnit deprecations
  - changed junit.framework.Assert to org.junit.Assert
* Add few missing licenses headers to tests
* Marked several test classes with: @DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
  - SplitterIntegrationTests
  - GatewayInvokingMessageHandlerTests
  - FileToChannelIntegrationTests
  - FileInboundChannelAdapterWithRecursiveDirectoryTests
  - JdbcMessageStoreChannelTests
  - ChatMessageInboundChannelAdapterParserTests
* 3 Tests ignored (Still needs to be addressed):
  - testOperationOnPrototypeBean
  - testFailOperationWithCustomScope
  - testOperationOfControlBus
* Update SQL script (test-failure):
  - spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/config/outboundSchema.sql
  - add drop table statements
  - add ignore-failures="DROPS" to "jdbcOutboundChannelAdapterCommonConfig.xml"

INT-2916 - Code Review Changes

INT-2916 - Fix ignored Tests

Fix 3 previously ignored tests in *GroovyControlBusTests*:

* testOperationOnPrototypeBean
* testFailOperationWithCustomScope
* testOperationOfControlBus

INT-2916 - CI Build Testing

INT-2963 - Remove JDK7 Compilation Warnings

* Upgrade Mockito to 1.9.5
* Fix failing SubscribableJmsChannelTests

INT-2916 - Standardize Hamcrest assertions
Ensure Hamcrest assertions are standardized to: is(instanceOf(...))
This commit is contained in:
Gunnar Hillert
2013-02-06 15:51:58 -05:00
committed by Gary Russell
parent 3c98b371fa
commit 0271acaf4c
183 changed files with 1730 additions and 1482 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -44,7 +44,7 @@ import org.springframework.util.Assert;
* An advisor that will apply the {@link MessagePublishingInterceptor} to any
* methods containing the provided annotations. If no annotations are provided,
* the default will be {@link Publisher @Publisher}.
*
*
* @author Mark Fisher
* @since 2.0
*/
@@ -55,7 +55,7 @@ public class PublisherAnnotationAdvisor extends AbstractPointcutAdvisor implemen
private final MessagePublishingInterceptor interceptor;
@SuppressWarnings("unchecked") //For JDK7
public PublisherAnnotationAdvisor(Class<? extends Annotation> ... publisherAnnotationTypes) {
this.publisherAnnotationTypes = new HashSet<Class<? extends Annotation>>(Arrays.asList(publisherAnnotationTypes));
PublisherMetadataSource metadataSource = new MethodAnnotationPublisherMetadataSource(this.publisherAnnotationTypes);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors
* Copyright 2002-2013 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.
@@ -252,12 +252,10 @@ public abstract class AbstractKeyValueMessageStore extends AbstractMessageGroupS
/**
* Will enrich Message with additional meta headers
* @param message
* @return
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({ "rawtypes", "unchecked" })
private Message<?> enrichMessage(Message<?> message){
Message<?> enrichedMessage = MessageBuilder.fromMessage(message).setHeader(CREATED_DATE, System.currentTimeMillis()).build();
Message<?> enrichedMessage = MessageBuilder.fromMessage(message).setHeader(CREATED_DATE, System.currentTimeMillis()).build();
Map innerMap = (Map) new DirectFieldAccessor(enrichedMessage.getHeaders()).getPropertyValue("headers");
innerMap.put(MessageHeaders.ID, message.getHeaders().getId());
innerMap.put(MessageHeaders.TIMESTAMP, message.getHeaders().getTimestamp());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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
@@ -14,6 +14,7 @@
package org.springframework.integration.aggregator;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
@@ -33,6 +34,7 @@ import org.springframework.integration.support.MessageBuilder;
/**
* @author Alex Peters
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class ExpressionEvaluatingCorrelationStrategyTests {
@@ -56,7 +58,7 @@ public class ExpressionEvaluatingCorrelationStrategyTests {
Expression expression = parser.parseExpression("payload.substring(0,1)");
strategy = new ExpressionEvaluatingCorrelationStrategy(expression);
Object correlationKey = strategy.getCorrelationKey(new GenericMessage<String>("bla"));
assertThat(correlationKey, is(String.class));
assertThat(correlationKey, is(instanceOf(String.class)));
assertThat((String) correlationKey, is("b"));
}

View File

@@ -16,13 +16,6 @@
package org.springframework.integration.aggregator;
import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -52,6 +45,15 @@ import org.springframework.integration.store.MessageGroup;
import org.springframework.integration.store.SimpleMessageGroup;
import org.springframework.integration.support.MessageBuilder;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
@RunWith(MockitoJUnitRunner.class)
public class MethodInvokingMessageGroupProcessorTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2013 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.
@@ -187,7 +187,7 @@ public class MethodInvokingReleaseStrategyTests {
}
// TODO: this is stupid, but maybe it should be illegal?
new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), TestReleaseStrategy.class.getMethod(
"notEnoughParameters", new Class[] {}));
"notEnoughParameters"));
}
@Test
@@ -238,7 +238,7 @@ public class MethodInvokingReleaseStrategyTests {
}
}
ReleaseStrategy adapter = new MethodInvokingReleaseStrategy(new TestReleaseStrategy(),
TestReleaseStrategy.class.getMethod("listSubclassParameter", new Class[] { LinkedList.class }));
TestReleaseStrategy.class.getMethod("listSubclassParameter", new Class<?>[] { LinkedList.class }));
MessageGroup messages = createListOfMessages(3);
Assert.assertTrue(adapter.canRelease(messages));
}
@@ -253,7 +253,7 @@ public class MethodInvokingReleaseStrategyTests {
}
}
new MethodInvokingReleaseStrategy(new TestReleaseStrategy(), TestReleaseStrategy.class.getMethod(
"wrongReturnType", new Class[] { List.class }));
"wrongReturnType", new Class<?>[] { List.class }));
}
private static MessageGroup createListOfMessages(int size) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2013 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,7 @@
package org.springframework.integration.aggregator.integration;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
@@ -39,6 +40,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Alex Peters
* @author Iwein Fuld
* @author Gunnar Hillert
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@@ -60,7 +62,7 @@ public class DefaultMessageAggregatorIntegrationTests {
input.send(new GenericMessage<Integer>(i, headers));
}
Object payload = output.receive().getPayload();
assertThat(payload, is(List.class));
assertThat(payload, is(instanceOf(List.class)));
assertTrue(payload + " doesn't contain all of {0,1,2,3,4}",
((List) payload).containsAll(Arrays.asList(0, 1, 2, 3, 4)));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +19,7 @@ package org.springframework.integration.aggregator.scenarios;
import java.util.ArrayList;
import java.util.List;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
@@ -37,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* Tests courtesy of Sean Crotty (INT-1093)
*
* @author Iwein Fuld
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -56,7 +57,7 @@ public class AggregationResendTests {
* We expect to get back only one Message from the aggregator. We set an
* explicit timeout value of 1 second on the aggregator. What we'll see is
* that we get one aggregate Message back immediately.
*
*
* <p>We should <emphasis>not</emphasis> get another 3 after the 1 second.
*/
@Test
@@ -70,7 +71,7 @@ public class AggregationResendTests {
* explicit timeout value on the aggregator, but it automatically times out
* after 60 seconds. What we'll see is that we get one aggregate Message back
* immediately.
*
*
* <p>We should <emphasis>not</emphasis> get another 3 after the 60 seconds.
*/
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.aop;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.aop;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,6 +28,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration
@@ -49,7 +50,7 @@ public class MessagePublishingInterceptorUsageTests {
Assert.assertEquals("John Doe", message.getPayload());
Assert.assertEquals("bar", message.getHeaders().get("foo"));
}
public static class TestBean {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 @@
package org.springframework.integration.channel.config;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -28,7 +29,6 @@ import static org.junit.Assert.assertTrue;
import java.util.concurrent.Executor;
import org.junit.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.FatalBeanException;
import org.springframework.context.ApplicationContext;
@@ -50,7 +50,8 @@ import org.springframework.integration.util.ErrorHandlingTaskExecutor;
/**
* @author Mark Fisher
* @author Iwein Fuld
*
* @author Gunnar Hillert
*
* @see ChannelWithCustomQueueParserTests
*/
public class ChannelParserTests {
@@ -80,9 +81,9 @@ public class ChannelParserTests {
assertEquals(DirectChannel.class, channel.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
Object dispatcher = accessor.getPropertyValue("dispatcher");
assertThat(dispatcher, is(UnicastingDispatcher.class));
assertThat(dispatcher, is(instanceOf(UnicastingDispatcher.class)));
assertThat(new DirectFieldAccessor(dispatcher).getPropertyValue("loadBalancingStrategy"),
is(RoundRobinLoadBalancingStrategy.class));
is(instanceOf(RoundRobinLoadBalancingStrategy.class)));
}
@Test
@@ -93,7 +94,7 @@ public class ChannelParserTests {
assertEquals(DirectChannel.class, channel.getClass());
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
Object dispatcher = accessor.getPropertyValue("dispatcher");
assertThat(dispatcher, is(UnicastingDispatcher.class));
assertThat(dispatcher, is(instanceOf(UnicastingDispatcher.class)));
assertNull(new DirectFieldAccessor(dispatcher).getPropertyValue("loadBalancingStrategy"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2013 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.
@@ -35,9 +35,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* Testcases for detailed namespace support for &lt;queue/> element under
* &lt;channel/>
*
*
* @author Iwein Fuld
*
* @author Gunnar Hillert
*
* @see ChannelWithCustomQueueParserTests
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -52,13 +53,13 @@ public class ChannelWithCustomQueueParserTests {
public void parseConfig() throws Exception {
assertNotNull(customQueueChannel);
}
@Test
public void queueTypeSet() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(customQueueChannel);
Object queue = accessor.getPropertyValue("queue");
assertNotNull(queue);
assertThat(queue, is(ArrayBlockingQueue.class));
assertThat(queue, is(instanceOf(ArrayBlockingQueue.class)));
assertThat(((BlockingQueue<?>)queue).remainingCapacity(), is(2));
}

View File

@@ -16,12 +16,6 @@
package org.springframework.integration.config;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -55,6 +49,13 @@ import org.springframework.integration.endpoint.EventDrivenConsumer;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* @author Marius Bogoevici
@@ -62,6 +63,7 @@ import org.springframework.integration.test.util.TestUtils;
* @author Iwein Fuld
* @author Oleg Zhurakousky
* @author Artem Bilan
* @author Gunnar Hillert
*/
public class AggregatorParserTests {
@@ -119,7 +121,7 @@ public class AggregatorParserTests {
MessageChannel outputChannel = (MessageChannel) context.getBean("outputChannel");
MessageChannel discardChannel = (MessageChannel) context.getBean("discardChannel");
Object consumer = new DirectFieldAccessor(endpoint).getPropertyValue("handler");
assertThat(consumer, is(AggregatingMessageHandler.class));
assertThat(consumer, is(instanceOf(AggregatingMessageHandler.class)));
DirectFieldAccessor accessor = new DirectFieldAccessor(consumer);
Map<?, ?> map = (Map<?, ?>) new DirectFieldAccessor(new DirectFieldAccessor(new DirectFieldAccessor(accessor
.getPropertyValue("outputProcessor")).getPropertyValue("processor")).getPropertyValue("delegate"))

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2013 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.
@@ -35,11 +35,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import static org.junit.Assert.assertThat;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.hamcrest.CoreMatchers.containsString;
/**
* @author Marius Bogoevici
* @author Iwein Fuld
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -23,8 +23,6 @@ import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.matchers.JUnitMatchers.both;
import static org.junit.matchers.JUnitMatchers.containsString;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
@@ -66,6 +64,7 @@ import org.springframework.util.StringUtils;
* @author Iwein Fuld
* @author Dave Turanski
* @author Artem Bilan
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -309,7 +308,8 @@ public class ChainParserTests {
}
catch (BeansException e) {
assertEquals(IllegalArgumentException.class, e.getCause().getClass());
assertThat(e.getMessage(), both(containsString("output channel was provided")).and(containsString("does not implement the MessageProducer")));
assertTrue(e.getMessage().contains("output channel was provided"));
assertTrue(e.getMessage().contains("does not implement the MessageProducer"));
throw e;
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -43,6 +43,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration
@@ -54,7 +55,7 @@ public class ClaimCheckParserTests {
@Autowired
private MessageChannel checkinChannel;
@Autowired
private MessageChannel checkinChannelA;
@@ -66,7 +67,7 @@ public class ClaimCheckParserTests {
@Autowired
private EventDrivenConsumer checkout;
@Autowired
private MessageStore sampleMessageStore;
@@ -86,7 +87,7 @@ public class ClaimCheckParserTests {
new DirectFieldAccessor(checkout).getPropertyValue("handler")).getPropertyValue("transformer");
MessageStore messageStore = (MessageStore)
new DirectFieldAccessor(transformer).getPropertyValue("messageStore");
assertEquals(context.getBean("testMessageStore"), messageStore);
assertEquals(context.getBean("testMessageStore"), messageStore);
}
@Test
@@ -103,9 +104,9 @@ public class ClaimCheckParserTests {
assertEquals("test", resultMessage.getPayload());
assertNotNull(this.sampleMessageStore.getMessage(payload));
}
@Test
public void integrationTestWithRemoval() {
public void integrationTestWithRemoval() {
QueueChannel replyChannel = new QueueChannel();
Message<?> message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build();
checkinChannelA.send(message);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
@@ -39,6 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Dave Syer
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration
@@ -58,12 +59,12 @@ public class ControlBusTests {
assertEquals("catbar", output.receive(0).getPayload());
assertNull(output.receive(0));
}
@Test
public void testLifecycleMethods() {
ApplicationContext context = new ClassPathXmlApplicationContext("ControlBusLifecycleTests-context.xml", this.getClass());
MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
MessageChannel inputChannel = context.getBean("inputChannel", MessageChannel.class);
PollableChannel outputChannel = context.getBean("outputChannel", PollableChannel.class);
assertNull(outputChannel.receive(1000));
Message<?> message = MessageBuilder.withPayload("@adapter.start()").build();
inputChannel.send(message);
@@ -78,7 +79,7 @@ public class ControlBusTests {
return "cat";
}
}
public static class AdapterService {
public Message<String> receive() {
return new GenericMessage<String>(new Date().toString());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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.
@@ -46,6 +46,7 @@ import org.springframework.transaction.interceptor.TransactionInterceptor;
/**
* @author Mark Fisher
* @author Artem Bilan
* @author Gunnar Hillert
* @since 1.0.3
*/
@RunWith(SpringJUnit4ClassRunner.class)
@@ -104,7 +105,7 @@ public class DelayerParserTests {
public void transactionalSubElement() {
Object endpoint = context.getBean("delayerWithTransactional");
DelayHandler delayHandler = TestUtils.getPropertyValue(endpoint, "handler", DelayHandler.class);
List adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class);
List<?> adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class);
assertEquals(1, adviceChain.size());
Object advice = adviceChain.get(0);
assertTrue(advice instanceof TransactionInterceptor);
@@ -121,7 +122,7 @@ public class DelayerParserTests {
public void adviceChainSubElement() {
Object endpoint = context.getBean("delayerWithAdviceChain");
DelayHandler delayHandler = TestUtils.getPropertyValue(endpoint, "handler", DelayHandler.class);
List adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class);
List<?> adviceChain = TestUtils.getPropertyValue(delayHandler, "delayedAdviceChain", List.class);
assertEquals(2, adviceChain.size());
assertSame(context.getBean("testAdviceBean"), adviceChain.get(0));
@@ -129,7 +130,7 @@ public class DelayerParserTests {
assertEquals(TransactionInterceptor.class, txAdvice.getClass());
TransactionAttributeSource transactionAttributeSource = ((TransactionInterceptor) txAdvice).getTransactionAttributeSource();
assertEquals(NameMatchTransactionAttributeSource.class, transactionAttributeSource.getClass());
HashMap nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class);
HashMap<?, ?> nameMap = TestUtils.getPropertyValue(transactionAttributeSource, "nameMap", HashMap.class);
assertEquals("{*=PROPAGATION_REQUIRES_NEW,ISOLATION_DEFAULT,readOnly}", nameMap.toString());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,7 +15,7 @@
*/
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,33 +29,34 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class ErrorMessageExceptionTypeRouterParserTests {
@Autowired
private MessageChannel inputChannel;
@Autowired
private QueueChannel defaultChannel;
@Autowired
private QueueChannel illegalChannel;
@Autowired
private QueueChannel npeChannel;
@Test
public void validateExceptionTypeRouterConfig(){
inputChannel.send(new ErrorMessage(new NullPointerException()));
assertTrue(npeChannel.receive(1000).getPayload() instanceof NullPointerException);
inputChannel.send(new ErrorMessage(new IllegalArgumentException()));
assertTrue(illegalChannel.receive(1000).getPayload() instanceof IllegalArgumentException);
inputChannel.send(new ErrorMessage(new RuntimeException()));
assertTrue(defaultChannel.receive(1000).getPayload() instanceof RuntimeException);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -26,7 +26,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -52,12 +52,13 @@ import org.springframework.util.StringUtils;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class InnerDefinitionHandlerAwareEndpointParserTests {
@Autowired
@Autowired
private Properties testConfigurations;
@Test
@@ -65,7 +66,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
String configProperty = testConfigurations.getProperty("splitter-inner-success");
this.testSplitterDefinitionSuccess(configProperty);
}
@Test
public void testInnerSplitterDefinitionSuccessWithPoller(){
String configProperty = testConfigurations.getProperty("splitter-inner-success-with-poller");
@@ -89,7 +90,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
String xmlConfig = testConfigurations.getProperty("splitter-failure-refAndBean");
this.bootStrap(xmlConfig);
}
@Test
public void testInnerTransformerDefinitionSuccess(){
String configProperty = testConfigurations.getProperty("transformer-inner-success");
@@ -101,13 +102,13 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
String configProperty = testConfigurations.getProperty("transformer-ref-success");
this.testTransformerDefinitionSuccess(configProperty);
}
@Test(expected=BeanDefinitionStoreException.class)
public void testInnerTransformerDefinitionFailureRefAndInner(){
String xmlConfig = testConfigurations.getProperty("transformer-failure-refAndBean");
this.bootStrap(xmlConfig);
}
@Test
public void testInnerRouterDefinitionSuccess(){
String configProperty = testConfigurations.getProperty("router-inner-success");
@@ -119,13 +120,13 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
String configProperty = testConfigurations.getProperty("router-ref-success");
this.testRouterDefinitionSuccess(configProperty);
}
@Test(expected=BeanDefinitionStoreException.class)
public void testInnerRouterDefinitionFailureRefAndInner(){
String xmlConfig = testConfigurations.getProperty("router-failure-refAndBean");
this.bootStrap(xmlConfig);
}
@Test
public void testInnerSADefinitionSuccess(){
String configProperty = testConfigurations.getProperty("sa-inner-success");
@@ -143,7 +144,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
String xmlConfig = testConfigurations.getProperty("sa-failure-refAndBean");
this.bootStrap(xmlConfig);
}
@Test
public void testInnerAggregatorDefinitionSuccess(){
String configProperty = testConfigurations.getProperty("aggregator-inner-success");
@@ -173,13 +174,13 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
String xmlConfig = testConfigurations.getProperty("aggregator-failure-refAndBean");
this.bootStrap(xmlConfig);
}
@Test
public void testInnerFilterDefinitionSuccess(){
String configProperty = testConfigurations.getProperty("filter-inner-success");
this.testFilterDefinitionSuccess(configProperty);
}
@Test
public void testRefFilterDefinitionSuccess(){
String configProperty = testConfigurations.getProperty("filter-ref-success");
@@ -191,7 +192,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
String xmlConfig = testConfigurations.getProperty("filter-failure-refAndBean");
this.bootStrap(xmlConfig);
}
private void testSplitterDefinitionSuccess(String configProperty){
ApplicationContext ac = this.bootStrap(configProperty);
EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testSplitter");
@@ -205,7 +206,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
outChannel = (PollableChannel) ac.getBean("outChannel");
Assert.assertTrue(outChannel.receive().getPayload() instanceof String);
}
private void testTransformerDefinitionSuccess(String configProperty){
ApplicationContext ac = this.bootStrap(configProperty);
EventDrivenConsumer transformer = (EventDrivenConsumer) ac.getBean("testTransformer");
@@ -270,7 +271,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
Message<?> reply = output.receive(0);
assertEquals("foo", reply.getPayload());
}
private ApplicationContext bootStrap(String configProperty){
ByteArrayInputStream stream = new ByteArrayInputStream(configProperty.getBytes());
GenericApplicationContext ac = new GenericApplicationContext();
@@ -295,13 +296,13 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
return CollectionUtils.arrayToList(payload);
}
}
public static class TestTransformer{
public String split(String[] payload){
return StringUtils.arrayToDelimitedString(payload, ",");
}
}
public static class TestRouter{
public String route(String value) {
return (value.equals("1")) ? "channel1" : "channel2";
@@ -313,7 +314,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
return value;
}
}
public static class TestAggregator{
public Integer sum(List<Integer> numbers) {
int result = 0;
@@ -329,5 +330,5 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
return value.equals("foo");
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,9 +16,9 @@
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import java.util.HashMap;
import java.util.Map;
@@ -51,7 +51,7 @@ public class MapToObjectTransformerParserTests {
@Autowired
@Qualifier("output")
private PollableChannel output;
@Autowired
@Qualifier("inputA")
private MessageChannel inputA;
@@ -68,12 +68,12 @@ public class MapToObjectTransformerParserTests {
Address address = new Address();
address.setStreet("1123 Main st");
map.put("address", address);
Message message = MessageBuilder.withPayload(map).build();
input.send(message);
Message outMessage = output.receive();
Person person = (Person) outMessage.getPayload();
assertNotNull(person);
assertEquals("Justin", person.getFname());
@@ -92,7 +92,7 @@ public class MapToObjectTransformerParserTests {
Address address = new Address();
address.setStreet("1123 Main st");
map.put("address", address);
Message message = MessageBuilder.withPayload(map).build();
inputA.send(message);
Message<?> newMessage = outputA.receive();
@@ -113,10 +113,10 @@ public class MapToObjectTransformerParserTests {
map.put("fname", "Justin");
map.put("lname", "Case");
map.put("address", "1123 Main st");
Message message = MessageBuilder.withPayload(map).build();
inputA.send(message);
Message newMessage = outputA.receive();
Person person = (Person) newMessage.getPayload();
assertNotNull(person);
@@ -140,7 +140,7 @@ public class MapToObjectTransformerParserTests {
}
public void setSsn(String ssn) {
this.ssn = ssn;
}
}
public String getFname() {
return fname;
}
@@ -160,7 +160,7 @@ public class MapToObjectTransformerParserTests {
this.address = address;
}
}
public static class Address {
private String street;
@@ -172,7 +172,7 @@ public class MapToObjectTransformerParserTests {
this.street = street;
}
}
public static class StringToAddressConverter implements Converter<String, Address>{
public StringToAddressConverter(){}
public Address convert(String source) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2013 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,7 @@
package org.springframework.integration.config.xml;
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -35,6 +36,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Iwein Fuld
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -49,10 +51,9 @@ public class MethodInvokingSelectorParserTests {
public void configOK() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(chain);
List<MessageSelector> selectors = (List<MessageSelector>) accessor.getPropertyValue("selectors");
assertThat(selectors.get(0), is(MethodInvokingSelector.class));
assertThat(selectors.get(0), is(instanceOf(MethodInvokingSelector.class)));
}
public static class TestFilter {
public boolean accept(Message<?> m) {
return true;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -38,11 +38,12 @@ import org.springframework.integration.transformer.MessageTransformationExceptio
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@@ -64,10 +65,10 @@ public class ObjectToMapTransformerParserTests {
StandardEvaluationContext context = new StandardEvaluationContext(employee);
context.addPropertyAccessor(new MapAccessor());
ExpressionParser parser = new SpelExpressionParser();
Message<Employee> message = MessageBuilder.withPayload(employee).build();
directInput.send(message);
Message<Map<String, Object>> outputMessage = (Message<Map<String, Object>>) output.receive();
Map<String, Object> transformedMap = outputMessage.getPayload();
assertNotNull(outputMessage.getPayload());
@@ -76,12 +77,12 @@ public class ObjectToMapTransformerParserTests {
Object valueFromTheMap = transformedMap.get(key);
Object valueFromExpression = expression.getValue(context);
assertEquals(valueFromTheMap, valueFromExpression);
}
}
}
@Test(expected=MessageTransformationException.class)
public void testObjectToSpelMapTransformerWithCycle(){
Employee employee = this.buildEmployee();
Child child = new Child();
Child child = new Child();
Person parent = employee.getPerson();
parent.setChild(child);
child.setParent(parent);
@@ -95,12 +96,12 @@ public class ObjectToMapTransformerParserTests {
companyAddress.setCity("Philadelphia");
companyAddress.setStreet("1123 Main");
companyAddress.setZip("12345");
Map<String, Integer[]> coordinates = new HashMap<String, Integer[]>();
coordinates.put("latitude", new Integer[]{1, 5, 13});
coordinates.put("longitude", new Integer[]{156});
companyAddress.setCoordinates(coordinates);
Employee employee = new Employee();
employee.setCompanyName("ABC Inc.");
employee.setCompanyAddress(companyAddress);
@@ -108,7 +109,7 @@ public class ObjectToMapTransformerParserTests {
departments.add("HR");
departments.add("IT");
employee.setDepartments(departments);
Person person = new Person();
person.setFname("Justin");
person.setLname("Case");
@@ -123,7 +124,7 @@ public class ObjectToMapTransformerParserTests {
mapWithListTestData.put("mapWithListTestData", listTestData);
personAddress.setMapWithListData(mapWithListTestData);
person.setAddress(personAddress);
Map<String, Object> remarksA = new HashMap<String, Object>();
Map<String, Object> remarksB = new HashMap<String, Object>();
remarksA.put("foo", "foo");
@@ -134,22 +135,22 @@ public class ObjectToMapTransformerParserTests {
remarks.add(remarksB);
person.setRemarks(remarks);
employee.setPerson(person);
Map<String, Map<String, Object>> testMapData = new HashMap<String, Map<String, Object>>();
Map<String, Object> internalMapA = new HashMap<String, Object>();
internalMapA.put("foo", "foo");
internalMapA.put("bar", "bar");
Map<String, Object> internalMapB = new HashMap<String, Object>();
internalMapB.put("baz", "baz");
testMapData.put("internalMapA", internalMapA);
testMapData.put("internalMapB", internalMapB);
employee.setTestMapInMapData(testMapData);
return employee;
}
public static class Employee{
private List<String> departments;
private String companyName;
@@ -188,7 +189,7 @@ public class ObjectToMapTransformerParserTests {
this.departments = departments;
}
}
public static class Person{
private String fname;
private String lname;
@@ -233,7 +234,7 @@ public class ObjectToMapTransformerParserTests {
this.address = address;
}
}
public static class Address{
private String street;
private String city;
@@ -271,7 +272,7 @@ public class ObjectToMapTransformerParserTests {
this.coordinates = coordinates;
}
}
public static class Child {
private Person parent;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,7 +15,7 @@
*/
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -36,6 +36,7 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class PollerWithErrorChannelTests {
@@ -43,13 +44,13 @@ public class PollerWithErrorChannelTests {
@Test
/*
* Although adapter configuration specifies header-enricher pointing to the 'eChannel' as errorChannel
* the ErrorMessage will still be forwarded to the 'errorChannel' since exception occurs on
* the ErrorMessage will still be forwarded to the 'errorChannel' since exception occurs on
* receive() and not on send()
*/
public void testWithErrorChannelAsHeader() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
SourcePollingChannelAdapter adapter = ac.getBean("withErrorHeader", SourcePollingChannelAdapter.class);
SubscribableChannel errorChannel = ac.getBean("errorChannel", SubscribableChannel.class);
MessageHandler handler = mock(MessageHandler.class);
errorChannel.subscribe(handler);
@@ -58,7 +59,7 @@ public class PollerWithErrorChannelTests {
verify(handler, atLeastOnce()).handleMessage(Mockito.any(Message.class));
adapter.stop();
}
@Test
public void testWithErrorChannel() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
@@ -68,7 +69,7 @@ public class PollerWithErrorChannelTests {
assertNotNull(errorChannel.receive(1000));
adapter.stop();
}
@Test
public void testWithErrorChannelAndHeader() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
@@ -78,8 +79,8 @@ public class PollerWithErrorChannelTests {
assertNotNull(errorChannel.receive(1000));
adapter.stop();
}
@Test
@Test
// config the same as above but the error wil come from the send
public void testWithErrorChannelAndHeaderWithSendFailure() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
@@ -89,8 +90,8 @@ public class PollerWithErrorChannelTests {
assertNotNull(errorChannel.receive(1000));
adapter.stop();
}
@Test
@Test
// INT-1952
public void testWithErrorChannelAndPollingConsumer() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("PollerWithErrorChannel-context.xml", this.getClass());
@@ -99,7 +100,7 @@ public class PollerWithErrorChannelTests {
serviceWithPollerChannel.send(new GenericMessage<String>(""));
assertNotNull(errChannel.receive(1000));
}
public static class SampleService{
public String withSuccess(){
return "hello";

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.config.xml;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.anyObject;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.times;
@@ -37,6 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.core;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.verify;
@@ -39,6 +39,7 @@ import org.springframework.util.StopWatch;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class MessageIdGenerationTests {
@@ -56,7 +57,7 @@ public class MessageIdGenerationTests {
parent.close();
this.assertDestroy();
}
@Test
public void testCustomIdGenerationWithParentChileIndependentCreation() throws Exception{
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass());
@@ -73,7 +74,7 @@ public class MessageIdGenerationTests {
parent.close();
this.assertDestroy();
}
@Test
public void testCustomIdGenerationWithParentRegistrarClosed() throws Exception {
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass());
@@ -87,7 +88,7 @@ public class MessageIdGenerationTests {
child.close();
this.assertDestroy();
}
@Test
public void testCustomIdGenerationWithChildRegistrar() throws Exception{
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
@@ -102,7 +103,7 @@ public class MessageIdGenerationTests {
child.close();
this.assertDestroy();
}
@Test
public void testCustomIdGenerationWithChildRegistrarClosed() throws Exception{
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
@@ -122,19 +123,19 @@ public class MessageIdGenerationTests {
@Test
public void testCustomIdGenerationWithParentChildIndependentCreationChildrenRegistrarsOneAtTheTime() throws Exception{
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
GenericXmlApplicationContext childA = new GenericXmlApplicationContext();
childA.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
childA.setParent(parent);
childA.refresh();
childA.close();
GenericXmlApplicationContext childB = new GenericXmlApplicationContext();
childB.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
childB.setParent(parent);
childB.refresh();
parent.close();
childB.close();
this.assertDestroy();
@@ -144,7 +145,7 @@ public class MessageIdGenerationTests {
@Test(expected=BeanDefinitionStoreException.class)
public void testCustomIdGenerationWithParentChildIndependentCreation() throws Exception{
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass());
GenericXmlApplicationContext child = new GenericXmlApplicationContext();
try {
child.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
@@ -162,7 +163,7 @@ public class MessageIdGenerationTests {
@Test(expected=BeanDefinitionStoreException.class)
public void testCustomIdGenerationWithParentChildIndependentCreationChildrenRegistrars() throws Exception{
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context.xml", this.getClass());
GenericXmlApplicationContext childA = new GenericXmlApplicationContext();
GenericXmlApplicationContext childB = new GenericXmlApplicationContext();
@@ -170,7 +171,7 @@ public class MessageIdGenerationTests {
childA.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
childA.setParent(parent);
childA.refresh();
childB.load("classpath:/org/springframework/integration/core/MessageIdGenerationTests-context-withGenerator.xml");
childB.setParent(parent);
childB.refresh();
@@ -182,7 +183,7 @@ public class MessageIdGenerationTests {
this.assertDestroy();
}
}
@Test
@Ignore
public void performanceTest(){
@@ -197,7 +198,7 @@ public class MessageIdGenerationTests {
Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator");
ReflectionUtils.makeAccessible(idGeneratorField);
ReflectionUtils.setField(idGeneratorField, null, new IdGenerator() {
ReflectionUtils.setField(idGeneratorField, null, new IdGenerator() {
public UUID generateId() {
return TimeBasedUUIDGenerator.generateId();
}
@@ -209,12 +210,12 @@ public class MessageIdGenerationTests {
}
watch.stop();
double timebasedGeneratorElapsedTime = watch.getTotalTimeSeconds();
System.out.println("Generated " + times + " messages using default UUID generator " +
"in " + defaultGeneratorElapsedTime + " seconds");
System.out.println("Generated " + times + " messages using Timebased UUID generator " +
"in " + timebasedGeneratorElapsedTime + " seconds");
System.out.println("Time-based ID generator is " + defaultGeneratorElapsedTime/timebasedGeneratorElapsedTime + " times faster");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -24,7 +24,7 @@ import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.matchers.JUnitMatchers;
import static org.hamcrest.CoreMatchers.containsString;
import org.springframework.integration.Message;
import org.springframework.integration.MessageDeliveryException;
@@ -32,6 +32,7 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Iwein Fuld
* @author Gunnar Hillert
*/
public class AggregateMessageDeliveryExceptionTests {
@@ -60,9 +61,9 @@ public class AggregateMessageDeliveryExceptionTests {
@Test
public void shouldShowOriginalExceptionsInMessage() {
assertThat(exception.getMessage(), JUnitMatchers.containsString("first problem"));
assertThat(exception.getMessage(), JUnitMatchers.containsString("second problem"));
assertThat(exception.getMessage(), JUnitMatchers.containsString("third problem"));
assertThat(exception.getMessage(), containsString("first problem"));
assertThat(exception.getMessage(), containsString("second problem"));
assertThat(exception.getMessage(), containsString("third problem"));
}
@Test

View File

@@ -1,9 +1,21 @@
/**
*
/*
* Copyright 2002-2013 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.
*/
package org.springframework.integration.dispatcher;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
@@ -12,33 +24,34 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
* This test was influenced by INT-1483 where by registering TX Advisor
* in the BeanFactory while having <aop:config> resent resulted in
* in the BeanFactory while having <aop:config> resent resulted in
* TX Advisor being applied on all beans in AC
*/
public class TransactionalPollerWithMixedAopConfigTests {
@Test
public void validateTransactionalProxyIsolationToThePollerOnly(){
ApplicationContext context =
ApplicationContext context =
new ClassPathXmlApplicationContext("TransactionalPollerWithMixedAopConfig-context.xml", this.getClass());
assertTrue(!(context.getBean("foo") instanceof Advised));
assertTrue(!(context.getBean("inputChannel") instanceof Advised));
}
public static class SampleService{
public void foo(String payload){}
}
public static class Foo{
public Foo(String value){}
}
// public static class SampleAdvice implements MethodInterceptor{
// public Object invoke(MethodInvocation invocation) throws Throwable {
// return invocation.proceed();
// }
// }
// }
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,8 +15,8 @@
*/
package org.springframework.integration.dispatcher;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -33,6 +33,7 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class UnicastingDispatcherTests {
@@ -43,7 +44,7 @@ public class UnicastingDispatcherTests {
ApplicationContext context = new ClassPathXmlApplicationContext("unicasting-with-async.xml", this.getClass());
SubscribableChannel errorChannel = context.getBean("errorChannel", SubscribableChannel.class);
MessageHandler errorHandler = new MessageHandler() {
public void handleMessage(Message<?> message) throws MessagingException {
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
assertTrue(message.getPayload() instanceof MessageDeliveryException);
@@ -51,10 +52,10 @@ public class UnicastingDispatcherTests {
}
};
errorChannel.subscribe(errorHandler);
RequestReplyExchanger exchanger = context.getBean(RequestReplyExchanger.class);
Message<String> reply = (Message<String>) exchanger.exchange(new GenericMessage<String>("Hello"));
assertEquals("reply", reply.getPayload());
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,9 +15,9 @@
*/
package org.springframework.integration.endpoint;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -45,17 +45,18 @@ import org.springframework.scheduling.support.PeriodicTrigger;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class PollingLifecycleTests {
private ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
private TestErrorHandler errorHandler = new TestErrorHandler();
@Before
public void init() throws Exception {
taskScheduler.afterPropertiesSet();
}
@Test
public void ensurePollerTaskStops() throws Exception{
final CountDownLatch latch = new CountDownLatch(1);
@@ -86,12 +87,12 @@ public class PollingLifecycleTests {
Mockito.reset(handler);
Mockito.verify(handler, atMost(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void ensurePollerTaskStopsForAdapter() throws Exception{
final CountDownLatch latch = new CountDownLatch(1);
QueueChannel channel = new QueueChannel();
SourcePollingChannelAdapterFactoryBean adapterFactory = new SourcePollingChannelAdapterFactoryBean();
PollerMetadata pollerMetadata = new PollerMetadata();
pollerMetadata.setTrigger(new PeriodicTrigger(2000));
@@ -115,12 +116,12 @@ public class PollingLifecycleTests {
assertNull(channel.receive(1000));
Mockito.verify(source, times(1)).receive();
}
@Test
public void ensurePollerTaskStopsForAdapterWithInterruptible() throws Exception{
final CountDownLatch latch = new CountDownLatch(2);
QueueChannel channel = new QueueChannel();
SourcePollingChannelAdapterFactoryBean adapterFactory = new SourcePollingChannelAdapterFactoryBean();
PollerMetadata pollerMetadata = new PollerMetadata();
pollerMetadata.setMaxMessagesPerPoll(-1);
@@ -129,16 +130,16 @@ public class PollingLifecycleTests {
final Runnable coughtInterrupted = mock(Runnable.class);
MessageSource<String> source = new MessageSource<String>() {
public Message<String> receive() {
try {
for (int i = 0; i < 10; i++) {
for (int i = 0; i < 10; i++) {
Thread.sleep(1000);
latch.countDown();
}
} catch (InterruptedException e) {
coughtInterrupted.run();
}
return new GenericMessage<String>("hello");
}
};

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -29,6 +29,7 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class MethodInvokingSelectorTests {
@@ -41,7 +42,7 @@ public class MethodInvokingSelectorTests {
@Test
public void acceptedWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method method = testBean.getClass().getMethod("acceptString", new Class[] { Message.class });
Method method = testBean.getClass().getMethod("acceptString", new Class<?>[] { Message.class });
MethodInvokingSelector selector = new MethodInvokingSelector(testBean, method);
assertTrue(selector.accept(new GenericMessage<String>("should accept")));
}
@@ -55,7 +56,7 @@ public class MethodInvokingSelectorTests {
@Test
public void rejectedWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method method = testBean.getClass().getMethod("acceptString", new Class[] { Message.class });
Method method = testBean.getClass().getMethod("acceptString", new Class<?>[] { Message.class });
MethodInvokingSelector selector = new MethodInvokingSelector(testBean, method);
assertFalse(selector.accept(new GenericMessage<Integer>(99)));
}
@@ -69,7 +70,7 @@ public class MethodInvokingSelectorTests {
@Test
public void noArgMethodWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method method = testBean.getClass().getMethod("noArgs", new Class[] {});
Method method = testBean.getClass().getMethod("noArgs", new Class<?>[] {});
new MethodInvokingSelector(testBean, method);
}
@@ -82,7 +83,7 @@ public class MethodInvokingSelectorTests {
@Test(expected = IllegalArgumentException.class)
public void voidReturningMethodWithMethodReference() throws Exception {
TestBean testBean = new TestBean();
Method method = testBean.getClass().getMethod("returnVoid", new Class[] { Message.class });
Method method = testBean.getClass().getMethod("returnVoid", new Class<?>[] { Message.class });
MethodInvokingSelector selector = new MethodInvokingSelector(testBean, method);
selector.accept(new GenericMessage<String>("test"));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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,9 +16,9 @@
package org.springframework.integration.gateway;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -36,6 +36,7 @@ import org.springframework.integration.core.MessageHandler;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class GatewayInterfaceTests {
@@ -49,7 +50,7 @@ public class GatewayInterfaceTests {
bar.foo("hello");
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceAnnotatedMethod(){
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -60,7 +61,7 @@ public class GatewayInterfaceTests {
bar.bar("hello");
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceSuperclassUnAnnotatedMethod(){
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -71,7 +72,7 @@ public class GatewayInterfaceTests {
bar.baz("hello");
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceCastAsSuperclassAnnotatedMethod(){
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -82,7 +83,7 @@ public class GatewayInterfaceTests {
foo.foo("hello");
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceCastAsSuperclassUnAnnotatedMethod(){
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -93,7 +94,7 @@ public class GatewayInterfaceTests {
foo.baz("hello");
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceHashcode() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -104,7 +105,7 @@ public class GatewayInterfaceTests {
assertEquals(bar.hashCode(), ac.getBean(Bar.class).hashCode());
verify(handler, times(0)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceToString(){
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -115,7 +116,7 @@ public class GatewayInterfaceTests {
bar.toString();
verify(handler, times(0)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceEquals() throws Exception{
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -134,7 +135,7 @@ public class GatewayInterfaceTests {
assertFalse(bar.equals(fb.getObject()));
verify(handler, times(0)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithServiceGetClass(){
ApplicationContext ac = new ClassPathXmlApplicationContext("GatewayInterfaceTests-context.xml", this.getClass());
@@ -145,25 +146,25 @@ public class GatewayInterfaceTests {
bar.getClass();
verify(handler, times(0)).handleMessage(Mockito.any(Message.class));
}
@Test(expected=IllegalArgumentException.class)
public void testWithServiceAsNotAnInterface(){
new GatewayProxyFactoryBean(NotAnInterface.class);
}
public interface Foo {
@Gateway(requestChannel="requestChannelFoo")
public void foo(String payload);
public void baz(String payload);
}
public static interface Bar extends Foo{
@Gateway(requestChannel="requestChannelBar")
public void bar(String payload);
public void bar(String payload);
}
public static class NotAnInterface {
public void fail(String payload){}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.gateway;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -29,29 +29,33 @@ import org.springframework.integration.core.MessageHandler;
import org.springframework.integration.core.SubscribableChannel;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class GatewayInvokingMessageHandlerTests {
@Autowired
@Qualifier("inputA")
SubscribableChannel channel;
@Autowired
@Qualifier("simpleGateway")
SimpleGateway gateway;
@Autowired
@Qualifier("gatewayWithError")
SimpleGateway gatewayWithError;
@Autowired
@Qualifier("gatewayWithErrorAsync")
SimpleGateway gatewayWithErrorAsync;
@@ -77,7 +81,7 @@ public class GatewayInvokingMessageHandlerTests {
}
@Test
public void validateGatewayInTheChainViaAnotherGateway() {
public void validateGatewayInTheChainViaAnotherGateway() {
output.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message) {
Assert.assertEquals("echo:echo:echo:hello", message.getPayload());
@@ -88,9 +92,9 @@ public class GatewayInvokingMessageHandlerTests {
String result = gateway.process("hello");
Assert.assertEquals("echo:echo:echo:hello", result);
}
@Test
public void validateGatewayWithErrorMessageReturned() {
public void validateGatewayWithErrorMessageReturned() {
try {
String result = gatewayWithErrorChannelAndTransformer.process("echoWithRuntimeExceptionChannel");
Assert.assertNotNull(result);
@@ -99,7 +103,7 @@ public class GatewayInvokingMessageHandlerTests {
catch (Exception e) {
Assert.fail();
}
try {
gatewayWithError.process("echoWithRuntimeExceptionChannel");
Assert.fail();
@@ -107,7 +111,7 @@ public class GatewayInvokingMessageHandlerTests {
catch (SampleRuntimeException e) {
Assert.assertEquals("echoWithRuntimeExceptionChannel", e.getMessage());
}
try {
gatewayWithError.process("echoWithMessagingExceptionChannel");
Assert.fail();
@@ -115,7 +119,7 @@ public class GatewayInvokingMessageHandlerTests {
catch (MessageHandlingException e) {
Assert.assertEquals("echoWithMessagingExceptionChannel", e.getFailedMessage().getPayload());
}
try {
String result = gatewayWithErrorChannelAndTransformer.process("echoWithMessagingExceptionChannel");
Assert.assertNotNull(result);
@@ -125,9 +129,9 @@ public class GatewayInvokingMessageHandlerTests {
Assert.fail();
}
}
@Test
public void validateGatewayWithErrorAsync() {
public void validateGatewayWithErrorAsync() {
try {
gatewayWithErrorAsync.process("echoWithErrorAsyncChannel");
Assert.fail();
@@ -136,9 +140,9 @@ public class GatewayInvokingMessageHandlerTests {
Assert.assertEquals(SampleRuntimeException.class, e.getClass());
}
}
@Test
public void validateGatewayWithErrorFlowReturningMessage() {
public void validateGatewayWithErrorFlowReturningMessage() {
try {
Object result = gatewayWithErrorChannelAndTransformer.process("echoWithErrorAsyncChannel");
Assert.assertEquals("Error happened in message: echoWithErrorAsyncChannel", result);
@@ -151,10 +155,10 @@ public class GatewayInvokingMessageHandlerTests {
public static class SampleErrorTransformer {
public Message<?> toMessage(Throwable object) throws Exception {
MessageHandlingException ex = (MessageHandlingException) object;
MessageHandlingException ex = (MessageHandlingException) object;
return MessageBuilder.withPayload("Error happened in message: " + ex.getFailedMessage().getPayload()).build();
}
}
@@ -195,7 +199,7 @@ public class GatewayInvokingMessageHandlerTests {
public static class SampleRuntimeException extends RuntimeException {
public SampleRuntimeException(String message) {
super(message);
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.gateway;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
@@ -30,6 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Gunnar Hillert
* @since 2.0
*/
@ContextConfiguration
@@ -52,7 +53,7 @@ public class GatewayRequiresReplyTests {
TestService gateway = (TestService) applicationContext.getBean("gateway");
gateway.test("bad");
}
@Test
public void timedOutGateway() {
TestService gateway = (TestService) applicationContext.getBean("timeoutGateway");
@@ -64,7 +65,7 @@ public class GatewayRequiresReplyTests {
public static interface TestService {
public String test(String s);
}
public static class LongRunningService {
public String echo(String value) throws Exception{
Thread.sleep(5000);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.gateway;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,6 +30,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @author Gunnar Hillert
* @since 2.0
*/
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,8 +16,8 @@
package org.springframework.integration.gateway;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -32,6 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Gunnar Hillert
* @since 2.0
*/
@RunWith(SpringJUnit4ClassRunner.class)

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,7 +15,7 @@
*/
package org.springframework.integration.gateway;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -35,59 +35,60 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class InnerGatewayWithChainTests {
@Autowired
private TestGateway testGatewayWithErrorChannelA;
@Autowired
private TestGateway testGatewayWithErrorChannelAA;
@Autowired
private TestGateway testGatewayWithNoErrorChannelAAA;
@Autowired
private SourcePollingChannelAdapter inboundAdapterDefaultErrorChannel;
@Autowired
private SourcePollingChannelAdapter inboundAdapterAssignedErrorChannel;
@Autowired
private SubscribableChannel errorChannel;
@Autowired
private SubscribableChannel assignedErrorChannel;
@Test
public void testExceptionHandledByMainGateway(){
String reply = testGatewayWithErrorChannelA.echo(5);
assertEquals("ERROR from errorChannelA", reply);
}
@Test
public void testExceptionHandledByMainGatewayNoErrorChannelInChain(){
String reply = testGatewayWithErrorChannelAA.echo(0);
assertEquals("ERROR from errorChannelA", reply);
}
@Test
public void testExceptionHandledByInnerGateway(){
String reply = testGatewayWithErrorChannelA.echo(0);
assertEquals("ERROR from errorChannelB", reply);
}
// if no error channels explicitly defined exception is rethrown
@Test(expected=ArithmeticException.class)
public void testGatewaysNoErrorChannel(){
testGatewayWithNoErrorChannelAAA.echo(0);
}
@Test
public void testWithSPCADefaultErrorChannel() throws Exception{
MessageHandler handler = mock(MessageHandler.class);
@@ -97,7 +98,7 @@ public class InnerGatewayWithChainTests {
inboundAdapterDefaultErrorChannel.stop();
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testWithSPCAAssignedErrorChannel() throws Exception{
MessageHandler handler = mock(MessageHandler.class);
@@ -107,7 +108,7 @@ public class InnerGatewayWithChainTests {
inboundAdapterAssignedErrorChannel.stop();
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
}
public static interface TestGateway{
public String echo(int value);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.gateway;
import junit.framework.Assert;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -28,6 +28,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @since 2.0.M1
*/
@ContextConfiguration
@@ -41,12 +42,12 @@ public class MultiMethodGatewayConfigTests {
@Test
public void validateGatewayMethods() {
TestGateway gateway = (TestGateway) applicationContext.getBean("myGateway");
String parentClassName = "org.springframework.integration.gateway.MultiMethodGatewayConfigTests";
String parentClassName = "org.springframework.integration.gateway.MultiMethodGatewayConfigTests";
Assert.assertEquals(gateway.echo("oleg"),
parentClassName + "$TestBeanA:oleg");
Assert.assertEquals(gateway.echoUpperCase("oleg"),
Assert.assertEquals(gateway.echoUpperCase("oleg"),
parentClassName + "$TestBeanB:oleg");
Assert.assertEquals(gateway.echoViaDefault("oleg"),
Assert.assertEquals(gateway.echoViaDefault("oleg"),
parentClassName + "$TestBeanC:oleg");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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.
@@ -21,7 +21,7 @@ import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
import org.junit.Test;
import org.junit.matchers.JUnitMatchers;
import static org.hamcrest.CoreMatchers.containsString;
import org.junit.runner.RunWith;
import org.mockito.Mock;
@@ -32,6 +32,7 @@ import org.springframework.integration.support.MessageBuilder;
/**
* @author Iwein Fuld
* @author Gunnar Hillert
*/
@RunWith(org.mockito.runners.MockitoJUnitRunner.class)
public class AbstractReplyProducingMessageHandlerTests {
@@ -59,7 +60,7 @@ public class AbstractReplyProducingMessageHandlerTests {
fail("Expected a MessagingException");
}
catch (MessagingException e) {
assertThat(e.getMessage(), JUnitMatchers.containsString("'testChannel'"));
assertThat(e.getMessage(), containsString("'testChannel'"));
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2009 the original author or authors.
* Copyright 2002-2013 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.
@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.instanceOf;
import java.util.Arrays;
import java.util.HashSet;
@@ -38,6 +39,7 @@ import org.springframework.integration.support.MessageBuilder;
/**
* @author Mark Fisher
* @author Gunnar Hillert
* @since 2.0
*/
public class CollectionAndArrayTests {
@@ -76,7 +78,7 @@ public class CollectionAndArrayTests {
Message<?> reply2 = channel.receive(0);
assertNotNull(reply1);
assertNull(reply2);
assertThat(reply1.getPayload(), is(Set.class));
assertThat(reply1.getPayload(), is(instanceOf(Set.class)));
assertEquals(2, ((Set<?>) reply1.getPayload()).size());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2013 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,14 +19,12 @@ package org.springframework.integration.handler;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
@@ -51,6 +49,7 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/**
* @author Mark Fisher
* @author Artem Bilan
* @author Gunnar Hillert
* @since 1.0.3
*/
public class DelayHandlerTests {
@@ -405,7 +404,7 @@ public class DelayHandlerTests {
// Can happen in the parent-child context e.g. Spring-MVC applications
public void testDoubleOnApplicationEvent() throws Exception {
this.delayHandler = Mockito.spy(this.delayHandler);
Mockito.doAnswer(new Answer() {
Mockito.doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) throws Throwable {
return null;
}

View File

@@ -1,11 +1,11 @@
/*
* Copyright 2002-2010 the original author or authors.
*
* Copyright 2002-2013 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.
@@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.hamcrest.Description;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.config.BeanDefinition;
@@ -45,6 +45,7 @@ import org.springframework.integration.test.util.TestUtils;
/**
* @author Dave Syer
* @author Mark Fisher
* @author Gunnar Hillert
* @since 2.0
*/
public class ExpressionEvaluatingMessageProcessorTests {
@@ -105,7 +106,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
public String find(Resource[] resources) {
return Arrays.asList(resources).toString();
}
}
Expression expression = expressionParser.parseExpression("#target.find(payload)");
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
@@ -189,7 +190,7 @@ public class ExpressionEvaluatingMessageProcessorTests {
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor(expression);
assertEquals("foo", processor.processMessage(new GenericMessage<String>("foo")));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testProcessMessageExpressionThrowsRuntimeException() {

View File

@@ -30,7 +30,7 @@ import org.apache.commons.logging.LogFactory;
import org.hamcrest.Description;
import org.junit.Rule;
import org.junit.Test;
import org.junit.internal.matchers.TypeSafeMatcher;
import org.hamcrest.TypeSafeMatcher;
import org.junit.rules.ExpectedException;
import org.springframework.integration.Message;
import org.springframework.integration.MessageHandlingException;
@@ -48,6 +48,7 @@ import org.springframework.integration.util.MessagingMethodInvokerHelper;
* @author Oleg Zhurakousky
* @author Dave Syer
* @author Gary Russell
* @author Gunnar Hillert
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
public class MethodInvokingMessageProcessorTests {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,7 +15,7 @@
*/
package org.springframework.integration.history;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -38,6 +38,7 @@ import org.springframework.integration.test.util.TestUtils;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class AnotatedTests {
@@ -56,7 +57,7 @@ public class AnotatedTests {
};
listener = spy(listener);
ac.addApplicationListener(listener);
MessageChannel channel = ac.getBean("inputChannel", MessageChannel.class);
EventDrivenConsumer consumer = ac.getBean("myAdapter", EventDrivenConsumer.class);
MessageHandler handler = (MessageHandler) TestUtils.getPropertyValue(consumer, "handler");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,14 +37,15 @@ import org.springframework.integration.config.ConsumerEndpointFactoryBean;
import org.springframework.integration.core.MessageHandler;
import org.springframework.util.StopWatch;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertFalse;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class MessageHistoryIntegrationTests {
@@ -67,7 +68,7 @@ public class MessageHistoryIntegrationTests {
MessageHandler handler = Mockito.spy(new MessageHandler() {
public void handleMessage(Message<?> message) {
Iterator<Properties> historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
Properties event1 = historyIterator.next();
assertEquals("sampleGateway", event1.getProperty(MessageHistory.NAME_PROPERTY));
assertEquals("gateway", event1.getProperty(MessageHistory.TYPE_PROPERTY));
@@ -75,15 +76,15 @@ public class MessageHistoryIntegrationTests {
Properties event2 = historyIterator.next();
assertEquals("bridgeInChannel", event2.getProperty(MessageHistory.NAME_PROPERTY));
assertEquals("channel", event2.getProperty(MessageHistory.TYPE_PROPERTY));
Properties event3 = historyIterator.next();
assertEquals("testBridge", event3.getProperty(MessageHistory.NAME_PROPERTY));
assertEquals("bridge", event3.getProperty(MessageHistory.TYPE_PROPERTY));
Properties event4 = historyIterator.next();
assertEquals("headerEnricherChannel", event4.getProperty(MessageHistory.NAME_PROPERTY));
assertEquals("channel", event4.getProperty(MessageHistory.TYPE_PROPERTY));
Properties event5 = historyIterator.next();
assertEquals("testHeaderEnricher", event5.getProperty(MessageHistory.NAME_PROPERTY));
assertEquals("transformer", event5.getProperty(MessageHistory.TYPE_PROPERTY));
@@ -134,13 +135,13 @@ public class MessageHistoryIntegrationTests {
assertNotNull(result);
//assertEquals("hello", result);
}
@Test
public void testMessageHistoryWithoutHistoryWriter() {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml", MessageHistoryIntegrationTests.class);
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
MessageHandler handler = Mockito.spy(new MessageHandler() {
MessageHandler handler = Mockito.spy(new MessageHandler() {
public void handleMessage(Message<?> message) {
assertNull(message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class));
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
@@ -157,7 +158,7 @@ public class MessageHistoryIntegrationTests {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace.xml", MessageHistoryIntegrationTests.class);
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
MessageHandler handler = Mockito.spy(new MessageHandler() {
MessageHandler handler = Mockito.spy(new MessageHandler() {
public void handleMessage(Message<?> message) {
Iterator<Properties> historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
assertTrue(historyIterator.hasNext());
@@ -169,13 +170,13 @@ public class MessageHistoryIntegrationTests {
gateway.echo("hello");
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
}
@Test
public void testMessageHistoryParserWithNamePatterns() {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespaceAndPatterns.xml", MessageHistoryIntegrationTests.class);
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
MessageHandler handler = Mockito.spy(new MessageHandler() {
MessageHandler handler = Mockito.spy(new MessageHandler() {
public void handleMessage(Message<?> message) {
Iterator<Properties> historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
assertTrue(historyIterator.hasNext());
@@ -203,10 +204,10 @@ public class MessageHistoryIntegrationTests {
public void testMessageHistoryWithHistoryPerformance() {
ApplicationContext acWithHistory = new ClassPathXmlApplicationContext("perfWithMessageHistory.xml", MessageHistoryIntegrationTests.class);
ApplicationContext acWithoutHistory = new ClassPathXmlApplicationContext("perfWithoutMessageHistory.xml", MessageHistoryIntegrationTests.class);
SampleGateway gatewayHistory = acWithHistory.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannelHistory = acWithHistory.getBean("endOfThePipeChannel", DirectChannel.class);
endOfThePipeChannelHistory.subscribe(new MessageHandler() {
endOfThePipeChannelHistory.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message)
throws MessageRejectedException, MessageHandlingException,
MessageDeliveryException {
@@ -214,10 +215,10 @@ public class MessageHistoryIntegrationTests {
replyChannel.send(message);
}
});
SampleGateway gateway = acWithoutHistory.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = acWithoutHistory.getBean("endOfThePipeChannel", DirectChannel.class);
endOfThePipeChannel.subscribe(new MessageHandler() {
endOfThePipeChannel.subscribe(new MessageHandler() {
public void handleMessage(Message<?> message)
throws MessageRejectedException, MessageHandlingException,
MessageDeliveryException {
@@ -225,7 +226,7 @@ public class MessageHistoryIntegrationTests {
replyChannel.send(message);
}
});
StopWatch stopWatch = new StopWatch();
stopWatch.start();
for (int i = 0; i < 10000; i++) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.router;
import static junit.framework.Assert.fail;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
@@ -36,6 +36,7 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Mark Fisher
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*/
public class PayloadTypeRouterTests {
@@ -46,24 +47,24 @@ public class PayloadTypeRouterTests {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("stringChannel", stringChannel);
beanFactory.registerSingleton("integerChannel", integerChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setChannelMappings(payloadTypeChannelMap);
router.setBeanFactory(beanFactory);
Message<String> message1 = new GenericMessage<String>("test");
Message<Integer> message2 = new GenericMessage<Integer>(123);
assertEquals(1, router.getChannelKeys(message1).size());
assertNull(stringChannel.receive(0));
router.handleMessage(message1);
assertEquals(message1, stringChannel.receive(0));
assertEquals(1, router.getChannelKeys(message2).size());
assertNull(integerChannel.receive(0));
router.handleMessage(message2);
assertEquals(message2, integerChannel.receive(0));
@@ -78,14 +79,14 @@ public class PayloadTypeRouterTests {
router.handleMessage(message1);
assertEquals(message1, newChannel.receive(0));
// validate exception is thrown if mappings were removed and
// validate exception is thrown if mappings were removed and
// channelResolutionRequires = true (which is the default)
router.removeChannelMapping(String.class.getName());
router.removeChannelMapping(Integer.class.getName());
router.setResolutionRequired(true);
try {
router.handleMessage(message1);
fail();
@@ -104,7 +105,7 @@ public class PayloadTypeRouterTests {
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("numberChannel", numberChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
@@ -117,7 +118,7 @@ public class PayloadTypeRouterTests {
assertNotNull(result);
assertEquals(99, result.getPayload());
assertNull(defaultChannel.receive(0));
// validate dynamics
QueueChannel newChannel = new QueueChannel();
beanFactory.registerSingleton("newChannel", newChannel);
@@ -136,20 +137,20 @@ public class PayloadTypeRouterTests {
numberChannel.setBeanName("numberChannel");
QueueChannel integerChannel = new QueueChannel();
integerChannel.setBeanName("integerChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("numberChannel", numberChannel);
beanFactory.registerSingleton("integerChannel", integerChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<Integer> message = new GenericMessage<Integer>(99);
router.handleMessage(message);
@@ -166,18 +167,18 @@ public class PayloadTypeRouterTests {
defaultChannel.setBeanName("defaultChannel");
QueueChannel comparableChannel = new QueueChannel();
comparableChannel.setBeanName("comparableChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("comparableChannel", comparableChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<Integer> message = new GenericMessage<Integer>(99);
router.handleMessage(message);
@@ -186,118 +187,118 @@ public class PayloadTypeRouterTests {
assertEquals(99, result.getPayload());
assertNull(defaultChannel.receive(0));
}
@Test
public void extendedInterfaceMatch() {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel i2Channel = new QueueChannel();
i2Channel.setBeanName("i2Channel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("i2Channel", i2Channel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(I2.class.getName(), "i2Channel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
Message<?> result = i2Channel.receive(0);
assertNotNull(result);
}
@Test
@Test
public void higherWeightInterface() {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel serializableChannel = new QueueChannel();
serializableChannel.setBeanName("serializableChannel");
QueueChannel i3Channel = new QueueChannel();
i3Channel.setBeanName("i3Channel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("serializableChannel", serializableChannel);
beanFactory.registerSingleton("i3Channel", i3Channel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
payloadTypeChannelMap.put(I3.class.getName(), "i3Channel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
assertNotNull(serializableChannel.receive(0));
assertNull(i3Channel.receive(0));
}
@Test
public void superclassWinsOverDistantInterface() {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel c3Channel = new QueueChannel();
c3Channel.setBeanName("c3Channel");
QueueChannel i4Channel = new QueueChannel();
i4Channel.setBeanName("i4Channel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("c3Channel", c3Channel);
beanFactory.registerSingleton("i4Channel", i4Channel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(C3.class.getName(), "c3Channel");
payloadTypeChannelMap.put(I4.class.getName(), "i4Channel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
Message<?> result = c3Channel.receive(0);
assertNotNull(result);
}
@Test
public void directInterfaceOverTwoHopSuperclass() {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel c3Channel = new QueueChannel();
c3Channel.setBeanName("c3Channel");
QueueChannel i1AChannel = new QueueChannel();
i1AChannel.setBeanName("i1AChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("c3Channel", c3Channel);
beanFactory.registerSingleton("i1AChannel", i1AChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(C3.class.getName(), "c3Channel");
payloadTypeChannelMap.put(I1A.class.getName(), "i1AChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
@@ -313,20 +314,20 @@ public class PayloadTypeRouterTests {
numberChannel.setBeanName("numberChannel");
QueueChannel comparableChannel = new QueueChannel();
comparableChannel.setBeanName("comparableChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("numberChannel", numberChannel);
beanFactory.registerSingleton("comparableChannel", comparableChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<Integer> message = new GenericMessage<Integer>(99);
router.handleMessage(message);
@@ -335,7 +336,7 @@ public class PayloadTypeRouterTests {
assertEquals(99, result.getPayload());
assertNull(numberChannel.receive(0));
assertNull(defaultChannel.receive(0));
// validate dynamics
QueueChannel newChannel = new QueueChannel();
beanFactory.registerSingleton("newChannel", newChannel);
@@ -354,20 +355,20 @@ public class PayloadTypeRouterTests {
serializableChannel.setBeanName("serializableChannel");
QueueChannel comparableChannel = new QueueChannel();
comparableChannel.setBeanName("comparableChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("serializableChannel", serializableChannel);
beanFactory.registerSingleton("comparableChannel", comparableChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
payloadTypeChannelMap.put(Comparable.class.getName(), "comparableChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
@@ -381,20 +382,20 @@ public class PayloadTypeRouterTests {
numberChannel.setBeanName("numberChannel");
QueueChannel serializableChannel = new QueueChannel();
serializableChannel.setBeanName("serializableChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("numberChannel", numberChannel);
beanFactory.registerSingleton("serializableChannel", serializableChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(Number.class.getName(), "numberChannel");
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<Integer> message = new GenericMessage<Integer>(99);
router.handleMessage(message);
@@ -411,19 +412,19 @@ public class PayloadTypeRouterTests {
QueueChannel integerChannel = new QueueChannel();
stringChannel.setBeanName("stringChannel");
integerChannel.setBeanName("integerChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("stringChannel", stringChannel);
beanFactory.registerSingleton("integerChannel", integerChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
payloadTypeChannelMap.put(Integer.class.getName(), "integerChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
Message<String> message1 = new GenericMessage<String>("test");
Message<Integer> message2 = new GenericMessage<Integer>(123);
router.handleMessage(message1);
@@ -440,18 +441,18 @@ public class PayloadTypeRouterTests {
stringChannel.setBeanName("stringChannel");
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("stringChannel", stringChannel);
beanFactory.registerSingleton("defaultChannel", defaultChannel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(String.class.getName(), "stringChannel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<String> message1 = new GenericMessage<String>("test");
Message<Integer> message2 = new GenericMessage<Integer>(123);
@@ -464,107 +465,107 @@ public class PayloadTypeRouterTests {
assertNotNull(result2);
assertEquals(123, result2.getPayload());
}
@Test
public void classWinsOverMoreDistantAmbiguousInterfaces() throws Exception {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel i5aChannel = new QueueChannel();
i5aChannel.setBeanName("i5aChannel");
QueueChannel i5bChannel = new QueueChannel();
i5bChannel.setBeanName("i5bChannel");
QueueChannel c2Channel = new QueueChannel();
c2Channel.setBeanName("c2Channel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("i5aChannel", i5aChannel);
beanFactory.registerSingleton("i5bChannel", i5bChannel);
beanFactory.registerSingleton("c2Channel", c2Channel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(I5A.class.getName(), "i5aChannel");
payloadTypeChannelMap.put(I5B.class.getName(), "i5bChannel");
payloadTypeChannelMap.put(C2.class.getName(), "c2Channel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
assertNotNull(c2Channel.receive(100));
}
@Test(expected=MessageHandlingException.class)
public void classLosesOverLessDistantAmbiguousInterfaces() throws Exception {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel i2Channel = new QueueChannel();
i2Channel.setBeanName("i2Channel");
QueueChannel serializableChannel = new QueueChannel();
serializableChannel.setBeanName("serializableChannel");
QueueChannel c3Channel = new QueueChannel();
c3Channel.setBeanName("c3Channel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("i2Channel", i2Channel);
beanFactory.registerSingleton("serializableChannel", serializableChannel);
beanFactory.registerSingleton("c3Channel", c3Channel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(I2.class.getName(), "i2Channel");
payloadTypeChannelMap.put(Serializable.class.getName(), "serializableChannel");
payloadTypeChannelMap.put(C3.class.getName(), "c3Channel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
}
@Test(expected=MessageHandlingException.class)
public void classLosesOverAmbiguousInterfacesAtSameLevel() throws Exception {
QueueChannel defaultChannel = new QueueChannel();
defaultChannel.setBeanName("defaultChannel");
QueueChannel i1aChannel = new QueueChannel();
i1aChannel.setBeanName("i1aChannel");
QueueChannel i1bChannel = new QueueChannel();
i1bChannel.setBeanName("i1bChannel");
QueueChannel c2Channel = new QueueChannel();
c2Channel.setBeanName("c2Channel");
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
beanFactory.registerSingleton("defaultChannel", defaultChannel);
beanFactory.registerSingleton("i1aChannel", i1aChannel);
beanFactory.registerSingleton("i1bChannel", i1bChannel);
beanFactory.registerSingleton("c2Channel", c2Channel);
Map<String, String> payloadTypeChannelMap = new ConcurrentHashMap<String, String>();
payloadTypeChannelMap.put(I1A.class.getName(), "i1aChannel");
payloadTypeChannelMap.put(I1B.class.getName(), "i2bChannel");
payloadTypeChannelMap.put(C2.class.getName(), "c2Channel");
PayloadTypeRouter router = new PayloadTypeRouter();
router.setBeanFactory(beanFactory);
router.setChannelMappings(payloadTypeChannelMap);
router.setDefaultOutputChannel(defaultChannel);
Message<C1> message = new GenericMessage<C1>(new C1());
router.handleMessage(message);
}
@SuppressWarnings("serial")
public static class C1 extends C2 implements I1A, I1B {}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -15,8 +15,8 @@
*/
package org.springframework.integration.router.config;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
@@ -29,6 +29,7 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class ExceptionTypeRouterParserTests {
@@ -38,19 +39,19 @@ public class ExceptionTypeRouterParserTests {
public void testExceptionTypeRouterConfig(){
ApplicationContext context = new ClassPathXmlApplicationContext("ExceptionTypeRouterParserTests-context.xml", this.getClass());
MessageChannel inputChannel = context.getBean("inChannel", MessageChannel.class);
inputChannel.send(new GenericMessage<Throwable>(new NullPointerException()));
QueueChannel nullPointerChannel = context.getBean("nullPointerChannel", QueueChannel.class);
Message<Throwable> npeMessage = (Message<Throwable>) nullPointerChannel.receive(1000);
assertNotNull(npeMessage);
assertTrue(npeMessage.getPayload() instanceof NullPointerException);
inputChannel.send(new GenericMessage<Throwable>(new IllegalArgumentException()));
QueueChannel illegalArgumentChannel = context.getBean("illegalArgumentChannel", QueueChannel.class);
Message<Throwable> iaMessage = (Message<Throwable>) illegalArgumentChannel.receive(1000);
assertNotNull(iaMessage);
assertTrue(iaMessage.getPayload() instanceof IllegalArgumentException);
inputChannel.send(new GenericMessage<String>("Hello"));
QueueChannel outputChannel = context.getBean("outputChannel", QueueChannel.class);
assertNotNull(outputChannel.receive(1000));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2008 the original author or authors.
* Copyright 2002-2013 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,7 +16,7 @@
package org.springframework.integration.splitter;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNotNull;
@@ -37,6 +37,7 @@ import org.springframework.integration.support.MessageBuilder;
/**
* @author Mark Fisher
* @author Iwein Fuld
* @author Gunnar Hillert
*/
public class DefaultSplitterTests {

View File

@@ -37,6 +37,8 @@ import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.annotation.Splitter;
import org.springframework.integration.message.GenericMessage;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@@ -47,6 +49,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class SplitterIntegrationTests {
@Autowired

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2010 the original author or authors.
* Copyright 2002-2013 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,9 +16,9 @@
package org.springframework.integration.store;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.io.File;
import java.util.Properties;
@@ -32,6 +32,7 @@ import org.springframework.integration.store.PropertiesPersistingMetadataStore;
/**
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Gunnar Hillert
* @since 2.0
*/
public class PropertiesPersistingMetadataStoreTests {
@@ -57,7 +58,7 @@ public class PropertiesPersistingMetadataStoreTests {
File file = new File("target/foo" + "/metadata-store.properties");
file.deleteOnExit();
PropertiesPersistingMetadataStore metadataStore = new PropertiesPersistingMetadataStore();
metadataStore.setBaseDirectory("target/foo");
metadataStore.setBaseDirectory("target/foo");
metadataStore.afterPropertiesSet();
metadataStore.put("foo", "bar");
metadataStore.destroy();

View File

@@ -16,10 +16,6 @@
package org.springframework.integration.transformer;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static junit.framework.Assert.assertNull;
import java.lang.reflect.Constructor;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
@@ -40,6 +36,10 @@ import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.util.ClassUtils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
* @author Oleg Zhurakousky

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2011 the original author or authors.
* Copyright 2002-2013 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.
@@ -35,14 +35,15 @@ import org.springframework.expression.spel.support.StandardEvaluationContext;
import org.springframework.integration.Message;
import org.springframework.integration.support.MessageBuilder;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertNotNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
/**
*
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @since 2.0
*/
public class ObjectToMapTransformerTests {
@@ -53,89 +54,89 @@ public class ObjectToMapTransformerTests {
StandardEvaluationContext context = new StandardEvaluationContext();
context.addPropertyAccessor(new MapAccessor());
ExpressionParser parser = new SpelExpressionParser();
ObjectToMapTransformer transformer = new ObjectToMapTransformer();
Message<Employee> message = MessageBuilder.withPayload(employee).build();
Message<?> transformedMessage = transformer.transform(message);
Map<String, Object> transformedMap = (Map<String, Object>) transformedMessage.getPayload();
assertNotNull(transformedMap);
Object valueFromTheMap = null;
Object valueFromExpression = null;
Expression expression = null;
expression = parser.parseExpression("departments[0]");
valueFromTheMap = transformedMap.get("departments[0]");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.address.coordinates");
valueFromTheMap = transformedMap.get("person.address.coordinates");
valueFromExpression = expression.getValue(context, employee, Map.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.akaNames[0]");
valueFromTheMap = transformedMap.get("person.akaNames[0]");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("testMapInMapData.internalMapA.bar");
valueFromTheMap = transformedMap.get("testMapInMapData.internalMapA.bar");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("companyAddress.street");
valueFromTheMap = transformedMap.get("companyAddress.street");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.lname");
valueFromTheMap = transformedMap.get("person.lname");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.address.mapWithListData.mapWithListTestData[1]");
valueFromTheMap = transformedMap.get("person.address.mapWithListData.mapWithListTestData[1]");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("companyAddress.city");
valueFromTheMap = transformedMap.get("companyAddress.city");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.akaNames[2]");
valueFromTheMap = transformedMap.get("person.akaNames[2]");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.child");
valueFromTheMap = transformedMap.get("person.child");
valueFromExpression = expression.getValue(context, employee, String.class);
assertNull(valueFromTheMap);
assertNull(valueFromExpression);
expression = parser.parseExpression("testMapInMapData.internalMapA.foo");
valueFromTheMap = transformedMap.get("testMapInMapData.internalMapA.foo");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.address.city");
valueFromTheMap = transformedMap.get("person.address.city");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("companyAddress.coordinates.latitude[0]");
valueFromTheMap = transformedMap.get("companyAddress.coordinates.latitude[0]");
valueFromExpression = expression.getValue(context, employee, Integer.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("person.remarks[1].baz");
valueFromTheMap = transformedMap.get("person.remarks[1].baz");
valueFromExpression = expression.getValue(context, employee, String.class);
assertEquals(valueFromTheMap, valueFromExpression);
expression = parser.parseExpression("listOfDates[0][1]");
valueFromTheMap = new Date((Long) transformedMap.get("listOfDates[0][1]"));
valueFromExpression = expression.getValue(context, employee, Date.class);
@@ -145,7 +146,7 @@ public class ObjectToMapTransformerTests {
@Test(expected=MessageTransformationException.class)
public void testObjectToSpelMapTransformerWithCycle(){
Employee employee = this.buildEmployee();
Child child = new Child();
Child child = new Child();
Person parent = employee.getPerson();
parent.setChild(child);
child.setParent(parent);
@@ -160,24 +161,24 @@ public class ObjectToMapTransformerTests {
companyAddress.setCity("Philadelphia");
companyAddress.setStreet("1123 Main");
companyAddress.setZip("12345");
Map<String, Long[]> coordinates = new HashMap<String, Long[]>();
coordinates.put("latitude", new Long[]{(long)1, (long)5, (long)13});
coordinates.put("longitude", new Long[]{(long)156});
companyAddress.setCoordinates(coordinates);
List<Date> datesA = new ArrayList<Date>();
datesA.add(new Date(System.currentTimeMillis() + 10000));
datesA.add(new Date(System.currentTimeMillis() + 20000));
List<Date> datesB = new ArrayList<Date>();
datesB.add(new Date(System.currentTimeMillis() + 30000));
datesB.add(new Date(System.currentTimeMillis() + 40000));
List<List<Date>> listOfDates = new ArrayList<List<Date>>();
listOfDates.add(datesA);
listOfDates.add(datesB);
Employee employee = new Employee();
employee.setCompanyName("ABC Inc.");
employee.setCompanyAddress(companyAddress);
@@ -186,7 +187,7 @@ public class ObjectToMapTransformerTests {
departments.add("HR");
departments.add("IT");
employee.setDepartments(departments);
Person person = new Person();
person.setFname("Justin");
person.setLname("Case");
@@ -203,7 +204,7 @@ public class ObjectToMapTransformerTests {
mapWithListTestData.put("mapWithListTestData", listTestData);
personAddress.setMapWithListData(mapWithListTestData);
person.setAddress(personAddress);
Map<String, Object> remarksA = new HashMap<String, Object>();
Map<String, Object> remarksB = new HashMap<String, Object>();
remarksA.put("foo", "foo");
@@ -214,22 +215,22 @@ public class ObjectToMapTransformerTests {
remarks.add(remarksB);
person.setRemarks(remarks);
employee.setPerson(person);
Map<String, Map<String, Object>> testMapData = new HashMap<String, Map<String, Object>>();
Map<String, Object> internalMapA = new HashMap<String, Object>();
internalMapA.put("foo", "foo");
internalMapA.put("bar", "bar");
Map<String, Object> internalMapB = new HashMap<String, Object>();
internalMapB.put("baz", "baz");
testMapData.put("internalMapA", internalMapA);
testMapData.put("internalMapB", internalMapB);
employee.setTestMapInMapData(testMapData);
return employee;
}
public static class Employee{
private List<String> departments;
private List<List<Date>> listOfDates;
@@ -275,7 +276,7 @@ public class ObjectToMapTransformerTests {
this.departments = departments;
}
}
public static class Person{
private String fname;
private String lname;
@@ -338,7 +339,7 @@ public class ObjectToMapTransformerTests {
this.address = address;
}
}
public static class Address{
private String street;
private String city;
@@ -376,7 +377,7 @@ public class ObjectToMapTransformerTests {
this.coordinates = coordinates;
}
}
public static class Child {
private Person parent;

View File

@@ -15,10 +15,10 @@
*/
package org.springframework.integration.util;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
@@ -65,6 +65,7 @@ import org.springframework.integration.message.GenericMessage;
/**
* @author Oleg Zhurakousky
* @author Gary Russell
* @author Gunnar Hillert
*
*/
public class BeanFactoryTypeConverterTests {