wmedvede commented on code in PR #1991: URL: https://github.com/apache/incubator-kie-kogito-apps/pull/1991#discussion_r1492712548
########## data-index/data-index-common/src/test/java/org/kie/kogito/index/json/JsonUtilsTest.java: ########## @@ -0,0 +1,48 @@ +/* + * 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.kie.kogito.index.json; + +import org.junit.jupiter.api.Test; +import org.kie.kogito.jackson.utils.ObjectMapperFactory; + +import com.fasterxml.jackson.databind.node.ObjectNode; + +import static org.assertj.core.api.Assertions.assertThat; + +public class JsonUtilsTest { + + @Test + void testMergeWithDot() { + ObjectNode expected = ObjectMapperFactory.get().createObjectNode().set("Javier", ObjectMapperFactory.get().createObjectNode().put("ito", "manolo")); + assertThat(JsonUtils.mergeVariable("Javier.ito", "manolo", null)).isEqualTo(expected); + } + + @Test + void testSimpleMerge() { + ObjectNode expected = ObjectMapperFactory.get().createObjectNode().put("Javierito", "manolo"); + assertThat(JsonUtils.mergeVariable("Javierito", "manolo", null)).isEqualTo(expected); + } + + @Test + void testComplexMergeWithDot() { + ObjectNode expected = ObjectMapperFactory.get().createObjectNode().set("Javier", ObjectMapperFactory.get().createObjectNode().put("ito", "manolo").put("ato", "pepe")); Review Comment: your call, but I believe using more standard names, "bob", "alice", "user1", "user2" are more follow-able. ########## data-index/data-index-common/src/main/java/org/kie/kogito/index/json/JsonUtils.java: ########## @@ -50,4 +54,20 @@ public static ObjectMapper configure(ObjectMapper objectMapper) { objectMapper.registerModule(module); return objectMapper; } + + public static ObjectNode mergeVariable(String variableName, Object variableValue, ObjectNode variables) { + return (ObjectNode) MergeUtils.merge(getObjectNode(variableName, variableValue), variables); + } + + private static ObjectNode getObjectNode(String variableName, Object variableValue) { Review Comment: Sorry for being picky, but i believe this method name with "get" is a bit confusing, Id prefer a name like createVariableNode, or something similar. -- 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] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
