summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/CachedDataSourceTest.java159
-rw-r--r--dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java63
-rw-r--r--sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java201
3 files changed, 239 insertions, 184 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 6385c1b5..c463f38b 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,6 +1,9 @@
package org.onap.ccsdk.sli.core.dblib;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.sql.SQLFeatureNotSupportedException;
import java.util.Properties;
@@ -14,81 +17,81 @@ import org.slf4j.LoggerFactory;
public class CachedDataSourceTest {
- private static final Properties props = new Properties();
-
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
- props.setProperty("org.onap.ccsdk.sli.dbtype", "jdbc");
- props.setProperty("org.onap.ccsdk.sli.jdbc.hosts", "localhost");
- props.setProperty("org.onap.ccsdk.sli.jdbc.url", "jdbc:mysql://dbhost:3306/test");
- props.setProperty("org.onap.ccsdk.sli.jdbc.driver", "org.mariadb.jdbc.Driver");
- props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
- props.setProperty("org.onap.ccsdk.sli.jdbc.user", "dbuser");
- props.setProperty("org.onap.ccsdk.sli.jdbc.password", "passw0rd");
- props.setProperty("org.onap.ccsdk.sli.jdbc.connection.name", "testdb01");
- props.setProperty("org.onap.ccsdk.sli.jdbc.connection.timeout", "50");
- props.setProperty("org.onap.ccsdk.sli.jdbc.request.timeout", "100");
- props.setProperty("org.onap.ccsdk.sli.jdbc.limit.init", "10");
- props.setProperty("org.onap.ccsdk.sli.jdbc.limit.min", "10");
- props.setProperty("org.onap.ccsdk.sli.jdbc.limit.max", "20");
- props.setProperty("org.onap.dblib.connection.recovery", "false");
- }
-
- @Test
- public void testCachedDataSource() {
- BaseDBConfiguration config = new JDBCConfiguration(props);
- CachedDataSource ds = new JdbcDBCachedDataSource(config);
- assertNotNull(ds);
- }
-
- @Test
- public void testConfigure() {
- BaseDBConfiguration config = new JDBCConfiguration(props);
-
- CachedDataSource ds = new JdbcDBCachedDataSource(config);
- assertNotNull(ds.configure(config));
- }
-
- @Test
- public void testSetInitialDelay() {
- BaseDBConfiguration config = new JDBCConfiguration(props);
- CachedDataSource ds = new JdbcDBCachedDataSource(config);
- ds.setInitialDelay(1000L);
- assertTrue(ds.getInitialDelay() == 1000L);
- }
-
- @Test
- public void testSetInterval() {
- BaseDBConfiguration config = new JDBCConfiguration(props);
- CachedDataSource ds = new JdbcDBCachedDataSource(config);
- ds.setInterval(1000L);
- assertTrue(ds.getInterval() == 1000L);
- }
-
- @Test
- public void testSetExpectedCompletionTime() {
- BaseDBConfiguration config = new JDBCConfiguration(props);
- CachedDataSource ds = new JdbcDBCachedDataSource(config);
- ds.setExpectedCompletionTime(100L);
- assertTrue(ds.getExpectedCompletionTime() == 100L);
- }
-
- @Test
- public void testSetUnprocessedFailoverThreshold() {
- BaseDBConfiguration config = new JDBCConfiguration(props);
- CachedDataSource ds = new JdbcDBCachedDataSource(config);
- ds.setUnprocessedFailoverThreshold(100L);
- assertTrue(ds.getUnprocessedFailoverThreshold() == 100L);
- }
-
- @Test
- public void testGetParentLogger() {
- BaseDBConfiguration config = new JDBCConfiguration(props);
- CachedDataSource ds = new JdbcDBCachedDataSource(config);
- try {
- assertNull(ds.getParentLogger());
- } catch (SQLFeatureNotSupportedException e) {
- LoggerFactory.getLogger(CachedDataSourceTest.class).warn("Test Failure", e);
- }
- }
+ private static final Properties props = new Properties();
+ private static BaseDBConfiguration config;
+ private static CachedDataSource ds;
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ props.setProperty("org.onap.ccsdk.sli.dbtype", "jdbc");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.hosts", "localhost");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.url", "jdbc:mysql://dbhost:3306/test");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.driver", "org.mariadb.jdbc.Driver");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.user", "dbuser");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.password", "passw0rd");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.connection.name", "testdb01");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.connection.timeout", "50");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.request.timeout", "100");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.limit.init", "10");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.limit.min", "10");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.limit.max", "20");
+ props.setProperty("org.onap.dblib.connection.recovery", "false");
+
+ config = new JDBCConfiguration(props);
+ ds = new JdbcDBCachedDataSource(config);
+ }
+
+ @Test
+ public void testCachedDataSource() {
+ assertNotNull(ds);
+ }
+
+ @Test
+ public void testConfigure() {
+
+ assertNotNull(ds.configure(config));
+ }
+
+ @Test
+ public void testSetInitialDelay() {
+ ds.setInitialDelay(1000L);
+ assertTrue(ds.getInitialDelay() == 1000L);
+ }
+
+ @Test
+ public void testSetInterval() {
+ ds.setInterval(1000L);
+ assertTrue(ds.getInterval() == 1000L);
+ }
+
+ @Test
+ public void testSetExpectedCompletionTime() {
+ ds.setExpectedCompletionTime(100L);
+ assertTrue(ds.getExpectedCompletionTime() == 100L);
+ }
+
+ @Test
+ public void testSetUnprocessedFailoverThreshold() {
+ ds.setUnprocessedFailoverThreshold(100L);
+ assertTrue(ds.getUnprocessedFailoverThreshold() == 100L);
+ }
+
+ @Test
+ public void testGetParentLogger() {
+ try {
+ assertNull(ds.getParentLogger());
+ } catch (SQLFeatureNotSupportedException e) {
+ LoggerFactory.getLogger(CachedDataSourceTest.class).warn("Test Failure", e);
+ }
+ }
+
+ @Test
+ public void testGettersForJdbcDBCachedDataSource() {
+
+ assertEquals("jdbc:mysql://dbhost:3306/test", ((JdbcDBCachedDataSource) ds).getDbUrl());
+ assertEquals("dbuser", ((JdbcDBCachedDataSource) ds).getDbUserId());
+ assertEquals("passw0rd", ((JdbcDBCachedDataSource) ds).getDbPasswd());
+ assertEquals("testdb01", ((JdbcDBCachedDataSource) ds).toString());
+ }
} \ No newline at end of file
diff --git a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java
index dca07921..8d7d3432 100644
--- a/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java
+++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java
@@ -4,6 +4,7 @@ import static org.junit.Assert.*;
import java.io.InputStream;
import java.net.URL;
+import java.sql.SQLException;
import java.util.Properties;
import org.junit.Before;
@@ -14,42 +15,56 @@ import ch.vorburger.mariadb4j.DBConfigurationBuilder;
public class TestDBResourceManager {
- DbLibService dblibSvc;
+ DbLibService dblibSvc;
+ DBResourceManager dbm;
- @Before
- public void setUp() throws Exception {
- URL propUrl = getClass().getResource("/dblib.properties");
+ @Before
+ public void setUp() throws Exception {
+ URL propUrl = getClass().getResource("/dblib.properties");
- InputStream propStr = getClass().getResourceAsStream("/dblib.properties");
+ InputStream propStr = getClass().getResourceAsStream("/dblib.properties");
- Properties props = new Properties();
+ Properties props = new Properties();
- props.load(propStr);
+ props.load(propStr);
+ // Start MariaDB4j database
+ DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
+ config.setPort(0); // 0 => autom. detect free port
+ DB db = DB.newEmbeddedDB(config.build());
+ db.start();
- // Start MariaDB4j database
- DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
- config.setPort(0); // 0 => autom. detect free port
- DB db = DB.newEmbeddedDB(config.build());
- db.start();
+ // Override jdbc URL and database name
+ props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test"));
+ dblibSvc = new DBResourceManager(props);
+ dbm = new DBResourceManager(props);
+ dblibSvc.writeData("CREATE TABLE DBLIB_TEST (name varchar(20));", null, null);
+ dblibSvc.getData("SELECT * FROM DBLIB_TEST", null, null);
- // Override jdbc URL and database name
- props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
- props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test"));
+ }
+ @Test
+ public void testForceRecovery() {
+ dbm.testForceRecovery();
+ }
- dblibSvc = new DBResourceManager(props);
+ @Test
+ public void testGetConnection() throws SQLException {
+ assertNotNull(dbm.getConnection());
+ assertNotNull(dbm.getConnection("testUser", "testPaswd"));
+ }
- dblibSvc.writeData("CREATE TABLE DBLIB_TEST (name varchar(20));", null, null);
- dblibSvc.getData("SELECT * FROM DBLIB_TEST", null, null);
+ @Test
+ public void testCleanup() {
+ dbm.cleanUp();
- }
+ }
- @Test
- public void test() {
-
-
- }
+ @Test
+ public void testGetLogWriter() throws SQLException {
+ assertNull(dbm.getLogWriter());
+ }
}
diff --git a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java
index 166a60e9..266603d1 100644
--- a/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.java
+++ b/sliPluginUtils/provider/src/test/java/org/onap/ccsdk/sli/core/slipluginutils/CheckParametersTest.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,6 +23,9 @@
package org.onap.ccsdk.sli.core.slipluginutils;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
import java.util.HashMap;
import java.util.Map;
@@ -32,85 +37,117 @@ 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);
- }
+ @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);
+ }
+
+ @Test(expected = SvcLogicException.class)
+ public void testJsonStringToCtx() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("outputPath", "testPath");
+ parameters.put("isEscaped", "true");
+ parameters.put("source", "//{/name1/:value1/}//");
+ SliPluginUtils.jsonStringToCtx(parameters, ctx);
+ }
+
+ @Test
+ public void testGetAttributeValue() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("outputPath", "testPath");
+ parameters.put("source", "testSource");
+ SliPluginUtils.getAttributeValue(parameters, ctx);
+ assertNull(ctx.getAttribute(parameters.get("outputPath")));
+ }
+
+ @Test
+ public void testCtxListContains() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ Map<String, String> parameters = new HashMap<String, String>();
+ parameters.put("list", "10_length");
+ parameters.put("keyName", "testName");
+ parameters.put("keyValue", "testValue");
+ ctx.setAttribute("10_length", "10");
+ assertEquals("false", SliPluginUtils.ctxListContains(parameters, ctx));
+
+ }
}