INT-1082: Add tests for header expressions
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
package org.springframework.integration.http;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -25,8 +26,8 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.handler.ExpressionEvaluatingMessageProcessor;
|
||||
import org.springframework.mock.web.MockHttpServletRequest;
|
||||
import org.springframework.util.FileCopyUtils;
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
@@ -111,4 +112,16 @@ public class DefaultInboundRequestMapperTests {
|
||||
tmpFile.deleteOnExit();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMessageWithDollar() throws Exception {
|
||||
MockHttpServletRequest request = new MockHttpServletRequest();
|
||||
request.setContentType("text");
|
||||
request.setCharacterEncoding("utf-8");
|
||||
byte[] bytes = SIMPLE_STRING.getBytes("utf-8");
|
||||
request.setContent(bytes);
|
||||
Message<String> message = (Message<String>) mapper.toMessage(request);
|
||||
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor("headers['$http_requestUrl']");
|
||||
assertEquals(message.getHeaders().get(HttpHeaders.REQUEST_URL), processor.processMessage(message));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,6 @@ import org.easymock.IAnswer;
|
||||
import org.easymock.classextension.ConstructorArgs;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.core.MessageHeaders;
|
||||
|
||||
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.internal.matchers.TypeSafeMatcher;
|
||||
@@ -44,6 +45,21 @@ public class ExpressionEvaluatingMessageProcessorTests {
|
||||
assertEquals("foo", processor.processMessage(new StringMessage("foo")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMessageWithDollar() {
|
||||
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor("headers['$id']");
|
||||
StringMessage message = new StringMessage("foo");
|
||||
assertEquals(message.getHeaders().getId(), processor.processMessage(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore // This doesn't work because the context root for the expression evaluated as the map key is the headers (seems like a bug)
|
||||
public void testProcessMessageWithStaticKey() {
|
||||
ExpressionEvaluatingMessageProcessor processor = new ExpressionEvaluatingMessageProcessor("headers[T(org.springframework.integration.core.MessageHeaders).ID]");
|
||||
StringMessage message = new StringMessage("foo");
|
||||
assertEquals(message.getHeaders().getId(), processor.processMessage(message));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProcessMessageBadExpression() {
|
||||
expected.expect(new TypeSafeMatcher<Exception>(Exception.class) {
|
||||
|
||||
Reference in New Issue
Block a user