Moved scripting support from core to scripting
spring-integration-test: Enhanced RequestResponseScenario test framework changed scripting namespace URIs to standard pattern
This commit is contained in:
committed by
Mark Fisher
parent
b6294fc602
commit
08f81ae51d
@@ -63,13 +63,11 @@ public abstract class AbstractRequestResponseScenarioTest {
|
||||
if (outputChannel instanceof PollableChannel){
|
||||
Message<?> response = ((PollableChannel) outputChannel).receive(10000);
|
||||
assertNotNull(name + ": receive timeout on " + scenario.getOutputChannelName(),response);
|
||||
|
||||
if (scenario.getResponseValidator() instanceof PayloadValidator){
|
||||
scenario.getResponseValidator().validateResponse(response.getPayload());
|
||||
} else {
|
||||
scenario.getResponseValidator().validateResponse(response);
|
||||
}
|
||||
scenario.getResponseValidator().handleMessage(response);
|
||||
}
|
||||
|
||||
assertNotNull("message was not handled on " + outputChannel + " for scenario '" + scenario.getName() + "'.",
|
||||
scenario.getResponseValidator().getLastMessage());
|
||||
}
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -8,20 +8,33 @@ import org.springframework.integration.core.MessageHandler;
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractResponseValidator implements MessageHandler {
|
||||
|
||||
public abstract class AbstractResponseValidator<T> implements MessageHandler {
|
||||
|
||||
private Message<?> lastMessage;
|
||||
/**
|
||||
* handle the message
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
//@Override
|
||||
public void handleMessage(Message<?> message) throws MessagingException {
|
||||
validateResponse(extractPayload()? message.getPayload(): message );
|
||||
this.lastMessage = message;
|
||||
validateResponse((T) (extractPayload()? message.getPayload(): message ));
|
||||
}
|
||||
/**
|
||||
* Implement this method to validate the response (Message or Payload)
|
||||
* @param response
|
||||
*/
|
||||
protected abstract void validateResponse(Object response);
|
||||
protected abstract void validateResponse(T response);
|
||||
/**
|
||||
* If true will extract the payload as the parameter for validateResponse()
|
||||
* @return true to extract the payload; false to process the message.
|
||||
*/
|
||||
protected abstract boolean extractPayload();
|
||||
/**
|
||||
* @return the lastMessage
|
||||
*/
|
||||
public Message<?> getLastMessage() {
|
||||
return lastMessage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,12 +7,12 @@ import org.springframework.integration.Message;
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public abstract class MessageValidator extends AbstractResponseValidator {
|
||||
public abstract class MessageValidator extends AbstractResponseValidator<Message<?>> {
|
||||
protected final boolean extractPayload(){
|
||||
return false;
|
||||
}
|
||||
|
||||
protected final void validateResponse(Object response){
|
||||
protected final void validateResponse(Message<?> response){
|
||||
validateMessage((Message<?>) response);
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ package org.springframework.integration.test.support;
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
public abstract class PayloadValidator extends AbstractResponseValidator {
|
||||
public abstract class PayloadValidator<T> extends AbstractResponseValidator<T> {
|
||||
protected final boolean extractPayload(){
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ public class RequestResponseScenario {
|
||||
private final String outputChannelName;
|
||||
private Object payload;
|
||||
private Message<?> message;
|
||||
private AbstractResponseValidator responseValidator;
|
||||
private AbstractResponseValidator<?> responseValidator;
|
||||
private String name;
|
||||
|
||||
protected Message<? extends Object> getMessage(){
|
||||
@@ -91,7 +91,7 @@ public class RequestResponseScenario {
|
||||
* @return the response validator
|
||||
* @see AbstractResponseValidator
|
||||
*/
|
||||
public AbstractResponseValidator getResponseValidator(){
|
||||
public AbstractResponseValidator<?> getResponseValidator(){
|
||||
return responseValidator;
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ public class RequestResponseScenario {
|
||||
* @param responseValidator
|
||||
* @return
|
||||
*/
|
||||
public RequestResponseScenario setResponseValidator(AbstractResponseValidator responseValidator) {
|
||||
public RequestResponseScenario setResponseValidator(AbstractResponseValidator<?> responseValidator) {
|
||||
this.responseValidator = responseValidator;
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2002-2011 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.support;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Convenience class for a single {@link RequestResponsScenario} test
|
||||
* @author David Turanski
|
||||
*
|
||||
*/
|
||||
|
||||
public abstract class SingleRequestResponseScenarioTest extends AbstractRequestResponseScenarioTest {
|
||||
|
||||
@Override
|
||||
protected List<RequestResponseScenario> defineRequestResponseScenarios() {
|
||||
return Collections.singletonList(defineRequestResponseScenario());
|
||||
}
|
||||
|
||||
protected abstract RequestResponseScenario defineRequestResponseScenario();
|
||||
}
|
||||
@@ -21,9 +21,9 @@ public class MessageScenariosTest extends AbstractRequestResponseScenarioTest {
|
||||
RequestResponseScenario scenario1 = new RequestResponseScenario(
|
||||
"inputChannel","outputChannel")
|
||||
.setPayload("hello")
|
||||
.setResponseValidator(new PayloadValidator() {
|
||||
.setResponseValidator(new PayloadValidator<String>() {
|
||||
@Override
|
||||
protected void validateResponse(Object response) {
|
||||
protected void validateResponse(String response) {
|
||||
assertEquals("HELLO",response);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package org.springframework.integration.test.support;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
@ContextConfiguration("MessageScenariosTest-context.xml")
|
||||
public class SingleScenarioTest extends SingleRequestResponseScenarioTest {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.integration.test.support.SingleRequestResponseScenarioTest#defineRequestResponseScenario()
|
||||
*/
|
||||
@Override
|
||||
protected RequestResponseScenario defineRequestResponseScenario() {
|
||||
RequestResponseScenario scenario = new RequestResponseScenario(
|
||||
"inputChannel","outputChannel")
|
||||
.setPayload("hello")
|
||||
.setResponseValidator(new PayloadValidator<String>() {
|
||||
@Override
|
||||
protected void validateResponse(String response) {
|
||||
assertEquals("HELLO",response);
|
||||
}
|
||||
});
|
||||
return scenario;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user