aboutsummaryrefslogtreecommitdiffstats
path: root/sql-resource/provider/src/test
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-02-15 14:59:20 -0500
committerDan Timoney <dtimoney@att.com>2017-02-15 15:02:52 -0500
commit09b58e1832480e9529124ae422f040028546daff (patch)
treebc9600d325250ff9ad18a7a0f78f81750bcad839 /sql-resource/provider/src/test
parent9e84a53855f414a71633d73d76a8438cb25e1b58 (diff)
Initial commit for OpenECOMP SDN-C adaptors
Change-Id: I8d42e44d15fd85aee5b00d27e45da6751dda02b9 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'sql-resource/provider/src/test')
-rw-r--r--sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java218
-rwxr-xr-xsql-resource/provider/src/test/resources/delete.tests2
-rwxr-xr-xsql-resource/provider/src/test/resources/query.tests5
-rwxr-xr-xsql-resource/provider/src/test/resources/save.tests13
-rw-r--r--sql-resource/provider/src/test/resources/simplelogger.properties22
-rw-r--r--sql-resource/provider/src/test/resources/svclogic.properties34
6 files changed, 294 insertions, 0 deletions
diff --git a/sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java b/sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java
new file mode 100644
index 0000000..afed810
--- /dev/null
+++ b/sql-resource/provider/src/test/java/org/openecomp/sdnc/sli/resource/sql/SqlResourceTest.java
@@ -0,0 +1,218 @@
+/*-
+ * ============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.openecomp.sdnc.sli.resource.sql;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.Enumeration;
+import java.util.Properties;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+import org.openecomp.sdnc.sli.SvcLogicResource.QueryStatus;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import junit.framework.TestCase;
+
+public class SqlResourceTest extends TestCase {
+
+ private static final Logger LOG = LoggerFactory
+ .getLogger(SqlResourceTest.class);
+
+
+ public void testExists() {
+
+
+ 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");
+ }
+
+ // 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();
+
+
+
+ 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/resources/delete.tests b/sql-resource/provider/src/test/resources/delete.tests
new file mode 100755
index 0000000..a60a3bc
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/delete.tests
@@ -0,0 +1,2 @@
+DROP TABLE SQLRESOURCE_ORDER;
+DROP TABLE SQLRESOURCE_ORDER_ITEM;
diff --git a/sql-resource/provider/src/test/resources/query.tests b/sql-resource/provider/src/test/resources/query.tests
new file mode 100755
index 0000000..ec05c22
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/query.tests
@@ -0,0 +1,5 @@
+# max-price = 100
+SELECT * FROM SQLRESOURCE_ORDER where placed_on < now();
+SELECT SQLRESOURCE_ORDER.order_number, clli, service, price FROM SQLRESOURCE_ORDER, SQLRESOURCE_ORDER_ITEM where SQLRESOURCE_ORDER.order_number = SQLRESOURCE_ORDER_ITEM.order_number and price > $max-price ;
+SELECT SQLRESOURCE_ORDER.order_number, clli, service, price FROM SQLRESOURCE_ORDER, SQLRESOURCE_ORDER_ITEM where SQLRESOURCE_ORDER.order_number = SQLRESOURCE_ORDER_ITEM.order_number and price < $max-price ;
+SELECT SQLRESOURCE_ORDER.order_number AS ordernum, clli, service, price FROM SQLRESOURCE_ORDER, SQLRESOURCE_ORDER_ITEM where SQLRESOURCE_ORDER.order_number = SQLRESOURCE_ORDER_ITEM.order_number and price < $max-price ;
diff --git a/sql-resource/provider/src/test/resources/save.tests b/sql-resource/provider/src/test/resources/save.tests
new file mode 100755
index 0000000..e2c4221
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/save.tests
@@ -0,0 +1,13 @@
+# order-number = 1234
+# zero = 0
+# item[0].clli = MTJNJA14
+# item[0].service = NoD
+# item[0].price = 1000000
+# item[1].clli = MTJNJA14
+# item[1].service = Pizza
+# item[1].price = 10
+CREATE TABLE IF NOT EXISTS SQLRESOURCE_ORDER (order_number VARCHAR(40), placed_on TIMESTAMP);
+CREATE TABLE IF NOT EXISTS SQLRESOURCE_ORDER_ITEM (order_number VARCHAR(40), clli VARCHAR(40), service VARCHAR(40), price INTEGER(4));
+INSERT INTO SQLRESOURCE_ORDER VALUES ( $order-number , now());
+INSERT INTO SQLRESOURCE_ORDER_ITEM VALUES( $order-number , $item[$zero].clli , $item[0].service , $item[0].price );
+INSERT INTO SQLRESOURCE_ORDER_ITEM VALUES( $order-number , $item[1].clli , $item[1].service , $item[1].price );
diff --git a/sql-resource/provider/src/test/resources/simplelogger.properties b/sql-resource/provider/src/test/resources/simplelogger.properties
new file mode 100644
index 0000000..68ced84
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/simplelogger.properties
@@ -0,0 +1,22 @@
+###
+# ============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=========================================================
+###
+
+org.slf4j.simpleLogger.defaultLogLevel=debug
diff --git a/sql-resource/provider/src/test/resources/svclogic.properties b/sql-resource/provider/src/test/resources/svclogic.properties
new file mode 100644
index 0000000..a1b5fb7
--- /dev/null
+++ b/sql-resource/provider/src/test/resources/svclogic.properties
@@ -0,0 +1,34 @@
+###
+# ============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=========================================================
+###
+
+org.openecomp.sdnc.sli.dbtype=jdbc
+org.openecomp.sdnc.sli.jdbc.hosts=localhost
+org.openecomp.sdnc.sli.jdbc.url=jdbc:mysql://DBHOST:3306/sdnctl
+org.openecomp.sdnc.sli.jdbc.database=sdnctl
+org.openecomp.sdnc.sli.jdbc.user=sdnctl
+org.openecomp.sdnc.sli.jdbc.password=gamma
+org.openecomp.sdnc.sli.jdbc.connection.name=sdnctldb01
+
+org.openecomp.sdnc.sli.jdbc.connection.timeout=50
+org.openecomp.sdnc.sli.jdbc.request.timeout=100
+org.openecomp.sdnc.sli.jdbc.limit.init=10
+org.openecomp.sdnc.sli.jdbc.limit.min=10
+org.openecomp.sdnc.sli.jdbc.limit.max=20