From d73d257d76fa8211113fa3ef1a4e4058e67f4f2c Mon Sep 17 00:00:00 2001 From: Dan Timoney Date: Tue, 3 Oct 2017 08:17:38 -0400 Subject: Add unit tests for dblib Add unit test case for dblib/provider, using MariaDB4J as database. Change-Id: I18492595a9d54999c3d52b56ecfe33d0d2cae019 Issue-ID: CCSDK-106 Signed-off-by: Dan Timoney --- dblib/provider/pom.xml | 6 +++ .../sli/core/dblib/TestDBResourceManager.java | 55 ++++++++++++++++++++++ dblib/provider/src/test/resources/dblib.properties | 38 +++++++++++++++ 3 files changed, 99 insertions(+) create mode 100644 dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java create mode 100644 dblib/provider/src/test/resources/dblib.properties diff --git a/dblib/provider/pom.xml b/dblib/provider/pom.xml index d0dc7293..730919de 100755 --- a/dblib/provider/pom.xml +++ b/dblib/provider/pom.xml @@ -21,6 +21,12 @@ ${junit.version} test + + ch.vorburger.mariaDB4j + mariaDB4j + 2.2.3 + test + equinoxSDK381 org.eclipse.osgi 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 new file mode 100644 index 00000000..dca07921 --- /dev/null +++ b/dblib/provider/src/test/java/org/onap/ccsdk/sli/core/dblib/TestDBResourceManager.java @@ -0,0 +1,55 @@ +package org.onap.ccsdk.sli.core.dblib; + +import static org.junit.Assert.*; + +import java.io.InputStream; +import java.net.URL; +import java.util.Properties; + +import org.junit.Before; +import org.junit.Test; + +import ch.vorburger.mariadb4j.DB; +import ch.vorburger.mariadb4j.DBConfigurationBuilder; + +public class TestDBResourceManager { + + DbLibService dblibSvc; + + @Before + public void setUp() throws Exception { + URL propUrl = getClass().getResource("/dblib.properties"); + + InputStream propStr = getClass().getResourceAsStream("/dblib.properties"); + + Properties props = new Properties(); + + 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(); + + + // 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); + + dblibSvc.writeData("CREATE TABLE DBLIB_TEST (name varchar(20));", null, null); + dblibSvc.getData("SELECT * FROM DBLIB_TEST", null, null); + + } + + @Test + public void test() { + + + } + +} diff --git a/dblib/provider/src/test/resources/dblib.properties b/dblib/provider/src/test/resources/dblib.properties new file mode 100644 index 00000000..9506ac8d --- /dev/null +++ b/dblib/provider/src/test/resources/dblib.properties @@ -0,0 +1,38 @@ +### +# ============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========================================================= +### + +# dblib.properrties +org.onap.ccsdk.sli.dbtype=jdbc + +org.onap.ccsdk.sli.jdbc.hosts=sdnctldb01 +org.onap.ccsdk.sli.jdbc.url=jdbc:mysql://dbhost:3306/sdnctl +org.onap.ccsdk.sli.jdbc.driver=org.mariadb.jdbc.Driver +org.onap.ccsdk.sli.jdbc.database=sdnctl +org.onap.ccsdk.sli.jdbc.user=sdnctl +org.onap.ccsdk.sli.jdbc.password=gamma +org.onap.ccsdk.sli.jdbc.connection.name=sdnctldb01 +org.onap.ccsdk.sli.jdbc.connection.timeout=50 +org.onap.ccsdk.sli.jdbc.request.timeout=100 +org.onap.ccsdk.sli.jdbc.limit.init=10 +org.onap.ccsdk.sli.jdbc.limit.min=10 +org.onap.ccsdk.sli.jdbc.limit.max=20 +org.onap.dblib.connection.recovery=false + -- cgit 1.2.3-korg