diff --git a/src/test/java/com/fasterxml/jackson/databind/node/MissingValues4229Test.java b/src/test/java/com/fasterxml/jackson/databind/node/MissingValues4229Test.java deleted file mode 100644 index 3b06d08230..0000000000 --- a/src/test/java/com/fasterxml/jackson/databind/node/MissingValues4229Test.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.fasterxml.jackson.databind.node; - -import java.util.ArrayList; -import java.util.List; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import static com.fasterxml.jackson.databind.BaseMapTest.jsonMapperBuilder; -import static com.fasterxml.jackson.databind.BaseTest.a2q; - -// [databind#4229] JsonNode findValues and findParents missing expected values -public class MissingValues4229Test -{ - - private final String JSON = a2q("{" - + " 'target': 'target1'," // Found in <= 2.15.3 and 2.16.0 - + " 'object1': {" - + " 'target': 'target2' " // Found in <= 2.15.3, but not in 2.16.0 - + " }," - + " 'object2': {" - + " 'target': { " // Found in <= 2.15.3, but not in 2.16.0 - + " 'target': 'ignoredAsParentIsTarget'" // Expect not to be found (as sub-tree search ends when parent is found) - + " }" - + " }" - + "}"); - - private final ObjectMapper objectMapper = jsonMapperBuilder() - .configure(JsonParser.Feature.ALLOW_COMMENTS, true) - .build(); - - @Test - public void testFindValues() throws Exception - { - JsonNode rootNode = objectMapper.readTree(JSON); - - List expectedNodes = new ArrayList<>(); - expectedNodes.add(rootNode.at("/target")); - expectedNodes.add(rootNode.at("/object1/target")); - expectedNodes.add(rootNode.at("/object2/target")); - - List actualNodes = rootNode.findValues("target"); - - Assertions.assertEquals(expectedNodes, actualNodes); - } - - @Test - public void testFindParents() throws Exception - { - JsonNode rootNode = objectMapper.readTree(JSON); - - List expectedNodes = new ArrayList<>(); - expectedNodes.add(rootNode.at("")); - expectedNodes.add(rootNode.at("/object1")); - expectedNodes.add(rootNode.at("/object2")); - - List foundNodes = rootNode.findParents("target"); - - Assertions.assertEquals(expectedNodes, foundNodes); - } -} diff --git a/src/test/java/com/fasterxml/jackson/databind/node/TestFindMethods.java b/src/test/java/com/fasterxml/jackson/databind/node/TestFindMethods.java index fcecb29063..020c11e7ab 100644 --- a/src/test/java/com/fasterxml/jackson/databind/node/TestFindMethods.java +++ b/src/test/java/com/fasterxml/jackson/databind/node/TestFindMethods.java @@ -4,13 +4,32 @@ import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; public class TestFindMethods extends BaseMapTest { + private final String JSON_SAMPLE = "{ \"a\" : { \"value\" : 3 }," + +"\"array\" : [ { \"b\" : 3 }, {\"value\" : 42}, { \"other\" : true } ]" + +"}"; + + private final String JSON_4229 = a2q("{" + + " 'target': 'target1'," // Found in <= 2.15.3 and 2.16.0 + + " 'object1': {" + + " 'target': 'target2' " // Found in <= 2.15.3, but not in 2.16.0 + + " }," + + " 'object2': {" + + " 'target': { " // Found in <= 2.15.3, but not in 2.16.0 + + " 'target': 'ignoredAsParentIsTarget'" // Expect not to be found (as sub-tree search ends when parent is found) + + " }" + + " }" + + "}"); + + private final ObjectMapper MAPPER = newJsonMapper(); + public void testNonMatching() throws Exception { - JsonNode root = _buildTree(); + JsonNode root = MAPPER.readTree(JSON_SAMPLE); assertNull(root.findValue("boogaboo")); assertNull(root.findParent("boogaboo")); @@ -24,7 +43,7 @@ public void testNonMatching() throws Exception public void testMatchingSingle() throws Exception { - JsonNode root = _buildTree(); + JsonNode root = MAPPER.readTree(JSON_SAMPLE); JsonNode node = root.findValue("b"); assertNotNull(node); @@ -38,7 +57,7 @@ public void testMatchingSingle() throws Exception public void testMatchingMultiple() throws Exception { - JsonNode root = _buildTree(); + JsonNode root = MAPPER.readTree(JSON_SAMPLE); List nodes = root.findValues("value"); assertEquals(2, nodes.size()); @@ -61,11 +80,25 @@ public void testMatchingMultiple() throws Exception assertEquals("42", values.get(1)); } - private JsonNode _buildTree() throws Exception + // [databind#4229]: regression in 2.16.0 + public void testFindValues4229() throws Exception { - final String SAMPLE = "{ \"a\" : { \"value\" : 3 }," - +"\"array\" : [ { \"b\" : 3 }, {\"value\" : 42}, { \"other\" : true } ]" - +"}"; - return objectMapper().readTree(SAMPLE); + JsonNode rootNode = MAPPER.readTree(JSON_4229); + assertEquals(Arrays.asList( + rootNode.at("/target"), + rootNode.at("/object1/target"), + rootNode.at("/object2/target")), + rootNode.findValues("target")); + } + + // [databind#4229]: regression in 2.16.0 + public void testFindParents4229() throws Exception + { + JsonNode rootNode = MAPPER.readTree(JSON_4229); + assertEquals(Arrays.asList( + rootNode, + rootNode.at("/object1"), + rootNode.at("/object2")), + rootNode.findParents("target")); } }