summaryrefslogtreecommitdiffstats
path: root/sliPluginUtils/provider/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'sliPluginUtils/provider/src/test/java')
-rw-r--r--sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/CheckParametersTest.java116
-rw-r--r--sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/Dme2Test.java109
-rw-r--r--sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_StaticFunctionsTest.java250
-rw-r--r--sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortList.java96
-rw-r--r--sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortListTest.java97
-rw-r--r--sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliStringUtilsTest.java244
-rw-r--r--sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SvcLogicContextListTest.java307
7 files changed, 1219 insertions, 0 deletions
diff --git a/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/CheckParametersTest.java b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/CheckParametersTest.java
new file mode 100644
index 000000000..318e4643e
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/CheckParametersTest.java
@@ -0,0 +1,116 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.openecomp.sdnc.sli.SliPluginUtils;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class 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/openecomp/sdnc/sli/SliPluginUtils/Dme2Test.java b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/Dme2Test.java
new file mode 100644
index 000000000..d66b01145
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/Dme2Test.java
@@ -0,0 +1,109 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.openecomp.sdnc.sli.SliPluginUtils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openecomp.sdnc.sli.SliPluginUtils.DME2;
+import org.openecomp.sdnc.sli.SliPluginUtils.SliPluginUtilsActivator;
+
+public class Dme2Test {
+
+ @Test
+ public void createInstarUrl() {
+ String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com";
+ DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
+ String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(instarUrl, constructedUrl);
+ }
+
+ @Test
+ public void createInstarUrlNoSubContext() {
+ String instarUrl = "http://localhost:25055/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT?dme2.password=fake&dme2.username=user@sample.com";
+ DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", new String[] { "http://localhost:25055" }, "common");
+ Map<String, String> parameters = new HashMap<String, String>();
+ String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", parameters.get(null));
+ assertEquals(instarUrl, constructedUrl);
+ }
+
+ @Test
+ public void testRoundRobin() {
+ String[] proxyHostNames = new String[] { "http://one:25055", "http://two:25055", "http://three:25055" };
+ String urlSuffix = "/service=sample.com/services/eim/v1/rest/version=1702.0/envContext=TEST/routeOffer=DEFAULT/subContext=/enterpriseConnection/getEnterpriseConnectionDetails/v1?dme2.password=fake&dme2.username=user@sample.com";
+ DME2 dme = new DME2("user@sample.com", "fake", "TEST", "DEFAULT", proxyHostNames, "common");
+ String constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[1] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[2] + urlSuffix, constructedUrl);
+ constructedUrl = dme.constructUrl("sample.com/services/eim/v1/rest", "1702.0", "/enterpriseConnection/getEnterpriseConnectionDetails/v1");
+ assertEquals(proxyHostNames[0] + urlSuffix, constructedUrl);
+ }
+
+ @Test
+ public void createDme2EndtoEnd() {
+ SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
+ DME2 dme2 = activator.initDme2("src/test/resources/dme2.e2e.properties");
+ assertEquals("user@sample.com", dme2.aafUserName);
+ assertEquals("fake", dme2.aafPassword);
+ assertEquals("UAT", dme2.envContext);
+ assertEquals("UAT", dme2.routeOffer);
+ Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
+ assertEquals("1702.0", dme2.commonServiceVersion);
+ assertEquals(null, dme2.partner);
+
+ String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
+ assertNotNull(constructedUrl);
+ System.out.println(constructedUrl);
+ }
+
+ @Test
+ public void createDme2Prod() {
+ SliPluginUtilsActivator activator = new SliPluginUtilsActivator();
+ DME2 dme2 = activator.initDme2("src/test/resources/dme2.prod.properties");
+ assertEquals("user@sample.com", dme2.aafUserName);
+ assertEquals("fake", dme2.aafPassword);
+ assertEquals("PROD", dme2.envContext);
+ assertEquals("", dme2.routeOffer);
+ Assert.assertArrayEquals("http://sample.com:25055,http://sample.com:25055".split(","), dme2.proxyUrls);
+ assertEquals("1.0", dme2.commonServiceVersion);
+ assertEquals("LPP_PROD", dme2.partner);
+
+ String constructedUrl = dme2.constructUrl("sample.com/restservices/instar/v1/assetSearch", null, "/mySubContext");
+ assertNotNull(constructedUrl);
+ System.out.println(constructedUrl);
+ }
+
+}
diff --git a/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_StaticFunctionsTest.java b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_StaticFunctionsTest.java
new file mode 100644
index 000000000..e69d08676
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_StaticFunctionsTest.java
@@ -0,0 +1,250 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.openecomp.sdnc.sli.SliPluginUtils;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+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 printContext() throws SvcLogicException, IOException {
+ String filePath = "/src/test/resources/printContext.txt";
+ parameters.put("filename", filePath);
+ File f = new File(filePath);
+ assert (f.exists());
+ assert (!f.isDirectory());
+ ctx.setAttribute("hello", "world");
+ ctx.setAttribute("name", "value");
+
+ SliPluginUtils.printContext(parameters, ctx);
+ BufferedReader br = new BufferedReader(new FileReader(f));
+ String line = br.readLine();
+ assertEquals("#######################################", line);
+ line = br.readLine();
+ assertEquals("hello = world", line);
+ line = br.readLine();
+ assertEquals("name = value", line);
+ br.close();
+ Files.delete(Paths.get(filePath));
+ }*/
+
+ @Test
+ public void setTime() throws SvcLogicException {
+ String outputPath = "output";
+ parameters.put("outputPath", outputPath);
+ SliPluginUtils.setTime(parameters, ctx);
+ assertNotNull(ctx.getAttribute(outputPath));
+ }
+}
diff --git a/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortList.java b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortList.java
new file mode 100644
index 000000000..b1cae54a0
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortList.java
@@ -0,0 +1,96 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.openecomp.sdnc.sli.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.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.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 );
+ }
+ }
+}
diff --git a/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortListTest.java b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortListTest.java
new file mode 100644
index 000000000..e2fcb33d7
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliPluginUtils_ctxSortListTest.java
@@ -0,0 +1,97 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.openecomp.sdnc.sli.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.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.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/openecomp/sdnc/sli/SliPluginUtils/SliStringUtilsTest.java b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliStringUtilsTest.java
new file mode 100644
index 000000000..d57cefa0d
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SliStringUtilsTest.java
@@ -0,0 +1,244 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.openecomp.sdnc.sli.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.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.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 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 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));
+ }
+
+}
diff --git a/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SvcLogicContextListTest.java b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SvcLogicContextListTest.java
new file mode 100644
index 000000000..5d7bb249a
--- /dev/null
+++ b/sliPluginUtils/provider/src/test/java/org/openecomp/sdnc/sli/SliPluginUtils/SvcLogicContextListTest.java
@@ -0,0 +1,307 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * openECOMP : SDN-C
+ * ================================================================================
+ * 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.openecomp.sdnc.sli.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.openecomp.sdnc.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"));
+ }
+}