diff options
3 files changed, 142 insertions, 92 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 c463f38b..45268107 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 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)); + + } } 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 c879d8f6..d0cc8318 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); + } } |