gemmellr commented on code in PR #5079: URL: https://github.com/apache/activemq-artemis/pull/5079#discussion_r1678160843
########## artemis-server/src/test/java/org/apache/activemq/artemis/core/config/DivertConfigurationEncodingTest.java: ########## @@ -0,0 +1,47 @@ +/* + * 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.activemq.artemis.core.config; + +import org.apache.activemq.artemis.api.core.ActiveMQBuffer; +import org.apache.activemq.artemis.api.core.ActiveMQBuffers; +import org.apache.activemq.artemis.core.server.ComponentConfigurationRoutingType; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class DivertConfigurationEncodingTest { + + @Test + public void testStoreDivertConfigurationWithTransformerNoProperties() { + DivertConfiguration configuration = new DivertConfiguration(); + configuration.setName("myDivertName"); + configuration.setAddress("myDivertAddress"); + configuration.setForwardingAddress("myDivertForwardingAddress"); + configuration.setFilterString("foo='foo'"); + configuration.setRoutingName("myDivertRoutingName"); + configuration.setExclusive(false); + configuration.setRoutingType(ComponentConfigurationRoutingType.ANYCAST); + TransformerConfiguration myDivertTransformer = new TransformerConfiguration("myDivertTransformer"); + myDivertTransformer.getProperties().put("foo", "foo"); + configuration.setTransformerConfiguration(myDivertTransformer); + + int encodeSize = configuration.getEncodeSize(); + ActiveMQBuffer data = ActiveMQBuffers.fixedBuffer(encodeSize); + configuration.encode(data); + assertEquals(encodeSize, data.writerIndex()); Review Comment: The new tests are better, but still dont really cover the original comment. The bug here was apparently that the value of getEncodeSize() was wrong. For a comprehensive encoder test I'd expect an assertion on the exact actual value for given inputs to check it is as expected, but there still isnt such an assertion. All the tests do is verify the number of bytes written equals that value returned, which it always should, but that doesnt actually check the value was correct to expectations. Similarly with the actual encoded bytes, they are not directly asserted, only indirectly verified by using the decoder. The new tests decode those output bytes, and assert the resulting components are as expected, which is certainly much better than before. However that also doesnt strictly check that they were encoded properly to begin with; the encoder and decoder could have compensating bugs and both be incorrect. Or the wrong methods could be used to encode a value giving it an unexpected (but perhaps decodable as equivalent) value in the buffer.. You also fixed such an issue in the encoder in the PR, though in this case it seems like it would just have caused an NPE. -- 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: gitbox-unsubscr...@activemq.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@activemq.apache.org For additional commands, e-mail: gitbox-h...@activemq.apache.org For further information, visit: https://activemq.apache.org/contact