aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSandeep J <sandeejh@in.ibm.com>2018-10-02 01:42:18 +0530
committerSandeep J <sandeejh@in.ibm.com>2018-10-02 01:42:26 +0530
commit4f6fbb98b4775a6ec181cbfc1992c2ea4a94b30f (patch)
tree3b5d902486ee916d1f833ab860a429fb5ff39bd4
parent6f094ba9114abf9983bb6de3b365919b88df3af3 (diff)
added test cases to MdsalHelperTest
to increase code coverage Issue-ID: CCSDK-552 Change-Id: I9d5ba40bc0039ef335642a0c66d8680c704b2d40 Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
-rw-r--r--sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java160
1 files changed, 86 insertions, 74 deletions
diff --git a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
index 307c69c7..d0ea4f55 100644
--- a/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
+++ b/sli/provider/src/test/java/org/onap/ccsdk/sli/core/sli/provider/MdsalHelperTest.java
@@ -3,7 +3,9 @@
* ONAP : CCSDK
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights
- * reserved.
+ * 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.
@@ -21,33 +23,26 @@
package org.onap.ccsdk.sli.core.sli.provider;
-import java.io.File;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.Properties;
-import static org.junit.Assert.*;
-
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput.Mode;
-import org.onap.ccsdk.sli.core.sli.provider.MdsalHelper;
-import org.onap.ccsdk.sli.core.sli.SvcLogicGraph;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInputBuilder;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameter;
import org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.execute.graph.input.SliParameterBuilder;
-import org.opendaylight.yang.gen.v1.test.CosModelType;
import org.opendaylight.yang.gen.v1.test.WrapperObj;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.Dscp;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpAddressBuilder;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.PortNumber;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import junit.framework.TestCase;
-
public class MdsalHelperTest extends TestCase {
- private static final Logger LOG = LoggerFactory
- .getLogger(MdsalHelperTest.class);
+ private static final Logger LOG = LoggerFactory.getLogger(MdsalHelperTest.class);
public static final String pathToSdnPropertiesFile = "src/test/resources/l3sdn.properties";
public void testSdnProperties() {
@@ -56,8 +51,8 @@ public class MdsalHelperTest extends TestCase {
assertEquals("synccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "synccomplete"));
assertEquals("asynccomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "asynccomplete"));
assertEquals("notifycomplete", MdsalHelperTesterUtil.mapEnumeratedValue("request-status", "notifycomplete"));
- assertEquals("service-configuration-operation", MdsalHelperTesterUtil.mapEnumeratedValue("rpc-name",
- "service-configuration-operation"));
+ assertEquals("service-configuration-operation",
+ MdsalHelperTesterUtil.mapEnumeratedValue("rpc-name", "service-configuration-operation"));
}
public void testNegativeSdnProperties() {
@@ -66,85 +61,82 @@ public class MdsalHelperTest extends TestCase {
public void testToProperties() {
- ExecuteGraphInputBuilder execBuilder = new ExecuteGraphInputBuilder();
- SliParameterBuilder parmBuilder = new SliParameterBuilder();
- List<SliParameter> params = new LinkedList<SliParameter>();
-
- parmBuilder.setParameterName("boolean-parm");
- parmBuilder.setBooleanValue(Boolean.TRUE);
- params.add(parmBuilder.build());
-
- parmBuilder.setParameterName("int-parm");
- parmBuilder.setBooleanValue(null);
- parmBuilder.setIntValue(1);
- params.add(parmBuilder.build());
-
- parmBuilder.setParameterName("str-parm");
- parmBuilder.setIntValue(null);
- parmBuilder.setStringValue("hello");
- params.add(parmBuilder.build());
+ ExecuteGraphInputBuilder execBuilder = new ExecuteGraphInputBuilder();
+ SliParameterBuilder parmBuilder = new SliParameterBuilder();
+ List<SliParameter> params = new LinkedList<SliParameter>();
- parmBuilder.setParameterName("ipaddress4-parm");
- parmBuilder.setStringValue(null);
- parmBuilder.setIpaddressValue(IpAddressBuilder.getDefaultInstance("127.0.0.1"));
- params.add(parmBuilder.build());
+ parmBuilder.setParameterName("boolean-parm");
+ parmBuilder.setBooleanValue(Boolean.TRUE);
+ params.add(parmBuilder.build());
- parmBuilder.setParameterName("ipaddress6-parm");
- parmBuilder.setIpaddressValue(IpAddressBuilder.getDefaultInstance("ef::1"));
- params.add(parmBuilder.build());
+ parmBuilder.setParameterName("int-parm");
+ parmBuilder.setBooleanValue(null);
+ parmBuilder.setIntValue(1);
+ params.add(parmBuilder.build());
+ parmBuilder.setParameterName("str-parm");
+ parmBuilder.setIntValue(null);
+ parmBuilder.setStringValue("hello");
+ params.add(parmBuilder.build());
- execBuilder.setMode(Mode.Sync);
- execBuilder.setModuleName("my-module");
- execBuilder.setRpcName("do-it-now");
- execBuilder.setSliParameter(params);
+ parmBuilder.setParameterName("ipaddress4-parm");
+ parmBuilder.setStringValue(null);
+ parmBuilder.setIpaddressValue(IpAddressBuilder.getDefaultInstance("127.0.0.1"));
+ params.add(parmBuilder.build());
+ parmBuilder.setParameterName("ipaddress6-parm");
+ parmBuilder.setIpaddressValue(IpAddressBuilder.getDefaultInstance("ef::1"));
+ params.add(parmBuilder.build());
- Properties props = new Properties();
+ execBuilder.setMode(Mode.Sync);
+ execBuilder.setModuleName("my-module");
+ execBuilder.setRpcName("do-it-now");
+ execBuilder.setSliParameter(params);
- MdsalHelperTesterUtil.toProperties(props, execBuilder);
+ Properties props = new Properties();
- LOG.info("Converted to properties");
- for (Map.Entry<Object, Object> e : props.entrySet()) {
- LOG.info(e.getKey().toString() + " = "+e.getValue().toString());
+ MdsalHelperTesterUtil.toProperties(props, execBuilder);
+ MdsalHelperTesterUtil.toProperties(props, "", execBuilder);
- }
+ LOG.info("Converted to properties");
+ for (Map.Entry<Object, Object> e : props.entrySet()) {
+ LOG.info(e.getKey().toString() + " = " + e.getValue().toString());
+ }
}
public void testToBuilder() {
- Properties props = new Properties();
-
- props.setProperty("execute-graph-input.mode", "Sync");
- props.setProperty("execute-graph-input.module", "my-module");
- props.setProperty("execute-graph-input.rpc", "do-it-now");
- props.setProperty("execute-graph-input.sli-parameter[0].parameter-name", "bool-parm");
- props.setProperty("execute-graph-input.sli-parameter[0].boolean-value", "true");
- props.setProperty("execute-graph-input,sli-parameter[1].parameter-name", "int-param");
- props.setProperty("execute-graph-input.sli-parameter[1].int-value", "1");
- props.setProperty("execute-graph-input.sli-parameter[2].parameter-name", "str-param");
- props.setProperty("execute-graph-input.sli-parameter[2].str-value", "hello");
- props.setProperty("execute-graph-input.sli-parameter[3].parameter-name", "ipv4address-param");
- props.setProperty("execute-graph-input.sli-parameter[3].ipaddress-value", "127.0.0.1");
- props.setProperty("execute-graph-input.sli-parameter[4].parameter-name", "ipv6address-param");
- props.setProperty("execute-graph-input.sli-parameter[4].ipaddress-value", "ef::1");
- ExecuteGraphInputBuilder execBuilder = new ExecuteGraphInputBuilder();
-
- MdsalHelperTesterUtil.toBuilder(props, execBuilder);
-
+ Properties props = new Properties();
+ props.setProperty("execute-graph-input.mode", "Sync");
+ props.setProperty("execute-graph-input.module", "my-module");
+ props.setProperty("execute-graph-input.rpc", "do-it-now");
+ props.setProperty("execute-graph-input.sli-parameter[0].parameter-name", "bool-parm");
+ props.setProperty("execute-graph-input.sli-parameter[0].boolean-value", "true");
+ props.setProperty("execute-graph-input,sli-parameter[1].parameter-name", "int-param");
+ props.setProperty("execute-graph-input.sli-parameter[1].int-value", "1");
+ props.setProperty("execute-graph-input.sli-parameter[2].parameter-name", "str-param");
+ props.setProperty("execute-graph-input.sli-parameter[2].str-value", "hello");
+ props.setProperty("execute-graph-input.sli-parameter[3].parameter-name", "ipv4address-param");
+ props.setProperty("execute-graph-input.sli-parameter[3].ipaddress-value", "127.0.0.1");
+ props.setProperty("execute-graph-input.sli-parameter[4].parameter-name", "ipv6address-param");
+ props.setProperty("execute-graph-input.sli-parameter[4].ipaddress-value", "ef::1");
+ ExecuteGraphInputBuilder execBuilder = new ExecuteGraphInputBuilder();
+
+ MdsalHelperTesterUtil.toBuilder(props, execBuilder);
}
- public void testToJavaEnum() throws Exception{
- assertEquals("_2018HelloWorld",MdsalHelper.toJavaEnum("2018Hello World"));
- assertEquals("SomethingElse",MdsalHelper.toJavaEnum("Something.Else"));
- assertEquals("MyTestString",MdsalHelper.toJavaEnum("my-test-string"));
+ public void testToJavaEnum() throws Exception {
+ assertEquals("_2018HelloWorld", MdsalHelper.toJavaEnum("2018Hello World"));
+ assertEquals("SomethingElse", MdsalHelper.toJavaEnum("Something.Else"));
+ assertEquals("MyTestString", MdsalHelper.toJavaEnum("my-test-string"));
}
-
- // During the default enumeration mapping no properties file is needed, the yang value is returned
+
+ // During the default enumeration mapping no properties file is needed, the
+ // yang value is returned
// by the java object
public void testDefaultEnumerationMapping() throws Exception {
Properties props = new Properties();
@@ -152,7 +144,8 @@ public class MdsalHelperTest extends TestCase {
assertEquals("4COS", props.getProperty("wrapper-obj.cos-model-type"));
}
- // When no properties file exists the default java value will be returned if legacy enumeration
+ // When no properties file exists the default java value will be returned if
+ // legacy enumeration
// mapping is enabled
public void testLegacyEnumerationMappingNoProperties() throws Exception {
Properties props = new Properties();
@@ -160,7 +153,8 @@ public class MdsalHelperTest extends TestCase {
assertEquals("_4COS", props.getProperty("wrapper-obj.cos-model-type"));
}
- // When a properties file exists & legacy enumeration mapping is enabled the value from the
+ // When a properties file exists & legacy enumeration mapping is enabled the
+ // value from the
// properties file should be returned
public void testLegacyEnumerationMappingWithProperties() throws Exception {
MdsalHelper.loadProperties("src/test/resources/EnumerationMapping.properties");
@@ -168,4 +162,22 @@ public class MdsalHelperTest extends TestCase {
MdsalHelper.toProperties(props, new WrapperObj(), true);
assertEquals("HelloWorld", props.getProperty("wrapper-obj.cos-model-type"));
}
+
+ public void testGetFullPropertiesPath() {
+ String fullPath = MdsalHelper.getFullPropertiesPath("testFile");
+ assertEquals("/opt/bvc/controller/configuration/testFile", fullPath);
+
+ }
+
+ public void testIsDscp() {
+
+ assertTrue(MdsalHelper.isDscp(Dscp.class));
+
+ }
+
+ public void testIsPortNumber() {
+
+ assertTrue(MdsalHelper.isPortNumber(PortNumber.class));
+
+ }
}