summaryrefslogtreecommitdiffstats
path: root/sql-resource/provider/src/test/java
diff options
context:
space:
mode:
authorJessica Wagantall <jwagantall@linuxfoundation.org>2020-12-01 11:26:31 -0800
committerJessica Wagantall <jwagantall@linuxfoundation.org>2020-12-01 11:27:11 -0800
commit11510b43c277b8e1dd7e58d79785544810118c8e (patch)
treeb88a497c999d24b5f357ea9b26bc93e0990fd5e7 /sql-resource/provider/src/test/java
parent5d2eab72fc4442f14108b41800cec88126913823 (diff)
Migrate sli-adaptor files
Migrate sli-adaptor repo files into a new "adaptors" directory. Signed-off-by: Jessica Wagantall <jwagantall@linuxfoundation.org>
Diffstat (limited to 'sql-resource/provider/src/test/java')
-rwxr-xr-xsql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java231
-rwxr-xr-xsql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceProviderTest.java38
2 files changed, 0 insertions, 269 deletions
diff --git a/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java b/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java
deleted file mode 100755
index 2863c6c96..000000000
--- a/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/ITCaseSqlResource.java
+++ /dev/null
@@ -1,231 +0,0 @@
-/*-
- * ============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=========================================================
- */
-
-package org.onap.ccsdk.sli.adaptors.resource.sql;
-
-import java.io.BufferedReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.util.Enumeration;
-import java.util.Properties;
-
-import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import ch.vorburger.mariadb4j.DB;
-import ch.vorburger.mariadb4j.DBConfigurationBuilder;
-import junit.framework.TestCase;
-
-public class ITCaseSqlResource extends TestCase {
-
- private static final Logger LOG = LoggerFactory
- .getLogger(ITCaseSqlResource.class);
-
-
- public void testExists() throws Exception {
-
-
- Properties props = new Properties();
- InputStream propStr = getClass().getResourceAsStream("/svclogic.properties");
- if (propStr == null) {
- fail("src/test/resources/svclogic.properties missing");
- }
-
- try {
- props.load(propStr);
- propStr.close();
- } catch (Exception e) {
- e.printStackTrace();
- fail("Could not initialize properties");
- }
-
-
- // 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"));
-
- // Add properties to global properties
-
- Enumeration propNames = props.keys();
-
- while (propNames.hasMoreElements()) {
- String propName = (String) propNames.nextElement();
-
- System.setProperty(propName, props.getProperty(propName));
- }
-
- SqlResource sqlResource = new SqlResource(new SqlResourcePropertiesProviderImpl());
-
-
-
- InputStream testStr = getClass().getResourceAsStream("/save.tests");
- BufferedReader testsReader = new BufferedReader(new InputStreamReader(testStr));
- SvcLogicContext ctx = new SvcLogicContext();
-
- try {
- String testExpr = null;
-
- int testNum = 0;
- while ((testExpr = testsReader.readLine()) != null) {
- testExpr = testExpr.trim();
-
- if (testExpr.startsWith("#")) {
- testExpr = testExpr.substring(1).trim();
- String[] nameValue = testExpr.split("=");
- String name = nameValue[0].trim();
- String value = nameValue[1].trim();
-
- LOG.info("Setting context attribute " + name + " = "
- + value);
- ctx.setAttribute(name, value);
-
- } else {
-
- testNum++;
- String sqlStmt = testExpr;
- QueryStatus status = sqlResource.save("SQL", true, false, sqlStmt, null, "savetest"+testNum, ctx);
-
- switch (status) {
- case SUCCESS:
- LOG.info("Found data for query [" + sqlStmt + "]");
- break;
- case NOT_FOUND:
- LOG.info("Did not data for query [" + sqlStmt + "]");
- break;
- default:
- fail("Failure executing query [" + sqlStmt + "]");
-
- }
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail("Caught exception running tests");
- }
-
-
- testStr = getClass().getResourceAsStream("/query.tests");
- testsReader = new BufferedReader(new InputStreamReader(testStr));
-
- try {
- String testExpr = null;
-
- int testNum = 0;
- while ((testExpr = testsReader.readLine()) != null) {
- testExpr = testExpr.trim();
- if (testExpr.startsWith("#")) {
- testExpr = testExpr.substring(1).trim();
- String[] nameValue = testExpr.split("=");
- String name = nameValue[0].trim();
- String value = nameValue[1].trim();
-
- LOG.info("Setting context attribute " + name + " = "
- + value);
- ctx.setAttribute(name, value);
-
- } else {
-
- testNum++;
-
- String sqlStmt = testExpr;
- QueryStatus status = sqlResource.query("SQL", false, null,
- sqlStmt, "querytest" + testNum, null, ctx);
-
- switch (status) {
- case SUCCESS:
- LOG.info("Found data for query [" + sqlStmt + "]");
- break;
- case NOT_FOUND:
- LOG.info("Did not data for query [" + sqlStmt + "]");
- break;
- default:
- fail("Failure executing query [" + sqlStmt + "]");
-
- }
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail("Caught exception running tests");
- }
-
-
- testStr = getClass().getResourceAsStream("/delete.tests");
- testsReader = new BufferedReader(new InputStreamReader(testStr));
-
- try {
- String testExpr = null;
-
- int testNum = 0;
- while ((testExpr = testsReader.readLine()) != null) {
- testExpr = testExpr.trim();
- if (testExpr.startsWith("#")) {
- testExpr = testExpr.substring(1).trim();
- String[] nameValue = testExpr.split("=");
- String name = nameValue[0].trim();
- String value = nameValue[1].trim();
-
- LOG.info("Setting context attribute " + name + " = "
- + value);
- ctx.setAttribute(name, value);
-
- } else {
-
- testNum++;
-
- String sqlStmt = testExpr;
- QueryStatus status = sqlResource.delete("SQL", sqlStmt, ctx);
-
- switch (status) {
- case SUCCESS:
- LOG.info("Found data for query [" + sqlStmt + "]");
- break;
- case NOT_FOUND:
- LOG.info("Did not data for query [" + sqlStmt + "]");
- break;
- default:
- fail("Failure executing query [" + sqlStmt + "]");
-
- }
- }
- }
-
- } catch (Exception e) {
- e.printStackTrace();
- fail("Caught exception running tests");
- }
-
- for (String attrName : ctx.getAttributeKeySet()) {
- LOG.info("ctx.getAttribute("+attrName+") = "+ctx.getAttribute(attrName));
- }
- }
-
-}
diff --git a/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceProviderTest.java b/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceProviderTest.java
deleted file mode 100755
index b261b9f7d..000000000
--- a/sql-resource/provider/src/test/java/org/onap/ccsdk/sli/adaptors/resource/sql/SqlResourceProviderTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package org.onap.ccsdk.sli.adaptors.resource.sql;
-
-import static org.junit.Assert.assertNotNull;
-import java.lang.reflect.Field;
-import java.util.Map;
-import java.util.Properties;
-
-import org.junit.Test;
-
-public class SqlResourceProviderTest {
-
- private static SqlResourcePropertiesProvider provider;
- private static final String SDNC_CONFIG_DIR = "SDNC_CONFIG_DIR";
-
- @Test
- public void testSqlResourceProvider() {
- try{
- Map<String, String> env = System.getenv();
- Class<?> cl = env.getClass();
- Field field = cl.getDeclaredField("m");
- field.setAccessible(true);
- Map<String, String> writableEnv = (Map<String, String>) field.get(env);
- writableEnv.put(SDNC_CONFIG_DIR, "./src/test/resources");
- } catch (Exception e) {
- throw new IllegalStateException("Failed to set environment variable", e);
- }
-
- provider = new SqlResourcePropertiesProviderImpl();
- assertNotNull(provider);
- }
-
- @Test
- public void testGetProperties() {
- Properties properties = provider.getProperties();
- assertNotNull(properties);
- }
-
-}