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-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.
@@ -40,16 +40,15 @@ import org.springframework.ws.WebServiceMessageFactory;
import org.springframework.ws.client.core.WebServiceMessageCallback;
import org.springframework.ws.client.support.destination.DestinationProvider;
import org.springframework.ws.soap.SoapMessage;
import org.springframework.ws.soap.SoapMessageFactory;
import org.springframework.ws.transport.WebServiceConnection;
import org.springframework.ws.transport.WebServiceMessageSender;
import org.springframework.xml.namespace.QNameUtils;
import static org.junit.Assert.*;
/**
* @author Mark Fisher
* @author Artem Bilan
* @author Gunnar Hillert
* @since 2.0
*/
public class SimpleWebServiceOutboundGatewayTests {
@@ -105,7 +104,7 @@ public class SimpleWebServiceOutboundGatewayTests {
Mockito.when(messageSender.createConnection(Mockito.any(URI.class))).thenReturn(wsConnection);
Mockito.when(messageSender.supports(Mockito.any(URI.class))).thenReturn(true);
Mockito.doAnswer(new Answer() {
Mockito.doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) throws Exception{
Object[] args = invocation.getArguments();
WebServiceMessageFactory factory = (WebServiceMessageFactory) args[0];

View File

@@ -1,12 +1,12 @@
/*
* 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
*
*
* 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.
@@ -41,15 +41,17 @@ import org.springframework.integration.ws.SimpleWebServiceInboundGateway;
import org.springframework.integration.ws.SoapHeaderMapper;
import org.springframework.oxm.Unmarshaller;
import org.springframework.oxm.support.AbstractMarshaller;
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;
import org.springframework.ws.context.DefaultMessageContext;
import org.springframework.ws.context.MessageContext;
import org.springframework.ws.soap.SoapMessage;
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 static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@@ -61,23 +63,25 @@ import static org.mockito.Mockito.when;
* @author Iwein Fuld
* @author Oleg Zhurakousky
* @author Mark Fisher
* @author Gunnar Hillert
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
public class WebServiceInboundGatewayParserTests {
@Autowired
@Qualifier("requestsMarshalling")
PollableChannel requestsMarshalling;
@Autowired
@Qualifier("requestsSimple")
PollableChannel requestsSimple;
@Autowired
@Qualifier("customErrorChannel")
MessageChannel customErrorChannel;
@Autowired
@Qualifier("requestsVerySimple")
MessageChannel requestsVerySimple;
@@ -98,7 +102,7 @@ public class WebServiceInboundGatewayParserTests {
assertThat(
(MessageChannel) accessor.getPropertyValue("requestChannel"),
is(requestsVerySimple));
assertThat(
(MessageChannel) accessor.getPropertyValue("errorChannel"),
is(customErrorChannel));
@@ -121,17 +125,20 @@ public class WebServiceInboundGatewayParserTests {
@Autowired
@Qualifier("marshalling")
MarshallingWebServiceInboundGateway marshallingGateway;
@Autowired
AbstractMarshaller marshaller;
@Test
public void marshallersSet() throws Exception {
DirectFieldAccessor accessor = new DirectFieldAccessor(marshallingGateway);
assertThat((AbstractMarshaller) accessor.getPropertyValue("marshaller"),
is(marshaller));
assertThat((AbstractMarshaller) accessor.getPropertyValue("unmarshaller"),
is(marshaller));
AbstractMarshaller retrievedMarshaller = (AbstractMarshaller) accessor.getPropertyValue("marshaller");
assertThat(retrievedMarshaller, is(marshaller));
AbstractMarshaller retrievedUnMarshaller = (AbstractMarshaller) accessor.getPropertyValue("unmarshaller");
assertThat(retrievedUnMarshaller, is(marshaller));
assertTrue("messaging gateway is not running", marshallingGateway.isRunning());
assertThat(
@@ -201,7 +208,7 @@ public class WebServiceInboundGatewayParserTests {
@SuppressWarnings("unused")
private static class TestHeaderMapper implements SoapHeaderMapper {
public void fromHeadersToRequest(MessageHeaders headers,
SoapMessage target) {
}

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.
@@ -16,8 +16,8 @@
package org.springframework.integration.ws.config;
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 static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

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.
@@ -16,7 +16,7 @@
package org.springframework.integration.ws.config;
import static junit.framework.Assert.assertEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
@@ -66,21 +66,22 @@ import org.w3c.dom.Element;
/**
* @author Oleg Zhurakousky
* @author Gunnar Hillert
*
*/
public class WebServiceOutboundGatewayWithHeaderMapperTests {
String responseSoapMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> " +
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +
String responseSoapMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> " +
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"> " +
"<SOAP-ENV:Header/>" +
"<SOAP-ENV:Body> " +
"<root><name>jane</name></root>" +
"</SOAP-ENV:Body> " +
"<SOAP-ENV:Body> " +
"<root><name>jane</name></root>" +
"</SOAP-ENV:Body> " +
"</SOAP-ENV:Envelope>";
String responseNonSoapMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> " +
String responseNonSoapMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?> " +
"<person><name>oleg</name></person>";
@SuppressWarnings("unchecked")
@Test
public void headerMapperParserTest() throws Exception{
@@ -88,17 +89,17 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
SimpleWebServiceOutboundGateway gateway = TestUtils.getPropertyValue(context.getBean("withHeaderMapper"), "handler", SimpleWebServiceOutboundGateway.class);
DefaultSoapHeaderMapper headerMapper = TestUtils.getPropertyValue(gateway, "headerMapper", DefaultSoapHeaderMapper.class);
assertNotNull(headerMapper);
List<String> requestHeaderNames = TestUtils.getPropertyValue(headerMapper, "requestHeaderNames", List.class);
assertEquals(2, requestHeaderNames.size());
assertEquals("foo*", requestHeaderNames.get(0));
assertEquals("*baz*", requestHeaderNames.get(1));
List<String> responseHeaderNames = TestUtils.getPropertyValue(headerMapper, "replyHeaderNames", List.class);
assertEquals(1, responseHeaderNames.size());
assertEquals("bar*", responseHeaderNames.get(0));
}
@Test
public void withHeaderMapperString() throws Exception{
String payload = "<root><name>bill</name></root>";
@@ -107,7 +108,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
assertEquals("bar", replyMessage.getHeaders().get("bar"));
assertNull(replyMessage.getHeaders().get("baz"));
}
@Test
public void withHeaderMapperStringPOX() throws Exception{
String payload = "<root><name>bill</name></root>";
@@ -115,7 +116,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
assertTrue(replyMessage.getPayload() instanceof String);
assertTrue(((String)replyMessage.getPayload()).contains("<person><name>oleg</name></person>"));
}
@Test
public void withHeaderMapperSource() throws Exception{
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
@@ -127,7 +128,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
assertEquals("bar", replyMessage.getHeaders().get("bar"));
assertNull(replyMessage.getHeaders().get("baz"));
}
@Test
public void withHeaderMapperSourcePOX() throws Exception{
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
@@ -135,10 +136,10 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
Document document = docBuilder.parse(new ByteArrayInputStream("<root><name>bill</name></root>".getBytes()));
DOMSource payload = new DOMSource(document);
Message<?> replyMessage = this.process(payload, "withHeaderMapper", "inputChannel", false);
assertTrue(replyMessage.getPayload() instanceof DOMSource);
assertTrue(replyMessage.getPayload() instanceof DOMSource);
assertTrue(this.extractStringResult(replyMessage).contains("<person><name>oleg</name></person>"));
}
@Test
public void withHeaderMapperDocument() throws Exception{
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
@@ -149,7 +150,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
assertEquals("bar", replyMessage.getHeaders().get("bar"));
assertNull(replyMessage.getHeaders().get("baz"));
}
@Test
public void withHeaderMapperDocumentPOX() throws Exception{
DocumentBuilderFactory dbfac = DocumentBuilderFactory.newInstance();
@@ -159,7 +160,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
assertTrue(replyMessage.getPayload() instanceof Document);
assertTrue(this.extractStringResult(replyMessage).contains("<person><name>oleg</name></person>"));
}
@Test
public void withHeaderMapperAndMarshaller() throws Exception{
Person person = new Person();
@@ -168,22 +169,22 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
assertEquals("bar", replyMessage.getHeaders().get("bar"));
assertNull(replyMessage.getHeaders().get("baz"));
}
@SuppressWarnings("rawtypes")
public Message<?> process(Object payload, String gatewayName, String channelName, final boolean soap) throws Exception{
ApplicationContext context = new ClassPathXmlApplicationContext("ws-outbound-gateway-with-headermappers.xml", this.getClass());
AbstractWebServiceOutboundGateway gateway = TestUtils.getPropertyValue(context.getBean(gatewayName), "handler", AbstractWebServiceOutboundGateway.class);
if (!soap){
WebServiceTemplate template = TestUtils.getPropertyValue(gateway, "webServiceTemplate", WebServiceTemplate.class);
template.setMessageFactory(new StubMessageFactory());
}
WebServiceMessageSender messageSender = Mockito.mock(WebServiceMessageSender.class);
WebServiceConnection wsConnection = Mockito.mock(WebServiceConnection.class);
Mockito.when(messageSender.createConnection(Mockito.any(URI.class))).thenReturn(wsConnection);
Mockito.when(messageSender.supports(Mockito.any(URI.class))).thenReturn(true);
Mockito.doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) {
Object[] args = invocation.getArguments();
@@ -191,7 +192,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
// try { // uncomment if you want to see a pretty-print of SOAP message
// Transformer transformer = TransformerFactory.newInstance().newTransformer();
// transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.transform(new DOMSource(soapMessage.getDocument()), new StreamResult(System.out));
// transformer.transform(new DOMSource(soapMessage.getDocument()), new StreamResult(System.out));
// } catch (Exception e) {
// // ignore
// }
@@ -202,11 +203,11 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
assertNotNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("abaz")));
assertNull(soapHeader.getAttributeValue(QNameUtils.parseQNameString("bar")));
}
return null;
}})
.when(wsConnection).send(Mockito.any(WebServiceMessage.class));
Mockito.doAnswer(new Answer() {
public Object answer(InvocationOnMock invocation) throws Exception{
Object[] args = invocation.getArguments();
@@ -214,26 +215,26 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
String responseMessage = factory instanceof SoapMessageFactory ? responseSoapMessage : responseNonSoapMessage;
WebServiceMessage wsMessage = factory.createWebServiceMessage(new ByteArrayInputStream(responseMessage.getBytes()));
if (soap){
((SoapMessage)wsMessage).getSoapHeader().addAttribute(QNameUtils.parseQNameString("bar"), "bar");
((SoapMessage)wsMessage).getSoapHeader().addAttribute(QNameUtils.parseQNameString("baz"), "baz");
}
// try { // uncomment if you want to see a pretty-print of SOAP message
// Transformer transformer = TransformerFactory.newInstance().newTransformer();
// transformer.setOutputProperty(OutputKeys.INDENT, "yes");
// transformer.transform(new DOMSource(soapMessage.getDocument()), new StreamResult(System.out));
// transformer.transform(new DOMSource(soapMessage.getDocument()), new StreamResult(System.out));
// } catch (Exception e) {
// // ignore
// }
return wsMessage;
}})
.when(wsConnection).receive(Mockito.any(WebServiceMessageFactory.class));
gateway.setMessageSender(messageSender);
MessageChannel inputChannel = context.getBean(channelName, MessageChannel.class);
Message<?> message =
Message<?> message =
MessageBuilder.withPayload(payload).
setHeader("foo", "foo").setHeader("foobar", "foobar").setHeader("abaz", "abaz").setHeader("bar", "bar").
setHeader(WebServiceHeaders.SOAP_ACTION, "someAction").build();
@@ -242,7 +243,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
Message<?> replyMessage = outputChannel.receive(0);
return replyMessage;
}
public static class Person{
private String name;
@@ -254,7 +255,7 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
this.name = name;
}
}
public static class SampleUnmarshaller implements Unmarshaller {
public boolean supports(Class<?> clazz) {
@@ -263,23 +264,23 @@ public class WebServiceOutboundGatewayWithHeaderMapperTests {
public Object unmarshal(Source source) throws IOException, XmlMappingException {
Element documentElement = (Element) ((DOMSource) source).getNode();
String name = DomUtils.getChildElementValueByTagName(documentElement, "name");
Person person = new Person();
person.setName(name);
return person;
}
}
private String extractStringResult(Message<?> replyMessage) throws Exception{
Transformer transformer = TransformerFactory.newInstance().newTransformer();
StringResult result = new StringResult();
Object payload = replyMessage.getPayload();
if (payload instanceof DOMSource){
transformer.transform(((DOMSource)replyMessage.getPayload()), result);
transformer.transform(((DOMSource)replyMessage.getPayload()), result);
}
else if (payload instanceof Document){
transformer.transform(new DOMSource((Document)replyMessage.getPayload()), result);
transformer.transform(new DOMSource((Document)replyMessage.getPayload()), result);
}
else {
throw new IllegalArgumentException("Unsupported payload type: " + payload.getClass().getName());