aboutsummaryrefslogtreecommitdiffstats
path: root/appc-config/appc-data-services/provider/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'appc-config/appc-data-services/provider/src/test')
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java29
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java178
-rw-r--r--appc-config/appc-data-services/provider/src/test/resources/query/message3.txt0
-rw-r--r--appc-config/appc-data-services/provider/src/test/resources/query/sampledata.txt0
-rw-r--r--appc-config/appc-data-services/provider/src/test/resources/svclogic.properties33
5 files changed, 240 insertions, 0 deletions
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java
new file mode 100644
index 000000000..386b9f926
--- /dev/null
+++ b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestDGGeneralDBService.java
@@ -0,0 +1,29 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APP-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=========================================================
+ */
+
+
+import org.junit.Test;
+//Model JUNIT Class
+public class TestDGGeneralDBService {
+
+
+
+
+}
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java
new file mode 100644
index 000000000..995934933
--- /dev/null
+++ b/appc-config/appc-data-services/provider/src/test/java/org/openecomp/appc/data/services/db/TestSQLSaveQuery.java
@@ -0,0 +1,178 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APP-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.appc.data.services.db;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.commons.lang.StringUtils;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.openecomp.sdnc.sli.SvcLogicContext;
+
+public class TestSQLSaveQuery {
+
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestSQLSaveQuery.class);
+
+ private static String CRYPT_KEY = "";
+
+ //@Test
+ public void testSQLSaveQuery() {
+
+ try {
+ String message = FileUtils.readFileToString(new File("src/test/resources/query/sampledata.txt"));
+ System.out.println("TestSQLSaveQuery.testSQLSaveQuery()" + message);
+
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("request-id", "1234");
+
+ String escapedMessage = StringEscapeUtils.escapeSql(message);
+ ctx.setAttribute("log_message", escapedMessage);
+
+ //String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , message_type = 'request' , message = '" + escapedMessage + "' ;";
+ String key = "INSERT INTO CONFIG_TRANSACTION_LOG " + " SET request_id = $request-id , message_type = 'request' , message = $log_message ;";
+ System.out.println("Query : " + key);
+ String resolvedContext = resolveCtxVars(key, ctx);
+
+ System.out.println("Resolved : " + resolvedContext);
+
+ ctx.setAttribute("log_message", null);
+
+
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ }
+
+
+ private String resolveCtxVars(String key,
+ SvcLogicContext ctx) {
+ if (key == null) {
+ return (null);
+ }
+
+ if (key.startsWith("'") && key.endsWith("'")) {
+ key = key.substring(1, key.length() - 1);
+
+ LOG.debug("Stripped outer single quotes - key is now [" + key + "]");
+ }
+
+ String[] keyTerms = key.split("\\s+");
+
+ StringBuffer sqlBuffer = new StringBuffer();
+
+
+ for (int i = 0; i < keyTerms.length; i++) {
+ sqlBuffer.append(resolveTerm(keyTerms[i], ctx));
+ sqlBuffer.append(" ");
+ }
+
+
+ return (sqlBuffer.toString());
+ }
+
+
+ private String resolveTerm(String term, SvcLogicContext ctx) {
+ if (term == null) {
+ return (null);
+ }
+
+ LOG.debug("resolveTerm: term is " + term);
+
+ if (term.startsWith("$") && (ctx != null)) {
+ // Resolve any index variables.
+ /*
+ String value = term;
+ String resolved = resolveCtxVariable(term.substring(1), ctx);
+ if(resolved != null){
+ value = "'" +resolved+ "'";
+ }
+ System.out.println("Dollar Term : " + term + " Value :"+ value);
+ return value;
+*/
+ return ("'" + resolveCtxVariable(term.substring(1), ctx) + "'");
+
+ } else {
+ return (term);
+ }
+
+ }
+
+ private String resolveCtxVariable(String ctxVarName, SvcLogicContext ctx) {
+
+ if (ctxVarName.indexOf('[') == -1) {
+ // Ctx variable contains no arrays
+ if ("CRYPT_KEY".equals(ctxVarName)) {
+
+ // Handle crypt key as special case. If it's set as a context variable, use it. Otherwise, use
+ // configured crypt key.
+ String cryptKey = ctx.getAttribute(ctxVarName);
+ if ((cryptKey != null) && (cryptKey.length() > 0)) {
+ return(cryptKey);
+ } else {
+ return(CRYPT_KEY);
+ }
+
+ }
+ return (ctx.getAttribute(ctxVarName));
+ }
+
+ // Resolve any array references
+ StringBuffer sbuff = new StringBuffer();
+ String[] ctxVarParts = ctxVarName.split("\\[");
+ sbuff.append(ctxVarParts[0]);
+ for (int i = 1; i < ctxVarParts.length; i++) {
+ if (ctxVarParts[i].startsWith("$")) {
+ int endBracketLoc = ctxVarParts[i].indexOf("]");
+ if (endBracketLoc == -1) {
+ // Missing end bracket ... give up parsing
+ LOG.warn("Variable reference " + ctxVarName
+ + " seems to be missing a ']'");
+ return (ctx.getAttribute(ctxVarName));
+ }
+
+ String idxVarName = ctxVarParts[i].substring(1, endBracketLoc);
+ String remainder = ctxVarParts[i].substring(endBracketLoc);
+
+ sbuff.append("[");
+ sbuff.append(ctx.getAttribute(idxVarName));
+ sbuff.append(remainder);
+
+ } else {
+ // Index is not a variable reference
+ sbuff.append("[");
+ sbuff.append(ctxVarParts[i]);
+ }
+ }
+
+ return (ctx.getAttribute(sbuff.toString()));
+ }
+
+
+}
diff --git a/appc-config/appc-data-services/provider/src/test/resources/query/message3.txt b/appc-config/appc-data-services/provider/src/test/resources/query/message3.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/appc-config/appc-data-services/provider/src/test/resources/query/message3.txt
diff --git a/appc-config/appc-data-services/provider/src/test/resources/query/sampledata.txt b/appc-config/appc-data-services/provider/src/test/resources/query/sampledata.txt
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/appc-config/appc-data-services/provider/src/test/resources/query/sampledata.txt
diff --git a/appc-config/appc-data-services/provider/src/test/resources/svclogic.properties b/appc-config/appc-data-services/provider/src/test/resources/svclogic.properties
new file mode 100644
index 000000000..02867302d
--- /dev/null
+++ b/appc-config/appc-data-services/provider/src/test/resources/svclogic.properties
@@ -0,0 +1,33 @@
+###
+# ============LICENSE_START=======================================================
+# ONAP : APP-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=
+org.openecomp.sdnc.sli.jdbc.hosts=
+org.openecomp.sdnc.sli.jdbc.url=
+org.openecomp.sdnc.sli.jdbc.database=
+org.openecomp.sdnc.sli.jdbc.user=
+org.openecomp.sdnc.sli.jdbc.password=
+org.openecomp.sdnc.sli.jdbc.connection.name=
+
+org.openecomp.sdnc.sli.jdbc.connection.timeout=
+org.openecomp.sdnc.sli.jdbc.request.timeout=
+org.openecomp.sdnc.sli.jdbc.limit.init=
+org.openecomp.sdnc.sli.jdbc.limit.min=
+org.openecomp.sdnc.sli.jdbc.limit.max=