diff --git a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java index 6ae85adcdd3..caf8ed3c46e 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/history/MessageHistory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.List; import java.util.ListIterator; +import java.util.Objects; import java.util.Properties; import java.util.stream.Collectors; @@ -42,6 +43,8 @@ import org.springframework.messaging.support.GenericMessage; import org.springframework.util.Assert; +import com.fasterxml.jackson.annotation.JsonCreator; + /** * @author Mark Fisher * @author Artem Bilan @@ -133,7 +136,7 @@ else if (message instanceof AdviceMessage) { return message; } - + @JsonCreator private MessageHistory(List components) { Assert.notEmpty(components, "component list must not be empty"); this.components = components; @@ -205,6 +208,21 @@ public int lastIndexOf(Object o) { return this.components.lastIndexOf(o); } + @Override public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof MessageHistory)) { + return false; + } + MessageHistory that = (MessageHistory) o; + return this.components.equals(that.components); + } + + @Override public int hashCode() { + return Objects.hash(this.components); + } + @Override public String toString() { return this.components diff --git a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java index 61d936327b5..10120a46a10 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/support/json/JacksonJsonUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 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. @@ -158,7 +158,8 @@ private static final class AllowlistTypeIdResolver implements TypeIdResolver { "org.springframework.messaging.support", "org.springframework.integration.support", "org.springframework.integration.message", - "org.springframework.integration.store" + "org.springframework.integration.store", + "org.springframework.integration.history" ); private final TypeIdResolver delegate; diff --git a/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/RedisMessageGroupStoreTests.java b/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/RedisMessageGroupStoreTests.java index 5b67c17c748..e403dc8d649 100644 --- a/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/RedisMessageGroupStoreTests.java +++ b/spring-integration-redis/src/test/java/org/springframework/integration/redis/store/RedisMessageGroupStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2019 the original author or authors. + * Copyright 2007-2021 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,6 +40,7 @@ import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer; import org.springframework.integration.channel.DirectChannel; +import org.springframework.integration.channel.NullChannel; import org.springframework.integration.channel.QueueChannel; import org.springframework.integration.history.MessageHistory; import org.springframework.integration.message.AdviceMessage; @@ -143,7 +144,7 @@ public void testRemoveMessageGroup() { store.removeMessageGroup(this.groupId); MessageGroup messageGroupA = store.getMessageGroup(this.groupId); assertThat(messageGroupA).isNotSameAs(messageGroup); -// assertEquals(0, messageGroupA.getMarked().size()); + // assertEquals(0, messageGroupA.getMarked().size()); assertThat(messageGroupA.getMessages().size()).isEqualTo(0); assertThat(messageGroupA.size()).isEqualTo(0); @@ -438,6 +439,9 @@ public void testJsonSerialization() { store.setValueSerializer(serializer); Message genericMessage = new GenericMessage<>(new Date()); + NullChannel testComponent = new NullChannel(); + testComponent.setBeanName("testChannel"); + genericMessage = MessageHistory.write(genericMessage, testComponent); Message mutableMessage = new MutableMessage<>(UUID.randomUUID()); Message adviceMessage = new AdviceMessage<>("foo", genericMessage); ErrorMessage errorMessage = new ErrorMessage(new RuntimeException("test exception"), mutableMessage); @@ -448,6 +452,7 @@ public void testJsonSerialization() { assertThat(messageGroup.size()).isEqualTo(4); List> messages = new ArrayList<>(messageGroup.getMessages()); assertThat(messages.get(0)).isEqualTo(genericMessage); + assertThat(messages.get(0).getHeaders()).containsKeys(MessageHistory.HEADER_NAME); assertThat(messages.get(1)).isEqualTo(mutableMessage); assertThat(messages.get(2)).isEqualTo(adviceMessage); Message errorMessageResult = messages.get(3);