added few test cases to TestSQLSaveQuery.java 83/57283/3
authorSandeep J <sandeejh@in.ibm.com>
Tue, 24 Jul 2018 10:06:31 +0000 (15:36 +0530)
committerPatrick Brady <pb071s@att.com>
Tue, 24 Jul 2018 20:02:49 +0000 (20:02 +0000)
added few test cases to increase code coverage

Issue-ID: APPC-1086
Change-Id: Id895923e0df4b55c7705534e971d67b972514e50
Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java

index b8e178f..b482eab 100644 (file)
@@ -5,7 +5,9 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
- * =============================================================================
+ * ================================================================================
+ * 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.
  * You may obtain a copy of the License at
@@ -27,6 +29,7 @@ import java.io.File;
 import java.io.IOException;
 
 import org.apache.commons.io.FileUtils;
+import static org.junit.Assert.assertEquals;
 import org.apache.commons.lang.StringEscapeUtils;
 import org.junit.Test;
 import org.slf4j.Logger;
@@ -57,6 +60,36 @@ public class TestSQLSaveQuery {
         }
 
     }
+    
+    @Test
+    public void testSQLSaveQueryForNestedRequestId() throws IOException{
+            String message = FileUtils.readFileToString(new File("src/test/resources/query/sampledata.txt"));
+            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        =  $log_message ;";
+            String resolvedContext = resolveCtxVars(key, ctx);
+            String expected="INSERT INTO CONFIG_TRANSACTION_LOG SET request_id = 'null' , message_type = 'request' , message = '' ;";
+            assertEquals(expected.trim(),resolvedContext.trim());
+    }
+    
+    @Test
+    public void testSQLSaveQueryForCryptKey() throws IOException{
+            String message = FileUtils.readFileToString(new File("src/test/resources/query/sampledata.txt"));
+            SvcLogicContext ctx = new SvcLogicContext();
+            ctx.setAttribute("request-id", "1234");
+            String escapedMessage = StringEscapeUtils.escapeSql(message);
+            ctx.setAttribute("log_message", escapedMessage);
+            ctx.setAttribute("ctxVarName", "test_crypt_key");
+            String key = "INSERT INTO CONFIG_TRANSACTION_LOG "
+                    + " SET request_id = $request-id , message_type  =  'request' ,  message        =  $CRYPT_KEY ;";
+            String resolvedContext = resolveCtxVars(key, ctx);
+            String expected="INSERT INTO CONFIG_TRANSACTION_LOG SET request_id = '1234' , message_type = 'request' , message = '' ;";
+            assertEquals(expected.trim(),resolvedContext.trim());
+       
+    }
 
     private String resolveCtxVars(String key, SvcLogicContext ctx) {
         if (key == null) {