summaryrefslogtreecommitdiffstats
path: root/properties-node/provider/src/test/java
diff options
context:
space:
mode:
authorGanesh Chandrasekaran <ganesh.c@samsung.com>2018-06-15 10:17:06 +0900
committerGanesh Chandrasekaran <ganesh.c@samsung.com>2018-06-15 10:34:36 +0900
commitb942c2091cacfe09e503e445c7a15b77080ab357 (patch)
treef586ce97080a0eb8bb0cb5de56097a87c35b746c /properties-node/provider/src/test/java
parenta87dc9c351b0c08d20adc428c215cf3934bb79bb (diff)
CCSDK PropNode can read JSON and put to ctx
Issue-ID: CCSDK-304 Change-Id: I510fe73c3eedc49071e386689090104a761a03a6 CCSDK PropertyNode can now read a JSON file and put to ctx memory Change-Id: I440ae043c020a08cd869df587916799dd7e3aeea CCSDK PropertyNode can now read a JSON file and put to ctx memory Issue-ID: CCSDK-304 Change-Id: Ic06a89c2327d07b31a1f45b9cc57783d8faf370a Signed-off-by: Ganesh Chandrasekaran <ganesh.c@samsung.com>
Diffstat (limited to 'properties-node/provider/src/test/java')
-rw-r--r--properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestJsonParser.java73
-rw-r--r--properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java247
2 files changed, 320 insertions, 0 deletions
diff --git a/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestJsonParser.java b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestJsonParser.java
new file mode 100644
index 00000000..0681124d
--- /dev/null
+++ b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestJsonParser.java
@@ -0,0 +1,73 @@
+/*-
+ * ============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 jtest.org.onap.ccsdk.sli.plugins.prop;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.plugins.prop.JsonParser;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestJsonParser {
+
+ private static final Logger log = LoggerFactory.getLogger(TestJsonParser.class);
+
+ @Test
+ public void test() throws SvcLogicException, IOException {
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(ClassLoader.getSystemResourceAsStream("test.json"))
+ );
+ StringBuilder b = new StringBuilder();
+ String line;
+ while ((line = in.readLine()) != null)
+ b.append(line).append('\n');
+
+ Map<String, String> mm = JsonParser.convertToProperties(b.toString());
+
+ logProperties(mm);
+
+ in.close();
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void testNullString() throws SvcLogicException {
+ JsonParser.convertToProperties(null);
+ }
+
+ private void logProperties(Map<String, String> mm) {
+ List<String> ll = new ArrayList<>();
+ for (Object o : mm.keySet())
+ ll.add((String) o);
+ Collections.sort(ll);
+ log.info("Properties:");
+ for (String name : ll)
+ log.info("--- {}: {}", name, mm.get(name));
+ }
+}
diff --git a/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java
new file mode 100644
index 00000000..894eee99
--- /dev/null
+++ b/properties-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/prop/TestPropertiesNode.java
@@ -0,0 +1,247 @@
+package jtest.org.onap.ccsdk.sli.plugins.prop;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.Test;
+import static org.junit.Assert.assertEquals;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.plugins.prop.PropertiesNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class TestPropertiesNode {
+
+ private static final Logger log = LoggerFactory.getLogger(TestPropertiesNode.class);
+
+ @Test
+ public void testJSONFileParsing() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.json");
+ p.put("contextPrefix", "test-json");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("test-json.message"),"The provisioned access " +
+ "bandwidth is at or exceeds 50% of the total server capacity.");
+ }
+
+ @Test
+ public void testJSONFileArrayParsing() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.json");
+ p.put("contextPrefix", "test-json");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("test-json.equipment-data[0].max-server-speed"),"1600000");
+ assertEquals(ctx.getAttribute("test-json.resource-state.used"),"1605000");
+ assertEquals(ctx.getAttribute("test-json.resource-rule.service-model"),"DUMMY");
+ assertEquals(ctx.getAttribute("test-json.resource-rule.endpoint-position"),"VCE-Cust");
+ }
+
+ @Test
+ public void testJSONFileParsingPrefixCheck() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.json");
+ p.put("contextPrefix", "");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("equipment-data[0].max-server-speed"),"1600000");
+ assertEquals(ctx.getAttribute("resource-state.used"),"1605000");
+ assertEquals(ctx.getAttribute("resource-rule.service-model"),"DUMMY");
+ assertEquals(ctx.getAttribute("resource-rule.endpoint-position"),"VCE-Cust");
+ assertEquals(ctx.getAttribute("resource-rule.hard-limit-expression"),"max-server-" +
+ "speed * number-primary-servers");
+ }
+
+ @Test
+ public void testJSONFileParsingNoPrefix() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.json");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("equipment-data[0].max-server-speed"),"1600000");
+ assertEquals(ctx.getAttribute("resource-state.used"),"1605000");
+ assertEquals(ctx.getAttribute("resource-rule.service-model"),"DUMMY");
+ assertEquals(ctx.getAttribute("resource-rule.endpoint-position"),"VCE-Cust");
+ assertEquals(ctx.getAttribute("resource-rule.hard-limit-expression"),"max-server-" +
+ "speed * number-primary-servers");
+ }
+
+ @Test
+ public void testJSONFileParsingCtxCheck() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.json");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("equipment-data[0].max-server-speed"),"1600000");
+ assertEquals(ctx.getAttribute("resource-state.used"),"1605000");
+ assertEquals(ctx.getAttribute("resource-rule.service-model"),"DUMMY");
+ assertEquals(ctx.getAttribute("resource-rule.endpoint-position"),"VCE-Cust");
+ assertEquals(ctx.getAttribute("resource-rule.hard-limit-expression"),"max-server-" +
+ "speed * number-primary-servers");
+ assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testToPropertiesInvalidJson() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test-invalid.json");
+ p.put("contextPrefix", "invalid");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
+ }
+
+ @Test
+ public void testTXTFileParsing() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.txt");
+ p.put("contextPrefix", "test-txt");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("test-txt.service-data.service-information.service-type"),"AVPN");
+ assertEquals(ctx.getAttribute("test-txt.service-configuration-notification-input.response-code"),"0");
+ assertEquals(ctx.getAttribute("test-txt.operational-data.avpn-ip-port-information.port-" +
+ "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
+ assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" +
+ "access-information.l1-customer-handoff"),"_1000BASELX");
+ assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" +
+ "access-information.vlan-tag-control"),"_1Q");
+ }
+
+ @Test
+ public void testTXTFileParsingPrefixCheck() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.txt");
+ p.put("contextPrefix", "");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN");
+ assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0");
+ assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" +
+ "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
+ assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
+ "access-information.l1-customer-handoff"),"_1000BASELX");
+ assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
+ "access-information.vlan-tag-control"),"_1Q");
+ }
+
+ @Test
+ public void testTXTFileParsingNoPrefix() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.txt");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN");
+ assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0");
+ assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" +
+ "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
+ assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
+ "access-information.l1-customer-handoff"),"_1000BASELX");
+ assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
+ "access-information.vlan-tag-control"),"_1Q");
+ }
+
+ @Test
+ public void testTXTFileParsingCtxCheck() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/test/resources/test.txt");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN");
+ assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0");
+ assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" +
+ "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
+ assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
+ "access-information.l1-customer-handoff"),"_1000BASELX");
+ assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
+ "access-information.vlan-tag-control"),"_1Q");
+ assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testToPropertiesInvalidParam() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("responsePrefix", "response");
+ p.put("skipSending", "true");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testToPropertiesNoParam() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
+
+ Map<String, String> p = new HashMap<String, String>();
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testToPropertiesFilePathError() throws SvcLogicException {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
+
+ Map<String, String> p = new HashMap<String, String>();
+ p.put("fileName", "src/tests/resources/test.txt");
+
+ PropertiesNode rcn = new PropertiesNode();
+ rcn.readProperties(p, ctx);
+
+ assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
+ }
+}