renamed modules org.springframework.integration.* -> spring-integration-*

@Ignore'd SimpleTcpNetOutboundGatewayTests#testOutboundClose() to avoid failure; this failure is correlated to the module name change, but hard to understand how it would be caused by it
This commit is contained in:
Chris Beams
2010-05-25 13:21:25 +00:00
parent b97b2fb090
commit c08a7a657e
1484 changed files with 18 additions and 23 deletions

View File

@@ -0,0 +1,196 @@
/*
* Copyright 2002-2008 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.test.matcher;
import static org.hamcrest.CoreMatchers.anything;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasAllHeaders;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasCorrelationId;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasExpirationDate;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeader;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasHeaderKey;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasMessageId;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasSequenceNumber;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasSequenceSize;
import static org.springframework.integration.test.matcher.HeaderMatcher.hasTimestamp;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.hamcrest.Matcher;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
/**
* @author Alex Peters
* @author Iwein Fuld
*
*/
public class HeaderMatcherTests {
static final String UNKNOWN_KEY = "unknownKey";
static final String ANY_HEADER_VALUE = "bar";
static final String ANY_HEADER_KEY = "test.foo";
static final String ANY_PAYLOAD = "bla";
static final String OTHER_HEADER_KEY = "test.number";
static final Integer OTHER_HEADER_VALUE = Integer.valueOf(123);
Message<?> message;
@Before
public void setUp() {
message = MessageBuilder.withPayload(ANY_PAYLOAD).setHeader(ANY_HEADER_KEY, ANY_HEADER_VALUE).setHeader(
OTHER_HEADER_KEY, OTHER_HEADER_VALUE).build();
}
@Test
public void hasEntry_withValidKeyValue_matches() throws Exception {
assertThat(message, hasHeader(ANY_HEADER_KEY, ANY_HEADER_VALUE));
assertThat(message, hasHeader(OTHER_HEADER_KEY, OTHER_HEADER_VALUE));
}
@Test
public void hasEntry_withUnknownKey_notMatching() throws Exception {
assertThat(message, not(hasHeader("test.unknown", ANY_HEADER_VALUE)));
}
@Test
public void hasEntry_withValidKeyAndMatcherValue_matches() throws Exception {
assertThat(message, hasHeader(ANY_HEADER_KEY, is(String.class)));
assertThat(message, hasHeader(ANY_HEADER_KEY, notNullValue()));
assertThat(message, hasHeader(ANY_HEADER_KEY, is(ANY_HEADER_VALUE)));
}
@Test
public void hasEntry_withValidKeyAndMatcherValue_notMatching() throws Exception {
assertThat(message, not(hasHeader(ANY_HEADER_KEY, is(Integer.class))));
}
@Test
public void hasKey_withValidKey_matches() throws Exception {
assertThat(message, hasHeaderKey(ANY_HEADER_KEY));
assertThat(message, hasHeaderKey(OTHER_HEADER_KEY));
}
@Test
public void hasKey_withInvalidKey_notMatching() throws Exception {
assertThat(message, not(hasHeaderKey(UNKNOWN_KEY)));
}
@Test
public void hasAllEntries_withMessageHeader_matches() throws Exception {
Map<String, Object> expectedInHeaderMap = message.getHeaders();
assertThat(message, hasAllHeaders(expectedInHeaderMap));
}
@Test
public void hasAllEntries_withValidKeyValueOrMatcherValue_matches() throws Exception {
Map<String, Object> expectedInHeaderMap = new HashMap<String, Object>();
expectedInHeaderMap.put(ANY_HEADER_KEY, ANY_HEADER_VALUE);
expectedInHeaderMap.put(OTHER_HEADER_KEY, is(OTHER_HEADER_VALUE));
assertThat(message, hasAllHeaders(expectedInHeaderMap));
}
@Test
public void hasAllEntries_withInvalidValidKeyValueOrMatcherValue_notMatching() throws Exception {
Map<String, Object> expectedInHeaderMap = new HashMap<String, Object>();
expectedInHeaderMap.put(ANY_HEADER_KEY, ANY_HEADER_VALUE); // valid
expectedInHeaderMap.put(UNKNOWN_KEY, not(nullValue())); // fails
assertThat(message, not(hasAllHeaders(expectedInHeaderMap)));
expectedInHeaderMap.remove(UNKNOWN_KEY);
expectedInHeaderMap.put(OTHER_HEADER_KEY, ANY_HEADER_VALUE); // fails
}
@Test
public void readableException_singleHeader() throws Exception {
try {
assertThat(message, hasHeader("corn", "bread"));
}
catch (AssertionError ae) {
assertTrue(ae.getMessage().contains("Expected: a Message with Headers containing "));
}
}
@Test
public void readableException_allHeaders() throws Exception {
try {
Map<String, String> entries = new HashMap<String, String>();
entries.put("corn", "bread");
entries.put("chocolate", "pudding");
assertThat(message, hasAllHeaders(entries));
}
catch (AssertionError ae) {
assertTrue(ae.getMessage().contains("Expected: a Message with Headers containing "));
}
}
@Test
public void hasMessageId_sameId() throws Exception {
assertThat(message, hasMessageId(message.getHeaders().getId()));
}
@Test
public void hasCorrelationId_() throws Exception {
UUID correlationId = message.getHeaders().getId();
message = MessageBuilder.withPayload("blabla").setCorrelationId(correlationId).build();
assertThat(message, hasCorrelationId(correlationId));
}
@Test
public void hasSequenceNumber_() throws Exception {
int sequenceNumber = 123;
message = MessageBuilder.fromMessage(message).setSequenceNumber(sequenceNumber).build();
assertThat(message, hasSequenceNumber(sequenceNumber));
}
@Test
public void hasSequenceSize_() throws Exception {
int sequenceSize = 123;
message = MessageBuilder.fromMessage(message).setSequenceSize(sequenceSize).build();
assertThat(message, hasSequenceSize(sequenceSize));
assertThat(message, hasSequenceSize(is(sequenceSize)));
}
@Test
public void hasTimestamp_() throws Exception {
assertThat(message, hasTimestamp(new Date(message.getHeaders().getTimestamp())));
}
@Test
public void hasExpirationDate_() throws Exception {
Matcher<Long> anyMatcher = anything();
assertThat(message, not(hasExpirationDate(anyMatcher)));
Date expirationDate = new Date(System.currentTimeMillis() + 10000);
message = MessageBuilder.fromMessage(message).setExpirationDate(expirationDate).build();
assertThat(message, hasExpirationDate(expirationDate));
assertThat(message, hasExpirationDate(not(is((System.currentTimeMillis())))));
}
}

View File

@@ -0,0 +1,104 @@
package org.springframework.integration.test.matcher;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.springframework.integration.test.matcher.MapContentMatchers.hasAllEntries;
import static org.springframework.integration.test.matcher.MapContentMatchers.hasEntry;
import static org.springframework.integration.test.matcher.MapContentMatchers.hasKey;
import java.util.HashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
/**
* @author Alex Peters
*
*/
public class MapContainsTests {
static final String UNKNOWN_KEY = "unknownKey";
static final String SOME_VALUE = "bar";
static final String SOME_KEY = "test.foo";
static final String OTHER_KEY = "test.number";
static final Integer OTHER_VALUE = Integer.valueOf(123);
private HashMap<String, Object> map;
@Before
public void setUp() {
map = new HashMap<String, Object>();
map.put(SOME_KEY, SOME_VALUE);
map.put(OTHER_KEY, OTHER_VALUE);
}
@Test
public void hasKey_validKey_matching() throws Exception {
assertThat(map, hasKey(SOME_KEY));
}
@Test
public void hasKey_unknownKey_notMatching() throws Exception {
assertThat(map, not(hasKey(UNKNOWN_KEY)));
}
@Test
public void hasEntry_withValidKeyValue_matches() throws Exception {
assertThat(map, hasEntry(SOME_KEY, SOME_VALUE));
assertThat(map, hasEntry(OTHER_KEY, OTHER_VALUE));
}
@Test
public void hasEntry_withUnknownKey_notMatching() throws Exception {
assertThat(map, not(hasEntry("test.unknown", SOME_VALUE)));
}
@Test
public void hasEntry_withValidKeyAndMatcherValue_matches() throws Exception {
assertThat(map, hasEntry(SOME_KEY, is(String.class)));
assertThat(map, hasEntry(SOME_KEY, notNullValue()));
assertThat(map, hasEntry(SOME_KEY, is(SOME_VALUE)));
}
@Test
public void hasEntry_withValidKeyAndMatcherValue_notMatching() throws Exception {
assertThat(map, not(hasEntry(SOME_KEY, is(Integer.class))));
}
@Test
public void hasEntry_withTypedValueMap_matches() throws Exception {
Map<String, String> map = new HashMap<String, String>();
map.put("a", "b");
map.put("c", "d");
assertThat(map, hasEntry("a", "b"));
assertThat(map, not(hasEntry(SOME_KEY, is("a"))));
assertThat(map, hasAllEntries(map));
}
@Test
public void hasAllEntries_withValidKeyValueOrMatcherValue_matches() throws Exception {
Map<String, Object> expectedInHeaderMap = new HashMap<String, Object>();
expectedInHeaderMap.put(SOME_KEY, SOME_VALUE);
expectedInHeaderMap.put(OTHER_KEY, is(OTHER_VALUE));
assertThat(map, hasAllEntries(expectedInHeaderMap));
}
@Test
public void hasAllEntries_withInvalidValidKeyValueOrMatcherValue_notMatching() throws Exception {
Map<String, Object> expectedInHeaderMap = new HashMap<String, Object>();
expectedInHeaderMap.put(SOME_KEY, SOME_VALUE); // valid
expectedInHeaderMap.put(UNKNOWN_KEY, not(nullValue())); // fails
assertThat(map, not(hasAllEntries(expectedInHeaderMap)));
expectedInHeaderMap.remove(UNKNOWN_KEY);
expectedInHeaderMap.put(OTHER_KEY, SOME_VALUE); // fails
}
}

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2002-2008 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.test.matcher;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.exceptions.verification.junit.ArgumentsAreDifferent;
import org.mockito.runners.MockitoJUnitRunner;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageHandler;
import java.util.Date;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.springframework.integration.test.matcher.MockitoMessageMatchers.messageWithHeaderEntry;
import static org.springframework.integration.test.matcher.MockitoMessageMatchers.messageWithPayload;
/**
* @author Alex Peters
* @author Iwein Fuld
*
*/
@RunWith(MockitoJUnitRunner.class)
public class MockitoMessageMatchersTests {
static final Date SOME_PAYLOAD = new Date();
static final String UNKNOWN_KEY = "unknownKey";
static final String SOME_HEADER_VALUE = "bar";
static final String SOME_HEADER_KEY = "test.foo";
@Mock
MessageHandler handler;
@Mock
MessageChannel channel;
Message<Date> message;
@Before
public void setUp() {
message = MessageBuilder.withPayload(SOME_PAYLOAD).setHeader(SOME_HEADER_KEY,
SOME_HEADER_VALUE).build();
}
@Test
public void anyMatcher_withVerifyArgumentMatcherAndEqualPayload_matching() throws Exception {
handler.handleMessage(message);
verify(handler).handleMessage(messageWithPayload(SOME_PAYLOAD));
verify(handler).handleMessage(messageWithPayload(is(Date.class)));
}
@Test(expected = ArgumentsAreDifferent.class)
public void anyMatcher_withVerifyAndDifferentPayload_notMatching() throws Exception {
handler.handleMessage(message);
verify(handler).handleMessage(messageWithPayload(nullValue()));
}
@Test
public void anyMatcher_withWhenArgumentMatcherAndEqualPayload_matching() throws Exception {
when(channel.send(messageWithPayload(SOME_PAYLOAD))).thenReturn(true);
assertThat(channel.send(message), is(true));
}
@Test
public void anyMatcher_withWhenAndDifferentPayload_notMatching() throws Exception {
when(channel.send(messageWithHeaderEntry(SOME_HEADER_KEY, is(Short.class)))).thenReturn(true);
assertThat(channel.send(message), is(false));
}
}

View File

@@ -0,0 +1,72 @@
/*
* Copyright 2002-2008 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.test.matcher;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.springframework.integration.test.matcher.PayloadMatcher.hasPayload;
import java.math.BigDecimal;
import org.junit.Test;
import org.springframework.integration.core.Message;
import org.springframework.integration.message.MessageBuilder;
/**
* @author Alex Peters
* @author Iwein Fuld
*/
public class PayloadMatcherTests {
static final BigDecimal ANY_PAYLOAD = new BigDecimal("1.123");
Message<BigDecimal> message =MessageBuilder.withPayload(ANY_PAYLOAD).build();;
@Test
public void hasPayload_withEqualValue_matches() throws Exception {
assertThat(message, hasPayload(new BigDecimal("1.123")));
}
@Test
public void hasPayload_withNotEqualValue_notMatching() throws Exception {
assertThat(message, not(hasPayload(new BigDecimal("456"))));
}
@Test
public void hasPayload_withMatcher_matches() throws Exception {
assertThat(message,
hasPayload(is(BigDecimal.class)));
assertThat(message, hasPayload(notNullValue()));
}
@Test
public void hasPayload_withNotMatchingMatcher_notMatching()
throws Exception {
assertThat(message, not((hasPayload(is(String.class)))));
}
@Test
public void readableException() throws Exception {
try {
assertThat(message, hasPayload("woot"));
} catch(AssertionError ae){
assertTrue(ae.getMessage().contains("Expected: a Message with payload: "));
}
}
}

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:i="http://www.springframework.org/schema/integration"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd">
<i:channel id="in"/>
<i:chain input-channel="in" output-channel="out">
<i:filter expression="payload == 'singleAnnotatedMethodOnClass'"/>
<i:service-activator ref="singleAnnotatedMethodOnClass"/>
</i:chain>
<bean id="singleAnnotatedMethodOnClass" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg
value="org.springframework.integration.test.mockito.ServiceActivatorOnMockitoMockTests.SingleAnnotatedMethodOnClass"/>
</bean>
<i:chain input-channel="in" output-channel="out">
<i:filter expression="payload == 'SingleMethodOnClass'"/>
<i:service-activator ref="singleMethodOnClass"/>
</i:chain>
<bean id="singleMethodOnClass" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg
value="org.springframework.integration.test.mockito.ServiceActivatorOnMockitoMockTests.SingleMethodOnClass"/>
</bean>
<i:chain input-channel="in" output-channel="out">
<i:filter expression="payload == 'SingleMethodAcceptingHeaderOnClass'"/>
<i:service-activator ref="singleMethodAcceptingHeaderOnClass"/>
</i:chain>
<bean id="singleMethodAcceptingHeaderOnClass" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg
value="org.springframework.integration.test.mockito.ServiceActivatorOnMockitoMockTests.SingleMethodAcceptingHeaderOnClass"/>
</bean>
<i:channel id="out">
<i:queue capacity="10"/>
</i:channel>
</beans>

View File

@@ -0,0 +1,94 @@
/*
* Copyright 2002-2009 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.test.mockito;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.integration.annotation.Header;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.mockito.Mockito.verify;
/**
* @author Iwein Fuld
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class ServiceActivatorOnMockitoMockTests {
@Autowired
@Qualifier("in")
MessageChannel in;
@Autowired
@Qualifier("out")
PollableChannel out;
public static class SingleAnnotatedMethodOnClass {
@ServiceActivator
public String move(String s) {
return s;
}
}
@Autowired
SingleAnnotatedMethodOnClass singleAnnotatedMethodOnClass;
@Test
public void shouldInvokeMockedSingleAnnotatedMethodOnClass() {
in.send(MessageBuilder.withPayload("singleAnnotatedMethodOnClass").build());
verify(singleAnnotatedMethodOnClass).move("singleAnnotatedMethodOnClass");
}
public static class SingleMethodOnClass {
public String move(String s) {
return s;
}
}
@Autowired
SingleMethodOnClass singleMethodOnClass;
@Test
public void shouldInvokeMockedSingleMethodOnClass() {
in.send(MessageBuilder.withPayload("SingleMethodOnClass").build());
verify(singleMethodOnClass).move("SingleMethodOnClass");
}
public static class SingleMethodAcceptingHeaderOnClass {
public String move(@Header("s") String s) {
return s;
}
}
@Autowired
SingleMethodAcceptingHeaderOnClass singleMethodAcceptingHeaderOnClass;
@Test
public void shouldInvokeMockedSingleMethodAcceptingHeaderOnClass() {
in.send(MessageBuilder.withPayload("SingleMethodAcceptingHeaderOnClass").setHeader("s", "SingleMethodAcceptingHeaderOnClass").build());
verify(singleMethodAcceptingHeaderOnClass).move("SingleMethodAcceptingHeaderOnClass");
}
}