diff options
author | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-12-01 11:48:20 -0800 |
---|---|---|
committer | Jessica Wagantall <jwagantall@linuxfoundation.org> | 2020-12-01 11:48:20 -0800 |
commit | 32fb53c13342d5ad353c839b7ffd0ca85d14bd48 (patch) | |
tree | f1b92068cf7b79d29e96243899e12495abb4795a /sliPluginUtils/provider/src/test/java/org | |
parent | 53eacd8519a535f96d8b4231e48925324f1086dd (diff) |
Migrate sli-core files
Migrate sli-core repo files into new
directory "core".
Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'sliPluginUtils/provider/src/test/java/org')
6 files changed, 0 insertions, 1659 deletions
diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java deleted file mode 100644 index 42e7ceb94..000000000 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_StaticFunctionsTest.java +++ /dev/null @@ -1,591 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.core.slipluginutils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.slipluginutils.SliPluginUtils.LogLevel; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import com.google.gson.JsonObject; - -public class SliPluginUtils_StaticFunctionsTest { - private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtils_StaticFunctionsTest.class); - SliPluginUtils utils = new SliPluginUtils(); - private SvcLogicContext ctx; - private HashMap<String, String> parameters; - - @Before - public void setUp() throws Exception { - this.ctx = new SvcLogicContext(); - parameters = new HashMap<String, String>(); - } - - // TODO: javadoc - @Test - public final void testCtxGetBeginsWith() { - ctx.setAttribute("service-data.oper-status.order-status", "InProgress"); - ctx.setAttribute("service-data.service-information.service-instance-id", "my-instance"); - ctx.setAttribute("service-data.service-information.service-type", "my-service"); - - Map<String, String> entries = SliPluginUtils.ctxGetBeginsWith(ctx, "service-data.service-information"); - - assertEquals("my-instance", entries.get("service-data.service-information.service-instance-id")); - assertEquals("my-service", entries.get("service-data.service-information.service-type")); - assertFalse(entries.containsKey("service-data.oper-status.order-status")); - } - - // TODO: javadoc - @Test - public final void testCtxListRemove_index() throws SvcLogicException { - LOG.trace("=== testCtxListRemove_index ==="); - ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2"); - ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2"); - ctx.setAttribute("service-data.vnf-l3_length", "3"); - - parameters.put("index", "1"); - parameters.put("list_pfx", "service-data.vnf-l3"); - - utils.ctxListRemove(parameters, ctx); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - assertEquals("2", ctx.getAttribute("service-data.vnf-l3_length")); - assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].vnf-host-name")); - assertEquals("device-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].device-host-name")); - assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].vnf-host-name")); - assertEquals("device-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].device-host-name")); - } - - // TODO: javadoc - @Test - public final void textCtxListRemove_keyValue() throws SvcLogicException { - LOG.trace("=== textCtxListRemove_keyValue ==="); - ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2"); - ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2"); - // 2nd entry - ctx.setAttribute("service-data.vnf-l3[3].vnf-host-name", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[3].device-host-name", "device-host-name_1"); - ctx.setAttribute("service-data.vnf-l3_length", "4"); - - parameters.put("list_pfx", "service-data.vnf-l3"); - parameters.put("key", "vnf-host-name"); - parameters.put("value", "vnf-host-name_1"); - - utils.ctxListRemove(parameters, ctx); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - assertEquals("2", ctx.getAttribute("service-data.vnf-l3_length")); - assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].vnf-host-name")); - assertEquals("device-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].device-host-name")); - assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].vnf-host-name")); - assertEquals("device-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].device-host-name")); - } - - // TODO: javadoc - @Test - public final void textCtxListRemove_keyValue_nullkey() throws SvcLogicException { - LOG.trace("=== textCtxListRemove_keyValue_nullkey ==="); - ctx.setAttribute("service-data.vnf-l3[0]", "vnf-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[1]", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[2]", "vnf-host-name_2"); - ctx.setAttribute("service-data.vnf-l3_length", "3"); - - parameters.put("list_pfx", "service-data.vnf-l3"); - parameters.put("value", "vnf-host-name_1"); - - utils.ctxListRemove(parameters, ctx); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - assertEquals("2", ctx.getAttribute("service-data.vnf-l3_length")); - assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0]")); - assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1]")); - } - - // TODO: javadoc - @Test - public final void textCtxListRemove_keyValueList() throws SvcLogicException { - LOG.trace("=== textCtxListRemove_keyValueList ==="); - ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2"); - ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2"); - // 2nd entry - ctx.setAttribute("service-data.vnf-l3[3].vnf-host-name", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[3].device-host-name", "device-host-name_1"); - // entries with only 1 of 2 key-value pairs matching - ctx.setAttribute("service-data.vnf-l3[4].vnf-host-name", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[4].device-host-name", "device-host-name_4"); - ctx.setAttribute("service-data.vnf-l3[5].vnf-host-name", "vnf-host-name_5"); - ctx.setAttribute("service-data.vnf-l3[5].device-host-name", "device-host-name_1"); - ctx.setAttribute("service-data.vnf-l3_length", "6"); - - parameters.put("list_pfx", "service-data.vnf-l3"); - parameters.put("keys_length", "2"); - parameters.put("keys[0].key", "vnf-host-name"); - parameters.put("keys[0].value", "vnf-host-name_1"); - parameters.put("keys[1].key", "device-host-name"); - parameters.put("keys[1].value", "device-host-name_1"); - - utils.ctxListRemove(parameters, ctx); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - assertEquals("4", ctx.getAttribute("service-data.vnf-l3_length")); - assertEquals("vnf-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].vnf-host-name")); - assertEquals("device-host-name_0", ctx.getAttribute("service-data.vnf-l3[0].device-host-name")); - assertEquals("vnf-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].vnf-host-name")); - assertEquals("device-host-name_2", ctx.getAttribute("service-data.vnf-l3[1].device-host-name")); - assertEquals("vnf-host-name_1", ctx.getAttribute("service-data.vnf-l3[2].vnf-host-name")); - assertEquals("device-host-name_4", ctx.getAttribute("service-data.vnf-l3[2].device-host-name")); - assertEquals("vnf-host-name_5", ctx.getAttribute("service-data.vnf-l3[3].vnf-host-name")); - assertEquals("device-host-name_1", ctx.getAttribute("service-data.vnf-l3[3].device-host-name")); - } - - // TODO: javadoc - @Test(expected = SvcLogicException.class) - public final void testCtxListRemove_nullListLength() throws SvcLogicException { - LOG.trace("=== testCtxListRemove_nullListLength ==="); - ctx.setAttribute("service-data.vnf-l3[0].vnf-host-name", "vnf-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[0].device-host-name", "device-host-name_0"); - ctx.setAttribute("service-data.vnf-l3[1].vnf-host-name", "vnf-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[1].device-host-name", "device-host-name_1"); - ctx.setAttribute("service-data.vnf-l3[2].vnf-host-name", "vnf-host-name_2"); - ctx.setAttribute("service-data.vnf-l3[2].device-host-name", "device-host-name_2"); - - parameters.put("index", "1"); - parameters.put("list_pfx", "service-data.vnf-l3"); - - utils.ctxListRemove(parameters, ctx); - } - - // TODO: javadoc - @Test - public final void testCtxPutAll() { - HashMap<String, Object> entries = new HashMap<String, Object>(); - entries.put("service-data.oper-status.order-status", "InProgress"); - entries.put("service-data.service-information.service-instance-id", "my-instance"); - entries.put("service-data.request-information.order-number", 1234); - entries.put("service-data.request-information.request-id", null); - - SliPluginUtils.ctxPutAll(ctx, entries); - - assertEquals("InProgress", ctx.getAttribute("service-data.oper-status.order-status")); - assertEquals("my-instance", ctx.getAttribute("service-data.service-information.service-instance-id")); - assertEquals("1234", ctx.getAttribute("service-data.request-information.order-number")); - assertFalse(ctx.getAttributeKeySet().contains("service-data.request-information.request-id")); - } - - // TODO: javadoc - @Test - public final void testCtxSetAttribute_LOG() { - LOG.debug("=== testCtxSetAttribute_LOG ==="); - Integer i = new Integer(3); - SliPluginUtils.ctxSetAttribute(ctx, "test", i, LOG, SliPluginUtils.LogLevel.TRACE); - } - - @Test - public void setTime() throws SvcLogicException { - String outputPath = "output"; - parameters.put("outputPath", outputPath); - SliPluginUtils.setTime(parameters, ctx); - assertNotNull(ctx.getAttribute(outputPath)); - } - - @Test - public void containsKey() throws Exception { - ctx = new SvcLogicContext(); - parameters.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); - String result = SliPluginUtils.containsKey(parameters, ctx); - assertEquals(SliStringUtils.FALSE_CONSTANT, result); - - ctx.setAttribute("a", null); - parameters.put(SliStringUtils.INPUT_PARAM_KEY, "a"); - result = SliPluginUtils.containsKey(parameters, ctx); - assertEquals(SliStringUtils.FALSE_CONSTANT, result); - - ctx.setAttribute("a", "hellworld"); - parameters.put(SliStringUtils.INPUT_PARAM_KEY, "a"); - result = SliPluginUtils.containsKey(parameters, ctx); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - } - - @Test - public void testGetAttributeValue() throws Exception { - parameters.put("outputPath", "testPath"); - parameters.put("source", "testSource"); - SliPluginUtils.getAttributeValue(parameters, ctx); - assertNull(ctx.getAttribute(parameters.get("outputPath"))); - } - - @Test - public void testCtxListContains() throws Exception { - parameters.put("list", "10_length"); - parameters.put("keyName", "testName"); - parameters.put("keyValue", "testValue"); - ctx.setAttribute("10_length", "10"); - assertEquals("false", SliPluginUtils.ctxListContains(parameters, ctx)); - - } - - @Test(expected = SvcLogicException.class) - public void testPrintContextForEmptyParameters() throws SvcLogicException { - SliPluginUtils.printContext(parameters, ctx); - } - - @Test(expected = SvcLogicException.class) - public void testPrintContextForNullParameters() throws SvcLogicException { - SliPluginUtils.printContext(null, ctx); - } - - @Test - public void testPrintContext() throws SvcLogicException { - parameters.put("filename", "testFileName"); - SliPluginUtils.printContext(parameters, ctx); - } - - @Test - public void testCtxKeyEmpty() { - ctx.setAttribute("key", ""); - assertTrue(SliPluginUtils.ctxKeyEmpty(ctx, "key")); - } - - @Test - public void testGetArrayLength() { - ctx.setAttribute("key_length", "test"); - Logger log = LoggerFactory.getLogger(getClass()); - SliPluginUtils.getArrayLength(ctx, "key", log, LogLevel.INFO, "invalid input"); - } - - @Test - public void testSetPropertiesForRoot() { - Map<String, String> parameters = new HashMap<>(); - parameters.put("root", "RootVal"); - parameters.put("valueRoot", "ValueRootVal"); - assertEquals(SvcLogicConstants.SUCCESS, SliPluginUtils.setPropertiesForRoot(parameters, ctx)); - } - - @Test - public void testJsonStringToCtxToplevelArray() throws Exception { - String path = "src/test/resources/ArrayMenu.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "false"); - parameters.put("source", "input"); - - SliPluginUtils.jsonStringToCtx(parameters, ctx); - - assertEquals("1000", ctx.getAttribute("testPath.[0].calories")); - assertEquals("1", ctx.getAttribute("testPath.[0].id")); - assertEquals("plain", ctx.getAttribute("testPath.[0].name")); - assertEquals("pizza", ctx.getAttribute("testPath.[0].type")); - assertEquals("true", ctx.getAttribute("testPath.[0].vegetarian")); - assertEquals(SliPluginUtils.CTX_NULL_VALUE, ctx.getAttribute("testPath.[1].calories")); - assertEquals("2", ctx.getAttribute("testPath.[1].id")); - assertEquals("Tuesday Special", ctx.getAttribute("testPath.[1].name")); - assertEquals("1", ctx.getAttribute("testPath.[1].topping[0].id")); - assertEquals("onion", ctx.getAttribute("testPath.[1].topping[0].name")); - assertEquals("2", ctx.getAttribute("testPath.[1].topping[1].id")); - assertEquals("pepperoni", ctx.getAttribute("testPath.[1].topping[1].name")); - assertEquals("2", ctx.getAttribute("testPath.[1].topping_length")); - assertEquals("pizza", ctx.getAttribute("testPath.[1].type")); - assertEquals("false", ctx.getAttribute("testPath.[1].vegetarian")); - assertEquals("1500", ctx.getAttribute("testPath.[2].calories")); - assertEquals("3", ctx.getAttribute("testPath.[2].id")); - assertEquals("House Special", ctx.getAttribute("testPath.[2].name")); - assertEquals("3", ctx.getAttribute("testPath.[2].topping[0].id")); - assertEquals("basil", ctx.getAttribute("testPath.[2].topping[0].name")); - assertEquals("4", ctx.getAttribute("testPath.[2].topping[1].id")); - assertEquals("fresh mozzarella", ctx.getAttribute("testPath.[2].topping[1].name")); - assertEquals("5", ctx.getAttribute("testPath.[2].topping[2].id")); - assertEquals("tomato", ctx.getAttribute("testPath.[2].topping[2].name")); - assertEquals("3", ctx.getAttribute("testPath.[2].topping_length")); - assertEquals("pizza", ctx.getAttribute("testPath.[2].type")); - assertEquals("true", ctx.getAttribute("testPath.[2].vegetarian")); - assertEquals("3", ctx.getAttribute("testPath._length")); - } - - @Test - public void testJsonStringToCtx() throws Exception { - String path = "src/test/resources/ObjectMenu.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "false"); - parameters.put("source", "input"); - - SliPluginUtils.jsonStringToCtx(parameters, ctx); - - - assertEquals("1000", ctx.getAttribute("testPath.menu[0].calories")); - assertEquals("1", ctx.getAttribute("testPath.menu[0].id")); - assertEquals("plain", ctx.getAttribute("testPath.menu[0].name")); - assertEquals("pizza", ctx.getAttribute("testPath.menu[0].type")); - assertEquals("true", ctx.getAttribute("testPath.menu[0].vegetarian")); - assertEquals("2000", ctx.getAttribute("testPath.menu[1].calories")); - assertEquals("2", ctx.getAttribute("testPath.menu[1].id")); - assertEquals("Tuesday Special", ctx.getAttribute("testPath.menu[1].name")); - assertEquals("1", ctx.getAttribute("testPath.menu[1].topping[0].id")); - assertEquals("onion", ctx.getAttribute("testPath.menu[1].topping[0].name")); - assertEquals("2", ctx.getAttribute("testPath.menu[1].topping[1].id")); - assertEquals("pepperoni", ctx.getAttribute("testPath.menu[1].topping[1].name")); - assertEquals("2", ctx.getAttribute("testPath.menu[1].topping_length")); - assertEquals("pizza", ctx.getAttribute("testPath.menu[1].type")); - assertEquals("false", ctx.getAttribute("testPath.menu[1].vegetarian")); - assertEquals("1500", ctx.getAttribute("testPath.menu[2].calories")); - assertEquals("3", ctx.getAttribute("testPath.menu[2].id")); - assertEquals("House Special", ctx.getAttribute("testPath.menu[2].name")); - assertEquals("3", ctx.getAttribute("testPath.menu[2].topping[0].id")); - assertEquals("basil", ctx.getAttribute("testPath.menu[2].topping[0].name")); - assertEquals("4", ctx.getAttribute("testPath.menu[2].topping[1].id")); - assertEquals("fresh mozzarella", ctx.getAttribute("testPath.menu[2].topping[1].name")); - assertEquals("5", ctx.getAttribute("testPath.menu[2].topping[2].id")); - assertEquals("tomato", ctx.getAttribute("testPath.menu[2].topping[2].name")); - assertEquals("3", ctx.getAttribute("testPath.menu[2].topping_length")); - assertEquals("pizza", ctx.getAttribute("testPath.menu[2].type")); - assertEquals("true", ctx.getAttribute("testPath.menu[2].vegetarian")); - assertEquals("3", ctx.getAttribute("testPath.menu_length")); - } - - @Test - public void test2dJsonStringToCtx() throws Exception { - String path = "src/test/resources/2dArray.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "false"); - parameters.put("source", "input"); - - SliPluginUtils.jsonStringToCtx(parameters, ctx); - assertEquals("apple", ctx.getAttribute("testPath.[0][0]")); - assertEquals("orange", ctx.getAttribute("testPath.[0][1]")); - assertEquals("banana", ctx.getAttribute("testPath.[0][2]")); - assertEquals(SliPluginUtils.CTX_NULL_VALUE, ctx.getAttribute("testPath.[0][3]")); - assertEquals("4", ctx.getAttribute("testPath.[0]_length")); - assertEquals("squash", ctx.getAttribute("testPath.[1][0]")); - assertEquals("broccoli", ctx.getAttribute("testPath.[1][1]")); - assertEquals("cauliflower", ctx.getAttribute("testPath.[1][2]")); - assertEquals("3", ctx.getAttribute("testPath.[1]_length")); - assertEquals("2", ctx.getAttribute("testPath._length")); - } - - @Test - public void test3dJsonStringToCtx() throws Exception { - String path = "src/test/resources/3dArray.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "false"); - parameters.put("source", "input"); - - SliPluginUtils.jsonStringToCtx(parameters, ctx); - assertEquals("a", ctx.getAttribute("testPath.[0][0][0]")); - assertEquals("b", ctx.getAttribute("testPath.[0][0][1]")); - assertEquals("c", ctx.getAttribute("testPath.[0][0][2]")); - assertEquals("3", ctx.getAttribute("testPath.[0][0]_length")); - assertEquals("d", ctx.getAttribute("testPath.[0][1][0]")); - assertEquals("e", ctx.getAttribute("testPath.[0][1][1]")); - assertEquals("f", ctx.getAttribute("testPath.[0][1][2]")); - assertEquals("3", ctx.getAttribute("testPath.[0][1]_length")); - assertEquals("2", ctx.getAttribute("testPath.[0]_length")); - assertEquals("x", ctx.getAttribute("testPath.[1][0][0]")); - assertEquals("y", ctx.getAttribute("testPath.[1][0][1]")); - assertEquals("z", ctx.getAttribute("testPath.[1][0][2]")); - assertEquals("3", ctx.getAttribute("testPath.[1][0]_length")); - assertEquals("1", ctx.getAttribute("testPath.[1]_length")); - assertEquals("2", ctx.getAttribute("testPath._length")); - } - - @Test - public void testJsonWidgetStringToCtx() throws Exception { - String path = "src/test/resources/Widget.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "false"); - parameters.put("source", "input"); - - SliPluginUtils.jsonStringToCtx(parameters, ctx); - assertEquals("false", ctx.getAttribute("testPath.widget.debug")); - assertEquals("center", ctx.getAttribute("testPath.widget.image.alignment")); - assertEquals("150", ctx.getAttribute("testPath.widget.image.hOffset")); - assertEquals("moon", ctx.getAttribute("testPath.widget.image.name")); - assertEquals("images/moon.png", ctx.getAttribute("testPath.widget.image.src")); - assertEquals("150", ctx.getAttribute("testPath.widget.image.vOffset")); - assertEquals("center", ctx.getAttribute("testPath.widget.text.alignment")); - assertEquals("Click Me", ctx.getAttribute("testPath.widget.text.data")); - assertEquals("350", ctx.getAttribute("testPath.widget.text.hOffset")); - assertEquals("text1", ctx.getAttribute("testPath.widget.text.name")); - assertEquals("21", ctx.getAttribute("testPath.widget.text.size")); - assertEquals("bold", ctx.getAttribute("testPath.widget.text.style")); - assertEquals(SliPluginUtils.CTX_NULL_VALUE, ctx.getAttribute("testPath.widget.text.vOffset")); - assertEquals("300", ctx.getAttribute("testPath.widget.window.height")); - assertEquals("main_window", ctx.getAttribute("testPath.widget.window.name")); - assertEquals("ONAP Widget", ctx.getAttribute("testPath.widget.window.title")); - assertEquals("200", ctx.getAttribute("testPath.widget.window.width")); - } - - @Test - public void testUpdateJsonObjectString() throws Exception { - String path = "src/test/resources/JsonObject.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - - Map<String, String> parametersUpdateJson = new HashMap<String, String>(); - parametersUpdateJson.put("source", "input"); - parametersUpdateJson.put("outputPath", "newJsonString"); - - // add key "ccc" and its value - parametersUpdateJson.put("add.ccc", "abcxyz"); - - // update keys and their values of "aaa" and "c.d" - parametersUpdateJson.put("add.aaa", "4567"); - parametersUpdateJson.put("add.c.d", "defg"); - - // delete key "bbb" - parametersUpdateJson.put("delete.bbb", ""); - - SliPluginUtils.updateJsonObjectString(parametersUpdateJson, ctx); - - Map<String, String> parametersJsonToCtx = new HashMap<String, String>(); - parametersJsonToCtx.put("source", "newJsonString"); - parametersJsonToCtx.put("outputPath", "testPath"); - parametersJsonToCtx.put("isEscaped", "false"); - - SliPluginUtils.jsonStringToCtx(parametersJsonToCtx, ctx); - - assertEquals("abcxyz", ctx.getAttribute("testPath.ccc")); - assertEquals("4567", ctx.getAttribute("testPath.aaa")); - assertEquals("defg", ctx.getAttribute("testPath.c.d")); - assertEquals(null, ctx.getAttribute("testPath.bbb")); - } - - @Test - public void testEmbeddedEscapedJsonJsonStringToCtx() throws Exception { - String path = "src/test/resources/EmbeddedEscapedJson.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "false"); - parameters.put("source", "input"); - - SliPluginUtils.jsonStringToCtx(parameters, ctx); - - assertEquals("escapedJsonObject", ctx.getAttribute("testPath.input.parameters[0].name")); - assertEquals("[{\"id\":\"0.2.0.0/16\"},{\"id\":\"ge04::/64\"}]", - ctx.getAttribute("testPath.input.parameters[0].value")); - assertEquals("Hello/World", ctx.getAttribute("testPath.input.parameters[1].value")); - assertEquals("resourceName", ctx.getAttribute("testPath.input.parameters[2].name")); - assertEquals("The\t\"Best\"\tName", ctx.getAttribute("testPath.input.parameters[2].value")); - assertEquals("3", ctx.getAttribute("testPath.input.parameters_length")); - - - // Break the embedded json object into properties - parameters.put("outputPath", "testPath.input.parameters[0].value"); - parameters.put("source", "testPath.input.parameters[0].value"); - SliPluginUtils.jsonStringToCtx(parameters, ctx); - - assertEquals("0.2.0.0/16", ctx.getAttribute("testPath.input.parameters[0].value.[0].id")); - assertEquals("ge04::/64", ctx.getAttribute("testPath.input.parameters[0].value.[1].id")); - assertEquals("2", ctx.getAttribute("testPath.input.parameters[0].value._length")); - } - - @Test - public void testEscapedJsonStringToCtx() throws Exception { - String path = "src/test/resources/EscapedJson.json"; - String content = new String(Files.readAllBytes(Paths.get(path))); - - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("input", content); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("outputPath", "testPath"); - parameters.put("isEscaped", "true"); // set to true because the entire json content has been escaped - parameters.put("source", "input"); - - - SliPluginUtils.jsonStringToCtx(parameters, ctx); - assertEquals("false", ctx.getAttribute("testPath.widget.debug")); - assertEquals("center", ctx.getAttribute("testPath.widget.image.alignment")); - assertEquals("150", ctx.getAttribute("testPath.widget.image.hOffset")); - assertEquals("moon", ctx.getAttribute("testPath.widget.image.name")); - assertEquals("images/moon.png", ctx.getAttribute("testPath.widget.image.src")); - assertEquals("150", ctx.getAttribute("testPath.widget.image.vOffset")); - assertEquals("center", ctx.getAttribute("testPath.widget.text.alignment")); - assertEquals("Click Me", ctx.getAttribute("testPath.widget.text.data")); - assertEquals("350", ctx.getAttribute("testPath.widget.text.hOffset")); - assertEquals("text1", ctx.getAttribute("testPath.widget.text.name")); - assertEquals("21", ctx.getAttribute("testPath.widget.text.size")); - assertEquals("bold", ctx.getAttribute("testPath.widget.text.style")); - assertEquals("200", ctx.getAttribute("testPath.widget.text.vOffset")); - assertEquals("300", ctx.getAttribute("testPath.widget.window.height")); - assertEquals("main_window", ctx.getAttribute("testPath.widget.window.name")); - assertEquals("ONAP Widget", ctx.getAttribute("testPath.widget.window.title")); - assertEquals("200", ctx.getAttribute("testPath.widget.window.width")); - } - -} diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_checkParametersTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_checkParametersTest.java deleted file mode 100644 index f92271f7c..000000000 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_checkParametersTest.java +++ /dev/null @@ -1,117 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (C) 2018 IBM. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.core.slipluginutils; - -import java.util.HashMap; -import java.util.Map; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SliPluginUtils_checkParametersTest { - - @Test - public void nullRequiredParameters() throws Exception { - Map<String, String> parametersMap = new HashMap<String, String>(); - String[] requiredParams = null; - Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); - SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); - } - - @Test(expected = SvcLogicException.class) - public void emptyParametersMap() throws Exception { - Map<String, String> parametersMap = new HashMap<String, String>(); - String[] requiredParams = new String[] { "param1", "param2", "param3" }; - Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); - SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); - } - - @Test(expected = SvcLogicException.class) - public void paramNotFound() throws Exception { - Map<String, String> parametersMap = new HashMap<String, String>(); - parametersMap.put("tst", "me"); - String[] requiredParams = new String[] { "param1", "parm2", "param3" }; - Logger Log = LoggerFactory.getLogger(SliPluginUtils.class); - SliPluginUtils.checkParameters(parametersMap, requiredParams, Log); - } - - @Test - public void testSunnyRequiredParameters() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("param1", "hello"); - ctx.setAttribute("param2", "world"); - ctx.setAttribute("param3", "!"); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("param1", "dog"); - parameters.put("param2", "cat"); - parameters.put("param3", "fish"); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test - public void testSunnyRequiredParametersWithPrefix() throws Exception { - String prefixValue = "my.unique.path."; - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute(prefixValue + "param1", "hello"); - ctx.setAttribute(prefixValue + "param2", "world"); - ctx.setAttribute(prefixValue + "param3", "!"); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("prefix", prefixValue); - parameters.put("param1", "dog"); - parameters.put("param2", "cat"); - parameters.put("param3", "fish"); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test(expected = SvcLogicException.class) - public void testRainyMissingRequiredParameters() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("param1", "hello"); - ctx.setAttribute("param3", "!"); - - Map<String, String> parameters = new HashMap<String, String>(); - parameters.put("param1", null); - parameters.put("param2", null); - parameters.put("param3", null); - - SliPluginUtils.requiredParameters(parameters, ctx); - } - - @Test(expected = SvcLogicException.class) - public void testEmptyRequiredParameters() throws Exception { - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("param1", "hello"); - ctx.setAttribute("param3", "!"); - - Map<String, String> parameters = new HashMap<String, String>(); - - SliPluginUtils.requiredParameters(parameters, ctx); - } -} diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortList.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortList.java deleted file mode 100644 index 3d4469bf2..000000000 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortList.java +++ /dev/null @@ -1,149 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (C) 2018 IBM. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.core.slipluginutils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import java.util.HashMap; -import java.util.Random; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicConstants; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings("unused") -public class SliPluginUtils_ctxSortList { - private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtils_ctxSortList.class); - SliPluginUtils utils = new SliPluginUtils(); - SvcLogicContext ctx; - HashMap<String, String> parameters; - Random rand = new Random(); - - @Before - public void setUp() throws Exception { - this.ctx = new SvcLogicContext(); - this.parameters = new HashMap<String, String>(); - } - - @Test - public final void list_of_containers() throws SvcLogicException { - this.parameters.put("list", "input.list"); - this.parameters.put("sort-fields", "sort-key"); - this.parameters.put("delimiter", ","); - - ctx.setAttribute("input.list_length", "10"); - for (int i = 0; i < 10; i++) { - this.ctx.setAttribute("input.list[" + i + "].sort-key", Integer.toString(rand.nextInt(10))); - this.ctx.setAttribute("input.list[" + i + "].value", Integer.toString(rand.nextInt(10))); - } - - LOG.trace("BEFORE SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - utils.ctxSortList(this.parameters, this.ctx); - - LOG.trace("AFTER SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - for (int i = 0; i < 9; i++) { - assertTrue(this.ctx.getAttribute("input.list[" + i + "].sort-key") - .compareTo(this.ctx.getAttribute("input.list[" + (i + 1) + "].sort-key")) < 1); - } - } - - @Test - public final void list_of_elements() throws SvcLogicException { - this.parameters.put("list", "input.list"); - this.parameters.put("delimiter", ","); - - this.ctx.setAttribute("input.list_length", "10"); - for (int i = 0; i < 10; i++) { - this.ctx.setAttribute("input.list[" + i + ']', Integer.toString(rand.nextInt(10))); - } - - LOG.trace("BEFORE SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - utils.ctxSortList(this.parameters, this.ctx); - - LOG.trace("AFTER SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - for (int i = 0; i < 9; i++) { - assertTrue(this.ctx.getAttribute("input.list[" + i + ']') - .compareTo(this.ctx.getAttribute("input.list[" + (i + 1) + ']')) < 1); - } - } - - @Test - public void testGenerateUUID() throws SvcLogicException { - SliPluginUtils utils = new SliPluginUtils(); - this.parameters.put("ctx-destination", "testDestination"); - utils.generateUUID(this.parameters, ctx); - } - - @Test - public void testSubstring() throws SvcLogicException { - SliPluginUtils utils = new SliPluginUtils(); - this.parameters.put("string", "testString"); - this.parameters.put("begin-index", "1"); - this.parameters.put("result", "testResult"); - this.parameters.put("end-index", "5"); - utils.substring(this.parameters, ctx); - assertEquals("estS", ctx.getAttribute("testResult")); - } - - @Test - public void testSubstringForNullEndIndex() throws SvcLogicException { - SliPluginUtils utils = new SliPluginUtils(); - this.parameters.put("string", "testString"); - this.parameters.put("begin-index", "1"); - this.parameters.put("result", "testResult"); - utils.substring(this.parameters, ctx); - assertEquals("estString", ctx.getAttribute("testResult")); - } - - @Test - public void testCtxBulkCopy() { - ctx.setAttribute("Mykey1", "MyValue1"); - ctx.setAttribute("Mykey2", "MyValue2"); - SliPluginUtils.ctxBulkCopy(ctx, "Mykey", "test."); - assertEquals("MyValue1", ctx.getAttribute("test.1")); - assertEquals("MyValue2", ctx.getAttribute("test.2")); - } - - @Test - public void testSetPropertiesForList() { - parameters.put("prefixKey", "testPrefixKey"); - parameters.put("valuePrefixKey", "testPrefixValue"); - parameters.put("keyName", "testKey"); - parameters.put("keyValue", "testValue"); - - assertEquals(SvcLogicConstants.SUCCESS, SliPluginUtils.setPropertiesForList(parameters, ctx)); - - } -} diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortListTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortListTest.java deleted file mode 100644 index bf7cc1399..000000000 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliPluginUtils_ctxSortListTest.java +++ /dev/null @@ -1,97 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.core.slipluginutils; - -import static org.junit.Assert.assertTrue; - -import java.util.HashMap; -import java.util.Random; - -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@SuppressWarnings("unused") -public class SliPluginUtils_ctxSortListTest { - private static final Logger LOG = LoggerFactory.getLogger(SliPluginUtils_ctxSortListTest.class); - SliPluginUtils utils = new SliPluginUtils(); - SvcLogicContext ctx; - HashMap<String, String> parameters; - Random rand = new Random(); - - @Before - public void setUp() throws Exception { - this.ctx = new SvcLogicContext(); - this.parameters = new HashMap<String, String>(); - } - - @Test - public final void list_of_containers() throws SvcLogicException { - this.parameters.put("list", "input.list"); - this.parameters.put("sort-fields", "sort-key"); - this.parameters.put("delimiter", ","); - - ctx.setAttribute("input.list_length", "10"); - for (int i = 0; i < 10; i++) { - this.ctx.setAttribute("input.list[" + i + "].sort-key", Integer.toString(rand.nextInt(10))); - this.ctx.setAttribute("input.list[" + i + "].value", Integer.toString(rand.nextInt(10))); - } - - LOG.trace("BEFORE SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - utils.ctxSortList(this.parameters, this.ctx); - - LOG.trace("AFTER SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - for (int i = 0; i < 9; i++) { - assertTrue(this.ctx.getAttribute("input.list[" + i + "].sort-key").compareTo(this.ctx.getAttribute("input.list[" + (i + 1) + "].sort-key")) < 1); - } - } - - @Test - public final void list_of_elements() throws SvcLogicException { - this.parameters.put("list", "input.list"); - this.parameters.put("delimiter", ","); - - this.ctx.setAttribute("input.list_length", "10"); - for (int i = 0; i < 10; i++) { - this.ctx.setAttribute("input.list[" + i + ']', Integer.toString(rand.nextInt(10))); - } - - LOG.trace("BEFORE SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - utils.ctxSortList(this.parameters, this.ctx); - - LOG.trace("AFTER SORT:"); - SliPluginUtils.logContextMemory(ctx, LOG, SliPluginUtils.LogLevel.TRACE); - - for (int i = 0; i < 9; i++) { - assertTrue(this.ctx.getAttribute("input.list[" + i + ']').compareTo(this.ctx.getAttribute("input.list[" + (i + 1) + ']')) < 1); - } - } -} diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java deleted file mode 100644 index da7046f43..000000000 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SliStringUtilsTest.java +++ /dev/null @@ -1,398 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Modifications Copyright (C) 2018 IBM. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.core.slipluginutils; - -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import java.util.HashMap; -import java.util.Map; -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; - -/** - * @author km991u - * - */ -public class SliStringUtilsTest { - private SvcLogicContext ctx; - private HashMap<String, String> param; - private SliStringUtils stringUtils = new SliStringUtils(); - - /** - * @throws java.lang.Exception - */ - @Before - public void setUp() throws Exception { - this.ctx = new SvcLogicContext(); - param = new HashMap<String, String>(); - } - - /** - * @throws SvcLogicException - * @see SliStringUtils#split(Map, SvcLogicContext) - */ - @Test - public final void testSplit() throws SvcLogicException { - param.put("original_string", "one ## two ## three"); - param.put("regex", " ## "); - param.put("ctx_memory_result_key", "result"); - - stringUtils.split(param, ctx); - - assertThat(ctx.getAttribute("result[0]"), equalTo("one")); - assertThat(ctx.getAttribute("result[1]"), equalTo("two")); - assertThat(ctx.getAttribute("result[2]"), equalTo("three")); - assertThat(ctx.getAttribute("result_length"), equalTo("3")); - } - - /** - * @throws SvcLogicException - * @see SliStringUtils#split(Map, SvcLogicContext) - */ - @Test - public final void testSplit_limit() throws SvcLogicException { - param.put("original_string", "one ## two ## three"); - param.put("regex", " ## "); - param.put("limit", "2"); - param.put("ctx_memory_result_key", "result"); - - stringUtils.split(param, ctx); - - assertThat(ctx.getAttribute("result[0]"), equalTo("one")); - assertThat(ctx.getAttribute("result[1]"), equalTo("two ## three")); - assertThat(ctx.getAttribute("result_length"), equalTo("2")); - } - - @Test - public final void testSubString() throws SvcLogicException { - param.put("string", "splitatgivenindex"); - param.put("begin-index", "0"); - param.put("end-index", "5"); - param.put("result", "result"); - - stringUtils.substring(param, ctx); - - assertEquals("split", ctx.getAttribute("result")); - } - - @Test - public final void testQuotedOrNull() throws SvcLogicException { - // param.put("nullString",null); - assertEquals("NULL", SliStringUtils.quotedOrNULL(null)); - } - - @Test - public void equalsIgnoreCaseTrue() throws SvcLogicException { - String sourceString = "HeLlOwORLD"; - String targetSTring = "HELLOWORLD"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("true", SliStringUtils.equalsIgnoreCase(param, ctx)); - } - - @Test - public void equalsIgnoreCaseFalse() throws SvcLogicException { - String sourceString = "HeLlOwORLD"; - String targetSTring = "goodbyeWORLD"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("false", SliStringUtils.equalsIgnoreCase(param, ctx)); - } - - @Test - public void toUpper() throws SvcLogicException { - String sourceString = "HeLlOwORLD"; - param.put("source", sourceString); - String path = "my.unique.path."; - param.put("outputPath", path); - SliStringUtils.toUpper(param, ctx); - assertEquals(sourceString.toUpperCase(), ctx.getAttribute(path)); - } - - @Test - public void toLower() throws SvcLogicException { - String sourceString = "HeLlOwORLD"; - param.put("source", sourceString); - String path = "my.unique.path."; - param.put("outputPath", path); - SliStringUtils.toLower(param, ctx); - assertEquals(sourceString.toLowerCase(), ctx.getAttribute(path)); - } - - @Test - public void containsTrue() throws SvcLogicException { - String sourceString = "Pizza"; - String targetSTring = "izza"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("true", SliStringUtils.contains(param, ctx)); - } - - @Test - public void containsFalse() throws SvcLogicException { - String sourceString = "Pizza"; - String targetSTring = "muffin"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("false", SliStringUtils.contains(param, ctx)); - } - - @Test - public void endsWithTrue() throws SvcLogicException { - String sourceString = "Pizza"; - String targetSTring = "za"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("true", SliStringUtils.endsWith(param, ctx)); - } - - @Test - public void endsWithFalse() throws SvcLogicException { - String sourceString = "Pizza"; - String targetSTring = "muffin"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("false", SliStringUtils.endsWith(param, ctx)); - } - - @Test - public void trim() throws SvcLogicException { - String sourceString = " H E L L O W O R L D"; - String outputPath = "muffin"; - param.put("source", sourceString); - param.put("outputPath", outputPath); - SliStringUtils.trim(param, ctx); - assertEquals(sourceString.trim(), ctx.getAttribute(outputPath)); - } - - @Test - public void getLength() throws SvcLogicException { - String sourceString = "SomeRandomString"; - String outputPath = "muffin"; - param.put("source", sourceString); - param.put("outputPath", outputPath); - SliStringUtils.getLength(param, ctx); - assertEquals(String.valueOf(sourceString.length()), ctx.getAttribute(outputPath)); - } - - @Test - public void startsWithFalse() throws SvcLogicException { - String sourceString = "Java"; - String targetSTring = "DG"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("false", SliStringUtils.startsWith(param, ctx)); - } - - @Test - public void startsWithTrue() throws SvcLogicException { - String sourceString = "Java"; - String targetSTring = "Ja"; - param.put("source", sourceString); - param.put("target", targetSTring); - assertEquals("true", SliStringUtils.startsWith(param, ctx)); - } - - @Test - public void replace() throws SvcLogicException { - String sourceString = "cat Hello World cat"; - String old = "cat"; - String neww = "dog"; - String outputPath = "out"; - - param.put("source", sourceString); - param.put("target", old); - param.put("replacement", neww); - param.put("outputPath", outputPath); - SliStringUtils.replace(param, ctx); - assertEquals(sourceString.replace(old, neww), ctx.getAttribute(outputPath)); - } - - @Test - public void replaceAll() throws SvcLogicException { - String source = "cat Hello World cat"; - String target = "\\s"; - String replacement = ""; - String outputPath = "out"; - - param.put("source", source); - param.put("target", target); - param.put("replacement", replacement); - param.put("outputPath", outputPath); - SliStringUtils.replaceAll(param, ctx); - assertEquals(source.replaceAll(target, replacement), ctx.getAttribute(outputPath)); - } - - @Test - public void concat() throws SvcLogicException { - String sourceString = "cat"; - String targetString = "dog"; - String outputPath = "out"; - - param.put("source", sourceString); - param.put("target", targetString); - param.put("outputPath", outputPath); - SliStringUtils.concat(param, ctx); - assertEquals(sourceString + targetString, ctx.getAttribute(outputPath)); - } - - @Test - public void urlEncode() throws SvcLogicException { - String sourceString = "102/GE100/SNJSCAMCJP8/SNJSCAMCJT4"; - String outputPath = "out"; - - param.put("source", sourceString); - param.put("outputPath", outputPath); - SliStringUtils.urlEncode(param, ctx); - assertEquals("102%2FGE100%2FSNJSCAMCJP8%2FSNJSCAMCJT4", ctx.getAttribute(outputPath)); - } - - @Test - public void urlDecode() throws SvcLogicException { - String sourceString = "102%2FGE100%2FSNJSCAMCJP8%2FSNJSCAMCJT4"; - String outputPath = "out"; - - param.put("source", sourceString); - param.put("outputPath", outputPath); - SliStringUtils.urlDecode(param, ctx); - assertEquals("102/GE100/SNJSCAMCJP8/SNJSCAMCJT4", ctx.getAttribute(outputPath)); - } - - @Test - public void testXmlEscapeText() { - param.put("source", "102/GE100/SNJSCAMCJP8/SNJSCAMCJT4"); - param.put("target", "target"); - SliStringUtils.xmlEscapeText(param, ctx); - assertEquals("102/GE100/SNJSCAMCJP8/SNJSCAMCJT4", ctx.getAttribute("target")); - } - - @Test(expected = Exception.class) - public void testSplitForEmptyParams() throws Exception { - SliStringUtils utils = new SliStringUtils(); - ctx = new SvcLogicContext(); - param = new HashMap<>(); - utils.split(param, ctx); - } - - @Test(expected = Exception.class) - public void testSubstringForEmptyParams() throws Exception { - SliStringUtils utils = new SliStringUtils(); - ctx = new SvcLogicContext(); - param = new HashMap<>(); - utils.substring(param, ctx); - } - - @Test - public void testUnescapeJsonString() throws Exception { - String source = "{\\\"image_name\\\":\\\"Ubuntu 14.04\\\",\\\"service-instance-id\\\":\\\"1\\\",\\\"vnf-model-customization-uuid\\\":\\\"2f\\\",\\\"vnf-id\\\":\\\"3b\\\"}"; - param.put(SliStringUtils.INPUT_PARAM_SOURCE, source); - String outputPath = "unescaped"; - param.put(SliStringUtils.INPUT_PARAM_TARGET, outputPath); - SliStringUtils.unescapeJsonString(param, ctx); - assertEquals("{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}", ctx.getAttribute(outputPath)); - } - - @Test - public void testEscapeJsonString() throws Exception { - String source = "{\"image_name\":\"Ubuntu 14.04\",\"service-instance-id\":\"1\",\"vnf-model-customization-uuid\":\"2f\",\"vnf-id\":\"3b\"}"; - param.put(SliStringUtils.INPUT_PARAM_SOURCE, source); - String outputPath = "unescaped"; - param.put(SliStringUtils.INPUT_PARAM_TARGET, outputPath); - SliStringUtils.escapeJsonString(param, ctx); - assertEquals("{\\\"image_name\\\":\\\"Ubuntu 14.04\\\",\\\"service-instance-id\\\":\\\"1\\\",\\\"vnf-model-customization-uuid\\\":\\\"2f\\\",\\\"vnf-id\\\":\\\"3b\\\"}", ctx.getAttribute(outputPath)); - } - - @Test - public void isEmpty() throws Exception { - String result = SliStringUtils.isEmpty(param, ctx); - param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", null); - param.put(SliStringUtils.INPUT_PARAM_KEY, "a"); - result = SliStringUtils.isEmpty(param, ctx); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", ""); - result = SliStringUtils.isEmpty(param, ctx); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", " "); - result = SliStringUtils.isEmpty(param, ctx); - assertEquals(SliStringUtils.FALSE_CONSTANT, result); - } - - @Test - public void isBlank() throws Exception { - String result = SliStringUtils.isBlank(param, ctx); - param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", null); - param.put(SliStringUtils.INPUT_PARAM_KEY, "a"); - result = SliStringUtils.isBlank(param, ctx); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", ""); - result = SliStringUtils.isBlank(param, ctx); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", " "); - result = SliStringUtils.isBlank(param, ctx); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - } - - @Test - public void isNull() throws Exception { - String result = SliStringUtils.isNull(param, ctx); - param.put(SliStringUtils.INPUT_PARAM_KEY, "key_does_not_exist"); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", null); - param.put(SliStringUtils.INPUT_PARAM_KEY, "a"); - result = SliStringUtils.isNull(param, ctx); - assertEquals(SliStringUtils.TRUE_CONSTANT, result); - - ctx.setAttribute("a", ""); - result = SliStringUtils.isNull(param, ctx); - assertEquals(SliStringUtils.FALSE_CONSTANT, result); - - ctx.setAttribute("a", " "); - result = SliStringUtils.isNull(param, ctx); - assertEquals(SliStringUtils.FALSE_CONSTANT, result); - } - - @Test - public void testBase64DecodingAlgo() throws Exception{ - String input = "MDUxMDAw"; - String decodeVal = "decodedPath"; - param.put("encodedValue",input); - param.put("decodedValue", decodeVal); - SliStringUtils.base64DecodingAlgo(param,ctx); - assertEquals("051000",ctx.getAttribute(decodeVal)); - } -} diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextListTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextListTest.java deleted file mode 100644 index f916bbfca..000000000 --- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/SvcLogicContextListTest.java +++ /dev/null @@ -1,307 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : CCSDK - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights - * reserved. - * ================================================================================ - * Licensed 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.ccsdk.sli.core.slipluginutils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; - -import java.util.HashMap; - -import org.junit.Before; -import org.junit.Test; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; - -public class SvcLogicContextListTest { - //private static final Logger LOG = LoggerFactory.getLogger(SvcLogicContextTest.class); - private SvcLogicContext ctx; - - @Before - public void setUp() throws Exception { - this.ctx = new SvcLogicContext(); - } - - // TODO: javadoc - @Test - public final void testSvcLogicContextList_SingleValueList() { - ctx.setAttribute("list[0]", "0"); - ctx.setAttribute("list[1]", "1"); - ctx.setAttribute("list[2]", "2"); - ctx.setAttribute("list[3]", "3"); - ctx.setAttribute("list[4]", "4"); - ctx.setAttribute("list_length", "5"); - - SvcLogicContextList list = new SvcLogicContextList( ctx, "list" ); - - // Check that size of list is 5 - assertEquals(5, list.size()); - - // Check that each HashMap has it's list value in the empty string key - // and has no other values - assertEquals(1, list.get(0).size()); - assertEquals("0", list.get(0).get("")); - assertEquals(1, list.get(1).size()); - assertEquals("1", list.get(1).get("")); - assertEquals(1, list.get(2).size()); - assertEquals("2", list.get(2).get("")); - assertEquals(1, list.get(3).size()); - assertEquals("3", list.get(3).get("")); - assertEquals(1, list.get(4).size()); - assertEquals("4", list.get(4).get("")); - } - - // TODO: javadoc - @Test - public final void testSvcLogicContextList_ObjectList() { - ctx.setAttribute("list[0].ipv4", "1.1.1.0"); - ctx.setAttribute("list[0].ipv6", "2001::0"); - ctx.setAttribute("list[1].ipv4", "1.1.1.1"); - ctx.setAttribute("list[1].ipv6", "2001::1"); - ctx.setAttribute("list[2].ipv4", "1.1.1.2"); - ctx.setAttribute("list[2].ipv6", "2001::2"); - ctx.setAttribute("list[3].ipv4", "1.1.1.3"); - ctx.setAttribute("list[3].ipv6", "2001::3"); - ctx.setAttribute("list[4].ipv4", "1.1.1.4"); - ctx.setAttribute("list[4].ipv6", "2001::4"); - ctx.setAttribute("list_length", "5"); - - SvcLogicContextList list = new SvcLogicContextList( ctx, "list" ); - - // Check that size of list is 5 - assertEquals(5, list.size()); - - assertEquals(2, list.get(0).size()); - assertEquals("1.1.1.0", list.get(0).get("ipv4")); - assertEquals("2001::0", list.get(0).get("ipv6")); - assertEquals(2, list.get(1).size()); - assertEquals("1.1.1.1", list.get(1).get("ipv4")); - assertEquals("2001::1", list.get(1).get("ipv6")); - assertEquals(2, list.get(2).size()); - assertEquals("1.1.1.2", list.get(2).get("ipv4")); - assertEquals("2001::2", list.get(2).get("ipv6")); - assertEquals(2, list.get(3).size()); - assertEquals("1.1.1.3", list.get(3).get("ipv4")); - assertEquals("2001::3", list.get(3).get("ipv6")); - assertEquals(2, list.get(4).size()); - assertEquals("1.1.1.4", list.get(4).get("ipv4")); - assertEquals("2001::4", list.get(4).get("ipv6")); - } - - // TODO: javadoc - @Test - public final void testExtract() { - ctx.setAttribute("list[0]", "0"); - ctx.setAttribute("list[1]", "1"); - ctx.setAttribute("list[2]", "2"); - ctx.setAttribute("list[3]", "3"); - ctx.setAttribute("list[4]", "4"); - ctx.setAttribute("list_length", "5"); - ctx.setAttribute("Other", "other"); - - SvcLogicContextList list = SvcLogicContextList.extract(ctx, "list"); - - // Check that size of list is 5 - assertEquals(5, list.size()); - - // Check that all list values exist in list object - assertEquals(1, list.get(0).size()); - assertEquals("0", list.get(0).get("")); - assertEquals(1, list.get(1).size()); - assertEquals("1", list.get(1).get("")); - assertEquals(1, list.get(2).size()); - assertEquals("2", list.get(2).get("")); - assertEquals(1, list.get(3).size()); - assertEquals("3", list.get(3).get("")); - assertEquals(1, list.get(4).size()); - assertEquals("4", list.get(4).get("")); - - // Check that all list values no longer exist in ctx - assertNull(ctx.getAttribute("list[0]")); - assertNull(ctx.getAttribute("list[1]")); - assertNull(ctx.getAttribute("list[2]")); - assertNull(ctx.getAttribute("list[3]")); - assertNull(ctx.getAttribute("list[4]")); - assertNull(ctx.getAttribute("list_length")); - - // Check that non-list values still exist in ctx - assertEquals("other", ctx.getAttribute("Other")); - } - - // TODO: javadoc - @Test - public final void testRemove_int() { - ctx.setAttribute("list[0]", "0"); - ctx.setAttribute("list[1]", "1"); - ctx.setAttribute("list[2]", "2"); - ctx.setAttribute("list[3]", "3"); - ctx.setAttribute("list[4]", "4"); - ctx.setAttribute("list_length", "5"); - - SvcLogicContextList list = new SvcLogicContextList( ctx, "list" ); - list.remove(2); - - // Check that size of list is 4 (1 less than original) - assertEquals(4, list.size()); - - // Check that value was remove from list - assertEquals(1, list.get(0).size()); - assertEquals("0", list.get(0).get("")); - assertEquals(1, list.get(1).size()); - assertEquals("1", list.get(1).get("")); - assertEquals(1, list.get(2).size()); - assertEquals("3", list.get(2).get("")); - assertEquals(1, list.get(3).size()); - assertEquals("4", list.get(3).get("")); - } - - // TODO: javadoc - @Test - public final void testRemove_StringString() { - ctx.setAttribute("list[0].ipv4", "1.1.1.0"); - ctx.setAttribute("list[0].ipv6", "2001::0"); - ctx.setAttribute("list[1].ipv4", "1.1.1.1"); - ctx.setAttribute("list[1].ipv6", "2001::1"); - ctx.setAttribute("list[2].ipv4", "1.1.1.2"); - ctx.setAttribute("list[2].ipv6", "2001::2"); - ctx.setAttribute("list[3].ipv4", "1.1.1.3"); - ctx.setAttribute("list[3].ipv6", "2001::3"); - ctx.setAttribute("list[4].ipv4", "1.1.1.4"); - ctx.setAttribute("list[4].ipv6", "2001::4"); - ctx.setAttribute("list[5].ipv4", "1.1.1.2"); - ctx.setAttribute("list[5].ipv6", "2001::2"); - ctx.setAttribute("list_length", "6"); - - SvcLogicContextList list = new SvcLogicContextList( ctx, "list" ); - list.remove("ipv4", "1.1.1.2"); - - // Check that size of list is 4 (2 less than original) - assertEquals(4, list.size()); - - // Check that all elements with values ending in 2 were removed - assertEquals("1.1.1.0", list.get(0).get("ipv4")); - assertEquals("2001::0", list.get(0).get("ipv6")); - assertEquals("1.1.1.1", list.get(1).get("ipv4")); - assertEquals("2001::1", list.get(1).get("ipv6")); - assertEquals("1.1.1.3", list.get(2).get("ipv4")); - assertEquals("2001::3", list.get(2).get("ipv6")); - assertEquals("1.1.1.4", list.get(3).get("ipv4")); - assertEquals("2001::4", list.get(3).get("ipv6")); - } - - // TODO: javadoc - @Test - public final void testRemove_StringString_ValueList() { - ctx.setAttribute("list[0]", "5"); - ctx.setAttribute("list[1]", "6"); - ctx.setAttribute("list[2]", "7"); - ctx.setAttribute("list[3]", "8"); - ctx.setAttribute("list[4]", "9"); - ctx.setAttribute("list_length", "5"); - - SvcLogicContextList list = new SvcLogicContextList( ctx, "list" ); - list.remove("", "6"); - - // Check that size of list is 4 (1 less than original) - assertEquals(4, list.size()); - - // Check that value was remove from list - assertEquals(1, list.get(0).size()); - assertEquals("5", list.get(0).get("")); - assertEquals(1, list.get(1).size()); - assertEquals("7", list.get(1).get("")); - assertEquals(1, list.get(2).size()); - assertEquals("8", list.get(2).get("")); - assertEquals(1, list.get(3).size()); - assertEquals("9", list.get(3).get("")); - } - - // TODO: javadoc - @Test - public final void testRemove_Map() { - ctx.setAttribute("list[0].ipv4", "1.1.1.0"); - ctx.setAttribute("list[0].ipv6", "2001::0"); - ctx.setAttribute("list[1].ipv4", "1.1.1.1"); - ctx.setAttribute("list[1].ipv6", "2001::1"); - ctx.setAttribute("list[2].ipv4", "1.1.1.2"); - ctx.setAttribute("list[2].ipv6", "2001::2"); - ctx.setAttribute("list[3].ipv4", "1.1.1.3"); - ctx.setAttribute("list[3].ipv6", "2001::3"); - ctx.setAttribute("list[4].ipv4", "1.1.1.4"); - ctx.setAttribute("list[4].ipv6", "2001::4"); - ctx.setAttribute("list[5].ipv4", "1.1.1.2"); - ctx.setAttribute("list[5].ipv6", "2001::2"); - ctx.setAttribute("list_length", "6"); - - HashMap<String,String> remove_key = new HashMap<String,String>(); - remove_key.put("ipv4", "1.1.1.2"); - remove_key.put("ipv6", "2001::2"); - - SvcLogicContextList list = new SvcLogicContextList( ctx, "list" ); - list.remove(remove_key); - - // Check that size of list is 4 (2 less than original) - assertEquals(4, list.size()); - - // Check that all elements with values ending in 2 were removed - assertEquals("1.1.1.0", list.get(0).get("ipv4")); - assertEquals("2001::0", list.get(0).get("ipv6")); - assertEquals("1.1.1.1", list.get(1).get("ipv4")); - assertEquals("2001::1", list.get(1).get("ipv6")); - assertEquals("1.1.1.3", list.get(2).get("ipv4")); - assertEquals("2001::3", list.get(2).get("ipv6")); - assertEquals("1.1.1.4", list.get(3).get("ipv4")); - assertEquals("2001::4", list.get(3).get("ipv6")); - } - - // TODO: javadoc - @Test - public final void testWriteToContext() { - ctx.setAttribute("list[0]", "0"); - ctx.setAttribute("list[1]", "1"); - ctx.setAttribute("list[2]", "2"); - ctx.setAttribute("list[3]", "3"); - ctx.setAttribute("list[4]", "4"); - ctx.setAttribute("list_length", "5"); - ctx.setAttribute("Other", "other"); - - SvcLogicContextList list = new SvcLogicContextList( ctx, "list" ); - - // Erase context memory - ctx = new SvcLogicContext(); - - // Write list back into context memory - list.writeToContext(ctx); - - // Check that size of list is 5 - assertEquals(5, list.size()); - - // Check that all list values exist in list object - assertEquals("0", ctx.getAttribute("list[0]")); - assertEquals("1", ctx.getAttribute("list[1]")); - assertEquals("2", ctx.getAttribute("list[2]")); - assertEquals("3", ctx.getAttribute("list[3]")); - assertEquals("4", ctx.getAttribute("list[4]")); - assertEquals("5", ctx.getAttribute("list_length")); - - // Check that old list values aren't in new list - assertNull(ctx.getAttribute("Other")); - } -} |