diff options
author | Sandeep J <sandeejh@in.ibm.com> | 2018-07-24 15:36:31 +0530 |
---|---|---|
committer | Patrick Brady <pb071s@att.com> | 2018-07-24 20:02:49 +0000 |
commit | a443497c24c45341b8c7090aa43488695c81e75a (patch) | |
tree | 9137bd8a1d3d62a9d7c4209a5f24ba9988bfafb1 /appc-config | |
parent | c3ff14a466ef3197d680658820a9044865f6a384 (diff) |
added few test cases to TestSQLSaveQuery.java
added few test cases to increase code coverage
Issue-ID: APPC-1086
Change-Id: Id895923e0df4b55c7705534e971d67b972514e50
Signed-off-by: Sandeep J <sandeejh@in.ibm.com>
Diffstat (limited to 'appc-config')
-rw-r--r-- | appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java index b8e178ff8..b482eab0b 100644 --- a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java +++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/db/TestSQLSaveQuery.java @@ -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) { |