Fix failing tests according new changes in SF SpEL module
Related to: https://github.com/spring-projects/spring-framework/issues/33174
This commit is contained in:
@@ -500,7 +500,7 @@ public class MethodInvokingMessageProcessorTests {
|
||||
Method method = service.getClass().getMethod("optionalAndRequiredHeader", String.class, Integer.class);
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
processor.setUseSpelInvoker(true);
|
||||
optionalAndRequiredWithAnnotatedMethodGuts(processor, false);
|
||||
optionalAndRequiredWithAnnotatedMethodGuts(processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -510,14 +510,13 @@ public class MethodInvokingMessageProcessorTests {
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
processor.setUseSpelInvoker(true);
|
||||
DirectFieldAccessor compilerConfigAccessor = compileImmediate(processor);
|
||||
optionalAndRequiredWithAnnotatedMethodGuts(processor, true);
|
||||
optionalAndRequiredWithAnnotatedMethodGuts(processor);
|
||||
assertThat(TestUtils.getPropertyValue(processor, "delegate.handlerMethod.expression.compiledAst")).isNotNull();
|
||||
optionalAndRequiredWithAnnotatedMethodGuts(processor, true);
|
||||
optionalAndRequiredWithAnnotatedMethodGuts(processor);
|
||||
compilerConfigAccessor.setPropertyValue("compilerMode", SpelCompilerMode.OFF);
|
||||
}
|
||||
|
||||
private void optionalAndRequiredWithAnnotatedMethodGuts(MethodInvokingMessageProcessor processor,
|
||||
boolean compiled) {
|
||||
private void optionalAndRequiredWithAnnotatedMethodGuts(MethodInvokingMessageProcessor processor) {
|
||||
|
||||
processor.setBeanFactory(mock(BeanFactory.class));
|
||||
Message<String> message = MessageBuilder.withPayload("foo")
|
||||
@@ -531,21 +530,14 @@ public class MethodInvokingMessageProcessorTests {
|
||||
.build();
|
||||
result = processor.processMessage(message);
|
||||
assertThat(result).isEqualTo("bar42");
|
||||
message = MessageBuilder.withPayload("foo")
|
||||
.setHeader("prop", "bar")
|
||||
.build();
|
||||
try {
|
||||
result = processor.processMessage(message);
|
||||
fail("Expected MessageHandlingException");
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
if (compiled) {
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("required header not available: num");
|
||||
}
|
||||
else {
|
||||
assertThat(e.getCause().getCause().getMessage()).isEqualTo("required header not available: num");
|
||||
}
|
||||
}
|
||||
|
||||
assertThatExceptionOfType(MessageHandlingException.class)
|
||||
.isThrownBy(() ->
|
||||
processor.processMessage(
|
||||
MessageBuilder.withPayload("foo")
|
||||
.setHeader("prop", "bar")
|
||||
.build()))
|
||||
.withStackTraceContaining("required header not available: num");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -555,7 +547,7 @@ public class MethodInvokingMessageProcessorTests {
|
||||
String.class);
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
processor.setUseSpelInvoker(true);
|
||||
optionalAndRequiredDottedWithAnnotatedMethodGuts(processor, false);
|
||||
optionalAndRequiredDottedWithAnnotatedMethodGuts(processor);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -566,14 +558,13 @@ public class MethodInvokingMessageProcessorTests {
|
||||
MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
|
||||
processor.setUseSpelInvoker(true);
|
||||
DirectFieldAccessor compilerConfigAccessor = compileImmediate(processor);
|
||||
optionalAndRequiredDottedWithAnnotatedMethodGuts(processor, true);
|
||||
optionalAndRequiredDottedWithAnnotatedMethodGuts(processor);
|
||||
assertThat(TestUtils.getPropertyValue(processor, "delegate.handlerMethod.expression.compiledAst")).isNotNull();
|
||||
optionalAndRequiredDottedWithAnnotatedMethodGuts(processor, true);
|
||||
optionalAndRequiredDottedWithAnnotatedMethodGuts(processor);
|
||||
compilerConfigAccessor.setPropertyValue("compilerMode", SpelCompilerMode.OFF);
|
||||
}
|
||||
|
||||
private void optionalAndRequiredDottedWithAnnotatedMethodGuts(MethodInvokingMessageProcessor processor,
|
||||
boolean compiled) {
|
||||
private void optionalAndRequiredDottedWithAnnotatedMethodGuts(MethodInvokingMessageProcessor processor) {
|
||||
|
||||
processor.setBeanFactory(mock(BeanFactory.class));
|
||||
Message<String> message = MessageBuilder.withPayload("hello")
|
||||
@@ -589,22 +580,15 @@ public class MethodInvokingMessageProcessorTests {
|
||||
.build();
|
||||
result = processor.processMessage(message);
|
||||
assertThat(result).isEqualTo("bar42dotted");
|
||||
message = MessageBuilder.withPayload("hello")
|
||||
.setHeader("dot1", new DotBean())
|
||||
.setHeader("dotted.literal", "dotted")
|
||||
.build();
|
||||
try {
|
||||
result = processor.processMessage(message);
|
||||
fail("Expected MessageHandlingException");
|
||||
}
|
||||
catch (MessageHandlingException e) {
|
||||
if (compiled) {
|
||||
assertThat(e.getCause().getMessage()).isEqualTo("required header not available: dot2");
|
||||
}
|
||||
else { // interpreted
|
||||
assertThat(e.getCause().getCause().getMessage()).isEqualTo("required header not available: dot2");
|
||||
}
|
||||
}
|
||||
|
||||
assertThatExceptionOfType(MessageHandlingException.class)
|
||||
.isThrownBy(() ->
|
||||
processor.processMessage(
|
||||
MessageBuilder.withPayload("hello")
|
||||
.setHeader("dot1", new DotBean())
|
||||
.setHeader("dotted.literal", "dotted")
|
||||
.build()))
|
||||
.withStackTraceContaining("required header not available: dot2");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -25,9 +25,8 @@ import com.jayway.jsonpath.Criteria;
|
||||
import com.jayway.jsonpath.Filter;
|
||||
import com.jayway.jsonpath.PathNotFoundException;
|
||||
import com.jayway.jsonpath.Predicate;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -39,18 +38,17 @@ import org.springframework.integration.annotation.ServiceActivator;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.config.EnableIntegration;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.transformer.MessageTransformationException;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageChannel;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
import org.springframework.messaging.PollableChannel;
|
||||
import org.springframework.messaging.handler.annotation.Payload;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.fail;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
@@ -58,9 +56,7 @@ import static org.assertj.core.api.Assertions.fail;
|
||||
*
|
||||
* @since 3.0
|
||||
*/
|
||||
@ContextConfiguration(classes = JsonPathTests.JsonPathTestsContextConfiguration.class,
|
||||
loader = AnnotationConfigContextLoader.class)
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringJUnitConfig(classes = JsonPathTests.JsonPathTestsContextConfiguration.class)
|
||||
public class JsonPathTests {
|
||||
|
||||
private static File JSON_FILE;
|
||||
@@ -69,7 +65,7 @@ public class JsonPathTests {
|
||||
|
||||
private static Message<String> testMessage;
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setUp() throws IOException {
|
||||
ClassPathResource jsonResource = new ClassPathResource("JsonPathTests.json", JsonPathTests.class);
|
||||
JSON_FILE = jsonResource.getFile();
|
||||
@@ -116,7 +112,7 @@ public class JsonPathTests {
|
||||
private PollableChannel routerOutput2;
|
||||
|
||||
@Test
|
||||
public void testInt3139JsonPathTransformer() throws IOException {
|
||||
public void testInt3139JsonPathTransformer() {
|
||||
this.transformerInput.send(testMessage);
|
||||
Message<?> receive = this.output.receive(10000);
|
||||
assertThat(receive).isNotNull();
|
||||
@@ -127,20 +123,14 @@ public class JsonPathTests {
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload()).isEqualTo("Nigel Rees");
|
||||
|
||||
this.transformerInput.send(new GenericMessage<File>(JSON_FILE));
|
||||
this.transformerInput.send(new GenericMessage<>(JSON_FILE));
|
||||
receive = this.output.receive(1000);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
assertThat(receive.getPayload()).isEqualTo("Nigel Rees");
|
||||
try {
|
||||
this.transformerInput.send(new GenericMessage<Object>(new Object()));
|
||||
fail("IllegalArgumentException expected");
|
||||
}
|
||||
catch (Exception e) {
|
||||
//MessageTransformationException / MessageHandlingException / InvocationTargetException / IllegalArgumentException
|
||||
Throwable cause = e.getCause().getCause().getCause();
|
||||
assertThat(cause instanceof PathNotFoundException).isTrue();
|
||||
}
|
||||
assertThatExceptionOfType(MessageTransformationException.class)
|
||||
.isThrownBy(() -> this.transformerInput.send(new GenericMessage<>(new Object())))
|
||||
.withRootCauseInstanceOf(PathNotFoundException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,13 +155,9 @@ public class JsonPathTests {
|
||||
receive = this.output.receive(10000);
|
||||
assertThat(receive).isNotNull();
|
||||
|
||||
try {
|
||||
this.filterInput1.send(new GenericMessage<String>("{foo:{}}"));
|
||||
fail("MessageRejectedException is expected.");
|
||||
}
|
||||
catch (Exception e) {
|
||||
assertThat(e).isInstanceOf(MessageRejectedException.class);
|
||||
}
|
||||
assertThatExceptionOfType(MessageRejectedException.class)
|
||||
.isThrownBy(() -> this.filterInput1.send(new GenericMessage<>("{foo:{}}")));
|
||||
|
||||
receive = this.output.receive(0);
|
||||
assertThat(receive).isNull();
|
||||
|
||||
@@ -186,7 +172,7 @@ public class JsonPathTests {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Message<?> receive = this.splitterOutput.receive(10000);
|
||||
assertThat(receive).isNotNull();
|
||||
assertThat(receive.getPayload() instanceof Map).isTrue();
|
||||
assertThat(receive.getPayload()).isInstanceOf(Map.class);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user