Mercurial > stress-tester
changeset 934:2d014d618480
JsonConfigurationReaderTest.testRead_EmptyString
author | Devel 2 |
---|---|
date | Mon, 07 May 2018 14:36:16 +0200 |
parents | 55590bb0e482 |
children | 53ff4d2e0abc |
files | stress-tester/src/main/java/com/passus/st/config/JsonConfigurationReader.java stress-tester/src/main/java/com/passus/st/utils/JsonUtils.java stress-tester/src/test/java/com/passus/st/config/JsonConfigurationReaderTest.java |
diffstat | 3 files changed, 23 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/config/JsonConfigurationReader.java Mon May 07 14:35:42 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/config/JsonConfigurationReader.java Mon May 07 14:36:16 2018 +0200 @@ -1,5 +1,6 @@ package com.passus.st.config; +import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.node.ArrayNode; @@ -33,6 +34,7 @@ private CCompositeNode readRootNode() throws IOException, NodeException { ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_READING_DUP_TREE_KEY, false); JsonNode jNode = mapper.readTree(reader); if (jNode == null) {
--- a/stress-tester/src/main/java/com/passus/st/utils/JsonUtils.java Mon May 07 14:35:42 2018 +0200 +++ b/stress-tester/src/main/java/com/passus/st/utils/JsonUtils.java Mon May 07 14:36:16 2018 +0200 @@ -84,9 +84,7 @@ } public static NodeException nodeException(String message, JsonNode node) { - //node. - //Mark mark = node.getStartMark(); - return new NodeException(message, 0, 0); + return new NodeException(message); } public static String escape(String value) {
--- a/stress-tester/src/test/java/com/passus/st/config/JsonConfigurationReaderTest.java Mon May 07 14:35:42 2018 +0200 +++ b/stress-tester/src/test/java/com/passus/st/config/JsonConfigurationReaderTest.java Mon May 07 14:36:16 2018 +0200 @@ -5,6 +5,7 @@ import java.util.List; +import static com.passus.config.ConfigurationUtils.extractString; import static com.passus.st.config.ConfigurationTestUtils.SIMPLE_CONFIG; import static com.passus.st.config.ConfigurationTestUtils.SIMPLE_CONFIG_NODE; import static org.testng.AssertJUnit.assertEquals; @@ -49,6 +50,25 @@ } @Test + public void testRead_DuplicatedKeys() throws Exception { + String config = "{" + + "\"key\": \"value1\"," + + "\"key\": \"value2\"" + + "}"; + + JsonConfigurationReader reader = new JsonConfigurationReader(config); + Configuration cfg = reader.read(); + + CMapNode rootNode = (CMapNode) cfg.getRootNode(); + List<CTupleNode> children = rootNode.getChildren(); + assertEquals(1, children.size()); + + CTupleNode tuple = children.get(0); + assertEquals("key", tuple.getName()); + assertEquals("value2", extractString(tuple.getNode())); + } + + @Test public void testRead_EmptyString() throws Exception { JsonConfigurationReader reader = new JsonConfigurationReader(""); Configuration cfg = reader.read();