diff options
7 files changed, 562 insertions, 448 deletions
diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java index c463f38bb..45268107e 100644 --- a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java @@ -1,10 +1,12 @@ package org.onap.ccsdk.sli.core.dblib; 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.sql.SQLException; import java.sql.SQLFeatureNotSupportedException; import java.util.Properties; @@ -94,4 +96,26 @@ public class CachedDataSourceTest { assertEquals("passw0rd", ((JdbcDBCachedDataSource) ds).getDbPasswd()); assertEquals("testdb01", ((JdbcDBCachedDataSource) ds).toString()); } + + @Test + public void testIsInitialised() { + assertTrue(ds.isInitialized()); + } + + @Test + public void testIsWrapperFor() throws SQLException { + assertFalse(ds.isWrapperFor(CachedDataSource.class)); + } + + @Test + public void testGetSetNextErrorReportTime() throws SQLException { + ds.setNextErrorReportTime(1L); + assertEquals(1L, ds.getNextErrorReportTime()); + } + + @Test + public void testGetSetGlobalHostName() throws SQLException { + ds.setGlobalHostName("hostName"); + assertEquals("hostName", ds.getGlobalHostName()); + } }
\ No newline at end of file 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 307c69c7d..d0ea4f551 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)); + + } } diff --git a/sli/recording/src/test/java/org/onap/ccsdk/sli/core/sli/recording/TestFileRecorder.java b/sli/recording/src/test/java/org/onap/ccsdk/sli/core/sli/recording/TestFileRecorder.java index c879d8f62..d0cc83182 100644 --- a/sli/recording/src/test/java/org/onap/ccsdk/sli/core/sli/recording/TestFileRecorder.java +++ b/sli/recording/src/test/java/org/onap/ccsdk/sli/core/sli/recording/TestFileRecorder.java @@ -3,8 +3,11 @@ */ package org.onap.ccsdk.sli.core.sli.recording; -import static org.junit.Assert.*; +import static org.junit.Assert.fail; + import java.util.HashMap; + +import org.junit.Before; import org.junit.Test; import org.onap.ccsdk.sli.core.sli.SvcLogicException; @@ -13,23 +16,34 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException; * */ public class TestFileRecorder { + private FileRecorder recorder; + + @Before + public void setUp() { + recorder = new FileRecorder(); + } + + /** + * Test method for + * {@link org.onap.ccsdk.sli.core.sli.recording.FileRecorder#record(java.util.Map)}. + */ + @Test + public void testRecord() { + HashMap<String, String> parms = new HashMap<>(); + parms.put("file", "/dev/null"); + parms.put("field1", "hi"); + try { + recorder.record(parms); + } catch (SvcLogicException e) { + fail("Caught SvcLogicException : " + e.getMessage()); + } + } - /** - * Test method for {@link org.onap.ccsdk.sli.core.sli.recording.FileRecorder#record(java.util.Map)}. - */ - @Test - public void testRecord() { - - FileRecorder recorder = new FileRecorder(); - - HashMap<String,String> parms = new HashMap<>(); - parms.put("file", "/dev/null"); - parms.put("field1","hi"); - try { - recorder.record(parms); - } catch (SvcLogicException e) { - fail("Caught SvcLogicException : "+e.getMessage()); - } - } + @Test(expected = Exception.class) + public void testRecordForEmptyFileName() throws Exception { + HashMap<String, String> parms = new HashMap<>(); + parms.put("field1", "hi"); + recorder.record(parms); + } } 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 index bfd19bc6a..78e846aef 100644 --- 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 @@ -19,8 +19,8 @@ * 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; @@ -28,7 +28,7 @@ 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; @@ -38,104 +38,113 @@ 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")); - } + 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("success", SliPluginUtils.setPropertiesForList(parameters, ctx)); + + } } 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 index 9bf851d5d..085d46ef7 100644 --- 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 @@ -19,7 +19,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= - */ + */ package org.onap.ccsdk.sli.core.slipluginutils; @@ -29,7 +29,7 @@ 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; @@ -40,246 +40,261 @@ import org.onap.ccsdk.sli.core.sli.SvcLogicException; * */ 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 testXmlEscapeText() - { - param.put("source", "102/GE100/SNJSCAMCJP8/SNJSCAMCJT4"); - param.put("target", "target"); - SliStringUtils.xmlEscapeText(param,ctx); - assertEquals("102/GE100/SNJSCAMCJP8/SNJSCAMCJT4",ctx.getAttribute("target")); - } + 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 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); + } } diff --git a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/SliapiHelperTest.java b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/SliapiHelperTest.java new file mode 100644 index 000000000..228f6127e --- /dev/null +++ b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/SliapiHelperTest.java @@ -0,0 +1,35 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : CCSDK + * ================================================================================ + * Copyright (C) 2018 IBM. 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.sliapi; + +import static org.junit.Assert.assertNotNull; + +import org.junit.Test; + +public class SliapiHelperTest { + + @Test + public void TestSliapiHelper() + { + SliapiHelper sliapiHelper= new SliapiHelper(); + assertNotNull(sliapiHelper); + } +} diff --git a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java index 38cbd40c9..287f2f206 100644 --- a/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java +++ b/sliapi/provider/src/test/java/org/onap/ccsdk/sli/core/sliapi/TestSliapiProvider.java @@ -4,8 +4,12 @@ package org.onap.ccsdk.sli.core.sliapi; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import static org.mockito.Mockito.*; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import java.io.InputStream; import java.net.URL; import java.util.HashMap; @@ -13,6 +17,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.concurrent.Future; + import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -86,7 +92,6 @@ public class TestSliapiProvider { } }; - /** * @throws java.lang.Exception */ @@ -95,10 +100,10 @@ public class TestSliapiProvider { DataBroker dataBroker = mock(DataBroker.class); NotificationPublishService notifyService = mock(NotificationPublishService.class); RpcProviderRegistry rpcRegistry = mock(RpcProviderRegistry.class); - BindingAwareBroker.RpcRegistration<SLIAPIService> rpcRegistration = (BindingAwareBroker.RpcRegistration<SLIAPIService>) mock(BindingAwareBroker.RpcRegistration.class); + BindingAwareBroker.RpcRegistration<SLIAPIService> rpcRegistration = (BindingAwareBroker.RpcRegistration<SLIAPIService>) mock( + BindingAwareBroker.RpcRegistration.class); when(rpcRegistry.addRpcImplementation(any(Class.class), any(SLIAPIService.class))).thenReturn(rpcRegistration); - // Load svclogic.properties and get a SvcLogicStore InputStream propStr = TestSliapiProvider.class.getResourceAsStream("/svclogic.properties"); Properties svcprops = new Properties(); @@ -111,7 +116,7 @@ public class TestSliapiProvider { // Load the DG for the healthcheck api URL testCaseUrl = TestSliapiProvider.class.getClassLoader().getResource(HEALTHCHECK_DG); if (testCaseUrl == null) { - fail("Cannot find "+HEALTHCHECK_DG); + fail("Cannot find " + HEALTHCHECK_DG); } SvcLogicParser.load(testCaseUrl.getPath(), store); SvcLogicParser.activate("sli", "healthcheck", "1.0.0", "sync", store); @@ -138,7 +143,8 @@ public class TestSliapiProvider { } /** - * Test method for {@link org.onap.ccsdk.sli.core.sliapi.sliapiProvider#executeGraph(org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput)}. + * Test method for + * {@link org.onap.ccsdk.sli.core.sliapi.sliapiProvider#executeGraph(org.opendaylight.yang.gen.v1.org.onap.ccsdk.sli.core.sliapi.rev161110.ExecuteGraphInput)}. */ @Test public void testExecuteGraph() { @@ -154,14 +160,13 @@ public class TestSliapiProvider { pList.add(pBuilder.build()); inputBuilder.setSliParameter(pList); - - - provider.executeGraph(inputBuilder.build()); + assertTrue(provider.vlbcheck() instanceof Future<?>); } /** - * Test method for {@link org.onap.ccsdk.sli.core.sliapi.sliapiProvider#healthcheck()}. + * Test method for + * {@link org.onap.ccsdk.sli.core.sliapi.sliapiProvider#healthcheck()}. */ @Test public void testHealthcheck() { |