gnodet-bot commented on code in PR #26626: URL: https://github.com/apache/camel/pull/26626#discussion_r4056788503
########## core/camel-core/src/test/java/org/apache/camel/processor/MessageHistoryBodyTypeAndSizeTest.java: ########## @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.camel.processor; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.camel.ContextTestSupport; +import org.apache.camel.Exchange; +import org.apache.camel.MessageHistory; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.support.MessageHelper; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + +/** + * The message history carries the body's type and size as each node was reached (CAMEL-24844): what a person or a model + * needs to see where the body changed from text into a Map or bytes, on every message and without the tracer. + */ +public class MessageHistoryBodyTypeAndSizeTest extends ContextTestSupport { + + @Test + public void testBodyTypeAndSizePerStep() throws Exception { + getMockEndpoint("mock:result").expectedMessageCount(1); + + Exchange out = template.request("direct:start", e -> e.getMessage().setBody("Hello World")); + assertMockEndpointsSatisfied(); + + List<MessageHistory> history = out.getProperty(Exchange.MESSAGE_HISTORY, List.class); + assertNotNull(history); + assertEquals(4, history.size()); + + // as each step was reached: the text sent, the bytes the first step made, the list the second step made + assertEquals("a", history.get(0).getNode().getId()); + assertEquals("java.lang.String", history.get(0).getBodyType()); + assertEquals(11, history.get(0).getBodySize()); + + assertEquals("b", history.get(1).getNode().getId()); + assertEquals("byte[]", history.get(1).getBodyType()); + assertEquals(11, history.get(1).getBodySize()); + + assertEquals("c", history.get(2).getNode().getId()); + assertEquals("java.util.ArrayList", history.get(2).getBodyType()); + assertEquals(3, history.get(2).getBodySize(), "the size strategy counts the elements of a collection"); + + // a null body is shown as such, not left blank like a body that was not captured Review Comment: **Missing: disabled-strategy path.** The test only covers `MessageSizeStrategy` enabled. Add a second test (or parameterize) verifying that when the strategy is disabled, `getBodyType()` is still populated but `getBodySize()` returns `-1` for every step. That is the default for non-dev profiles and the most common production path. ```suggestion assertEquals(11, history.get(0).getBodySize()); assertEquals("b", history.get(1).getNode().getId()); assertEquals("byte[]", history.get(1).getBodyType()); assertEquals(11, history.get(1).getBodySize()); assertEquals("c", history.get(2).getNode().getId()); assertEquals("java.util.ArrayList", history.get(2).getBodyType()); assertEquals(3, history.get(2).getBodySize(), "the size strategy counts the elements of a collection"); // a null body is shown as such, not left blank like a body that was not captured assertEquals("d", history.get(3).getNode().getId()); assertEquals("null", history.get(3).getBodyType()); assertEquals(0, history.get(3).getBodySize()); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
