From b5fe8a69e90b950c07dc11af481eab7e9bab52c6 Mon Sep 17 00:00:00 2001 From: "Dunietz, Irwin" Date: Thu, 16 Jan 2020 15:13:14 -0500 Subject: Change code in appc dispatcher for new LCMs in R6 Also introduce some minor improvements to robustness, efficiency, & formatting. Issue-ID: APPC-1789 Signed-off-by: Dunietz, Irwin Change-Id: I82d970c2f7cde6c8dab1222af86ea70ce93b7e50 --- .../appc/dao/util/AppcDatabaseConnectionPool.java | 11 +- .../appc/dao/util/api/DBConnectionPoolService.java | 15 +- .../onap/appc/dao/util/dbcp/DBConnectionPool.java | 26 +-- .../dao/util/AppcDatabaseConnectionPoolTest.java | 7 +- .../appc/dao/util/dbcp/DBConnectionPoolTest.java | 12 +- .../appc/domainmodel/lcm/TestRequestContext.java | 35 ++- .../impl/TransactionRecorderImpl.java | 252 +++++++++++---------- .../impl/TransactionRecorderImplTest.java | 218 +++++++++--------- 8 files changed, 287 insertions(+), 289 deletions(-) (limited to 'appc-dispatcher/appc-dispatcher-common') diff --git a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/AppcDatabaseConnectionPool.java b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/AppcDatabaseConnectionPool.java index 1f4a75911..2a1484c2d 100644 --- a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/AppcDatabaseConnectionPool.java +++ b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/AppcDatabaseConnectionPool.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -19,7 +19,6 @@ * 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========================================================= */ @@ -41,8 +40,8 @@ import java.util.Map; * This class implements * * @see org.onap.appc.dao.util.dbcp.DBConnectionPool - * that provides concrete implemenation of accessing appc database which basic setup - * data would be got from global configuration. + * that provides a concrete implementation of appc database access + * with basic setup data extracted from the global configuration. * @see org.onap.appc.configuration.Configuration *

* The singleton instance of this class has been instantiated by blueprint. @@ -88,8 +87,8 @@ public class AppcDatabaseConnectionPool implements DBConnectionPoolService { try { connection = dbConnectionPool.getConnection(); } catch (DBConnectionPoolException e) { - logger.error("DB connection pool is created failed." + - "Please make sure the provided information is correct."); + logger.error("DB connection pool creation failed." + + " Please make sure the provided information is correct."); } if (connection != null) { diff --git a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/api/DBConnectionPoolService.java b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/api/DBConnectionPoolService.java index 6f51fec3c..0a163544d 100644 --- a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/api/DBConnectionPoolService.java +++ b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/api/DBConnectionPoolService.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP : APPC * ================================================================================ - * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs * ================================================================================ @@ -11,15 +11,14 @@ * 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========================================================= */ @@ -45,10 +44,10 @@ import java.util.Map; *

  * {@code
  * private AppcDatabaseConnectionPool pool;
- * public void setAppcDatabaseConnectionPool(AppcDatabaseConnectionPool pool){
+ * public void setAppcDatabaseConnectionPool(AppcDatabaseConnectionPool pool) {
  *     this.pool = pool;
  * }
- * public queryAppcDatabase(AppcDatabaseConnectionPool pool){
+ * public queryAppcDatabase(AppcDatabaseConnectionPool pool) {
  *      Connection connection = null;
  *      try {
  *          connection = pool.getConnection();
@@ -64,11 +63,11 @@ import java.util.Map;
  *            System.out.println("# of entries in db:");
  *            int numcols = rs.getMetaData().getColumnCount();
  *            System.out.println(pool.getDataSourceStatus());
- *      }catch (SQLException e) {
+ *      } catch (SQLException e) {
  *          e.printStackTrace();
  *      } finally {
  *          try {
- *               pool.close(rs, stmt, conn);
+ *              pool.close(rs, stmt, conn);
  *              } catch (DataAccessException e) {
  *                  e.printStackTrace();
  *              }
diff --git a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/dbcp/DBConnectionPool.java b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/dbcp/DBConnectionPool.java
index d201f399c..5381721ea 100644
--- a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/dbcp/DBConnectionPool.java
+++ b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/dbcp/DBConnectionPool.java
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * ================================================================================
@@ -11,15 +11,14 @@
  * 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=========================================================
  */
 
@@ -63,11 +62,10 @@ public class DBConnectionPool implements DBConnectionPoolService {
         this(connectURI, username, password, driverClass, null, null, null, null, null);
     }
 
-    public DBConnectionPool(String connectURI, String username, String password,
-                            String driverClass, Integer initialSize, Integer maxActive,
-                            Integer maxIdle, Integer maxWait, Integer minIdle) {
+    public DBConnectionPool(String connectURI, String username, String password, String driverClass,
+            Integer initialSize, Integer maxActive, Integer maxIdle, Integer maxWait, Integer minIdle) {
         this.dataSource = getBasicDataSource(connectURI, username, password, driverClass,
-            initialSize, maxActive, maxIdle, maxWait, minIdle);
+                initialSize, maxActive, maxIdle, maxWait, minIdle);
     }
 
     /**
@@ -87,8 +85,8 @@ public class DBConnectionPool implements DBConnectionPoolService {
             throw new DBConnectionPoolException(e);
         }
 
-        if(connection == null){
-            //
+        if (connection == null) {
+            // Don't necessarily know why, but can report. . . .
             throw new DBConnectionPoolException("Connection was not created");
         }
 
@@ -125,8 +123,8 @@ public class DBConnectionPool implements DBConnectionPoolService {
     }
 
     protected BasicDataSource getBasicDataSource(String connectURI, String username, String password,
-                                               String driverClass, Integer initialSize, Integer maxtotal,
-                                               Integer maxIdle, Integer maxWaitMillis, Integer minIdle) {
+            String driverClass, Integer initialSize, Integer maxTotal, Integer maxIdle, Integer maxWaitMillis,
+            Integer minIdle) {
         BasicDataSource dataSource = new BasicDataSource();
         dataSource.setDriverClassName(driverClass);
         dataSource.setUsername(username);
@@ -136,8 +134,8 @@ public class DBConnectionPool implements DBConnectionPoolService {
         if (initialSize != null) {
             dataSource.setInitialSize(initialSize);
         }
-        if (maxtotal != null) {
-            dataSource.setMaxTotal(maxtotal);
+        if (maxTotal != null) {
+            dataSource.setMaxTotal(maxTotal);
         }
         if (maxIdle != null) {
             dataSource.setMaxIdle(maxIdle);
diff --git a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/AppcDatabaseConnectionPoolTest.java b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/AppcDatabaseConnectionPoolTest.java
index ad1b4ea0f..98ef98ab8 100644
--- a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/AppcDatabaseConnectionPoolTest.java
+++ b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/AppcDatabaseConnectionPoolTest.java
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * ================================================================================
@@ -19,7 +19,6 @@
  * 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=========================================================
  */
 
@@ -106,8 +105,8 @@ public class AppcDatabaseConnectionPoolTest {
 
     @Test
     public void testArgumentConstructor() {
-        AppcDatabaseConnectionPool appcDatabaseConnectionPool = new AppcDatabaseConnectionPool(dbUrl, username,
-            password, driver);
+        AppcDatabaseConnectionPool appcDatabaseConnectionPool =
+                new AppcDatabaseConnectionPool(dbUrl, username, password, driver);
         Object dbConnectionPool = Whitebox.getInternalState(appcDatabaseConnectionPool, "dbConnectionPool");
         Assert.assertNotNull(dbConnectionPool);
     }
diff --git a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/dbcp/DBConnectionPoolTest.java b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/dbcp/DBConnectionPoolTest.java
index d2ac778a4..a26f8c037 100644
--- a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/dbcp/DBConnectionPoolTest.java
+++ b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/test/java/org/onap/appc/dao/util/dbcp/DBConnectionPoolTest.java
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP : APPC
  * ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * ================================================================================
@@ -11,15 +11,14 @@
  * 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=========================================================
  */
 
@@ -39,7 +38,6 @@ import java.sql.Connection;
 import java.sql.SQLException;
 import java.util.Map;
 
-
 public class DBConnectionPoolTest {
     private final String connectURI = "jdbc:h2:mem:~/test;MODE=MYSQL;DB_CLOSE_DELAY=-1";
     private final String username = "sa";
@@ -104,8 +102,8 @@ public class DBConnectionPoolTest {
 
     @Test
     public void testShutdownException() throws SQLException {
-        DBConnectionPool dbcpSpy = Mockito.spy(new DBConnectionPool(connectURI, username, password, driverClass,
-                0, 0, 0, 0, 0));
+        DBConnectionPool dbcpSpy =
+                Mockito.spy(new DBConnectionPool(connectURI, username, password, driverClass, 0, 0, 0, 0, 0));
         BasicDataSource mockDataSource = Mockito.mock(BasicDataSource.class);
         Mockito.doThrow(new SQLException()).when(mockDataSource).close();
         Whitebox.setInternalState(dbcpSpy, "dataSource", mockDataSource);
diff --git a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/test/java/org/onap/appc/domainmodel/lcm/TestRequestContext.java b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/test/java/org/onap/appc/domainmodel/lcm/TestRequestContext.java
index 4df409995..7d56ab732 100644
--- a/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/test/java/org/onap/appc/domainmodel/lcm/TestRequestContext.java
+++ b/appc-dispatcher/appc-dispatcher-common/domain-model-lib/src/test/java/org/onap/appc/domainmodel/lcm/TestRequestContext.java
@@ -6,6 +6,8 @@
 *=================================================================================
 * Modifications Copyright 2018 IBM.
 *=================================================================================
+* Modifications Copyright 2019 AT&T Intellectual Property
+*=================================================================================
 * 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
@@ -42,26 +44,26 @@ public class TestRequestContext {
     @Test
     public void testGetActionLevel_ValidEnumConstant() {
         requestContext.setActionLevel(ActionLevel.VM);
-        Assert.assertNotNull(requestContext. getActionLevel());
-        Assert.assertEquals(requestContext. getActionLevel(),ActionLevel.VM);
+        Assert.assertNotNull(requestContext.getActionLevel());
+        Assert.assertEquals(requestContext.getActionLevel(), ActionLevel.VM);
     }
 
     @Test
     public void testgetAdditionalContext() {
-        testadditionalContext=new HashMap();
+        testadditionalContext = new HashMap();
         testadditionalContext.put("A", "a");
         requestContext.setAdditionalContext(testadditionalContext);
         Assert.assertNotNull(requestContext.getAdditionalContext());
         Assert.assertTrue(requestContext.getAdditionalContext().containsKey("A"));
         Assert.assertTrue(requestContext.getAdditionalContext().containsValue("a"));
     }
-    
+
     @Test
     public void testAddKeyValueToAdditionalContext() {
-        String key="key1";
-        String value="value1";
+        String key = "key1";
+        String value = "value1";
         requestContext.addKeyValueToAdditionalContext(key, value);
-        Map additionalContext= requestContext.getAdditionalContext();
+        Map additionalContext = requestContext.getAdditionalContext();
         Assert.assertEquals("value1", additionalContext.get("key1"));
     }
 
@@ -82,27 +84,24 @@ public class TestRequestContext {
     public void testToString_ContainsString() {
         assertTrue(requestContext.toString().contains("RequestContext{commonHeader"));
     }
-    
+
     @Test
-    public void testGetSetCommonHeader()
-    {
+    public void testGetSetCommonHeader() {
         CommonHeader commonHeader = new CommonHeader();
         requestContext.setCommonHeader(commonHeader);
         assertEquals(commonHeader, requestContext.getCommonHeader());
     }
-    
+
     @Test
-    public void testGetSetActionIdentifiers()
-    {
-        ActionIdentifiers actionIdentifiers= new ActionIdentifiers();
+    public void testGetSetActionIdentifiers() {
+        ActionIdentifiers actionIdentifiers = new ActionIdentifiers();
         requestContext.setActionIdentifiers(actionIdentifiers);
         assertEquals(actionIdentifiers, requestContext.getActionIdentifiers());
     }
-    
+
     @Test
-    public void testGetSetAction()
-    {
-        VNFOperation action= VNFOperation.ActionStatus;
+    public void testGetSetAction() {
+        VNFOperation action = VNFOperation.ActionStatus;
         requestContext.setAction(action);
         assertEquals(action, requestContext.getAction());
     }
diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java
index 15ed9ad4b..0acb2b5a0 100644
--- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java
+++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java
@@ -19,7 +19,6 @@
  * 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=========================================================
  */
 
@@ -37,17 +36,17 @@ import org.onap.ccsdk.sli.core.dblib.DbLibService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import javax.sql.rowset.CachedRowSet;
 import java.sql.SQLException;
+import javax.sql.rowset.CachedRowSet;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.Instant;
 import java.time.ZoneOffset;
 import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Map;
-import java.time.temporal.ChronoUnit;
 
 import static org.onap.appc.transactionrecorder.objects.TransactionConstants.TRANSACTION_ATTRIBUTES.*;
 import static org.onap.appc.transactionrecorder.objects.TransactionConstants.*;
@@ -74,44 +73,41 @@ public class TransactionRecorderImpl implements TransactionRecorder {
      */
     @Override
     public void store(TransactionRecord record) throws APPCException {
-        if (logger.isTraceEnabled()) {
-            logger.trace("Transaction data insertion into DB");
-        }
-        final String STORE_DATE_QUERY = TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS +
-            "(" + TRANSACTION_ID.getColumnName() + TransactionConstants.COMMA +
-            ORIGIN_TIMESTAMP.getColumnName() + TransactionConstants.COMMA +
-            REQUEST_ID.getColumnName() + TransactionConstants.COMMA +
-            SUBREQUEST_ID.getColumnName() + TransactionConstants.COMMA +
-            ORIGINATOR_ID.getColumnName() + TransactionConstants.COMMA +
-            START_TIME.getColumnName() + TransactionConstants.COMMA +
-            END_TIME.getColumnName() + TransactionConstants.COMMA +
-            TARGET_ID.getColumnName() + TransactionConstants.COMMA +
-            TARGET_TYPE.getColumnName() + TransactionConstants.COMMA +
-            OPERATION.getColumnName() + TransactionConstants.COMMA +
-            RESULT_CODE.getColumnName() + TransactionConstants.COMMA +
-            DESCRIPTION.getColumnName() + TransactionConstants.COMMA +
-            STATE.getColumnName() + TransactionConstants.COMMA +
-            SERVICE_INSTANCE_ID + TransactionConstants.COMMA +
-            VNFC_NAME + TransactionConstants.COMMA +
-            VSERVER_ID + TransactionConstants.COMMA +
-            VF_MODULE_ID + TransactionConstants.COMMA +
-            MODE + ") " +
-            "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
+        logger.trace("Transaction data insertion into DB");
+        final String STORE_DATE_QUERY =
+                TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS
+                + "(" + TRANSACTION_ID.getColumnName() + TransactionConstants.COMMA
+                + ORIGIN_TIMESTAMP.getColumnName() + TransactionConstants.COMMA
+                + REQUEST_ID.getColumnName() + TransactionConstants.COMMA
+                + SUBREQUEST_ID.getColumnName() + TransactionConstants.COMMA
+                + ORIGINATOR_ID.getColumnName() + TransactionConstants.COMMA
+                + START_TIME.getColumnName() + TransactionConstants.COMMA
+                + END_TIME.getColumnName() + TransactionConstants.COMMA
+                + TARGET_ID.getColumnName() + TransactionConstants.COMMA
+                + TARGET_TYPE.getColumnName() + TransactionConstants.COMMA
+                + OPERATION.getColumnName() + TransactionConstants.COMMA
+                + RESULT_CODE.getColumnName() + TransactionConstants.COMMA
+                + DESCRIPTION.getColumnName() + TransactionConstants.COMMA
+                + STATE.getColumnName() + TransactionConstants.COMMA
+                + SERVICE_INSTANCE_ID + TransactionConstants.COMMA
+                + VNFC_NAME + TransactionConstants.COMMA
+                + VSERVER_ID + TransactionConstants.COMMA
+                + VF_MODULE_ID + TransactionConstants.COMMA
+                + MODE + ") "
+                + "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
         try {
             dbLibService.writeData(STORE_DATE_QUERY, prepareArguments(record), SCHEMA);
         } catch (SQLException e) {
             logger.error("Error on storing record " + record.toString(), e);
             throw new APPCException(ERROR_ACCESSING_DATABASE, e);
         }
-        if (logger.isTraceEnabled()) {
-            logger.trace("Transaction Data Inserted Successfully into DB");
-        }
+        logger.trace("Transaction Data Inserted Successfully into DB");
     }
 
     @Override
     public void update(String key,
-                       String requestId,
-                       Map updateColumns) throws APPCException {
+            String requestId,
+            Map updateColumns) throws APPCException {
         logger.debug("Inside update in TransactionRecorderImpl");
 
         if (appcInstanceId != null && checkIfNullInstanceEntryExist(key, requestId)) {
@@ -151,15 +147,12 @@ public class TransactionRecorderImpl implements TransactionRecorder {
             logger.error("Error in updating records in updateTransactionEntry " + e);
             throw new APPCException(ERROR_ACCESSING_DATABASE, e);
         }
-        if (logger.isTraceEnabled()) {
-            logger.trace("Transaction data updated successfully");
-        }
-
+        logger.trace("Transaction data updated successfully");
     }
 
     private void updateNullInstanceEntry(String key,
-                                         String requestId,
-                                         Map updateColumns) throws APPCException {
+            String requestId,
+            Map updateColumns) throws APPCException {
         logger.debug("Inside updateNullInstanceEntry");
 
         ArrayList values = new ArrayList<>();
@@ -180,7 +173,7 @@ public class TransactionRecorderImpl implements TransactionRecorder {
             if (logger.isDebugEnabled()) {
                 logger.debug("Before updating Transaction table the Query is: " + query);
                 for (String value : values) {
-                        logger.debug("Value for Transaction table: " + value);
+                    logger.debug("Value for Transaction table: " + value);
                 }
             }
             Boolean result = dbLibService.writeData(query, values, SCHEMA);
@@ -195,24 +188,24 @@ public class TransactionRecorderImpl implements TransactionRecorder {
 
     private boolean checkIfNullInstanceEntryExist(String key, String requestId) throws APPCException {
         logger.debug("Entered checkIfNullInstanceEntryExist");
-        String nullInstanceCheckQuery = new String("SELECT COUNT(*) as ROWCOUNT  FROM " +
-            TransactionConstants.TRANSACTIONS + WHERE +
-            TRANSACTION_ID.getColumnName() + " = ? AND " +
-            REQUEST_ID.getColumnName() + " = ? ");
+        String nullInstanceCheckQuery = new String(
+                "SELECT COUNT(*) as ROWCOUNT  FROM "
+                + TransactionConstants.TRANSACTIONS + WHERE
+                + TRANSACTION_ID.getColumnName() + " = ? AND "
+                + REQUEST_ID.getColumnName() + " = ? ");
 
         ArrayList nullInstanceCheckParams = new ArrayList<>();
         nullInstanceCheckParams.add(null + "~" + key);
         nullInstanceCheckParams.add(requestId);
 
-        try{
-            CachedRowSet rowSet = dbLibService.getData(nullInstanceCheckQuery, nullInstanceCheckParams, SCHEMA);
+        try (CachedRowSet rowSet = dbLibService.getData(nullInstanceCheckQuery, nullInstanceCheckParams, SCHEMA)) {
             int noRows = 0;
             if (rowSet != null && rowSet.first()) {
                 noRows = rowSet.getInt("ROWCOUNT");
-                logger.info("No of Rows in Transactions Table with TRANSACTION_ID: " +
-                            null + "~" + key + " and REQUEST_ID " + requestId + " is: " + noRows);
+                logger.info("No of Rows in Transactions Table with TRANSACTION_ID: "
+                            + null + "~" + key + " and REQUEST_ID " + requestId + " is: " + noRows);
             }
-            if(noRows > 0)
+            if (noRows > 0)
                 return true;
         } catch (SQLException e) {
             logger.error("Error in checkIfNullInstanceEntryExist in the transaction table", e);
@@ -223,14 +216,12 @@ public class TransactionRecorderImpl implements TransactionRecorder {
 
     @Override
     public void markTransactionsAborted(String appcInstanceId) {
-        if (logger.isTraceEnabled()) {
-            logger.trace("marking in progress transactions to aborted");
-        }
+        logger.trace("marking in progress transactions to aborted");
         final String updateQuery =
-            "UPDATE " + TransactionConstants.TRANSACTIONS +
-                " SET " + STATE.getColumnName() + " = '" + RequestStatus.ABORTED.name() + "',"
-                        + END_TIME.getColumnName() + " = ? " +
-                WHERE + TRANSACTION_ID.getColumnName() + " LIKE '" + appcInstanceId + "%'  AND "
+                "UPDATE " + TransactionConstants.TRANSACTIONS
+                + " SET " + STATE.getColumnName() + " = '" + RequestStatus.ABORTED.name() + "',"
+                + END_TIME.getColumnName() + " = ? "
+                + WHERE + TRANSACTION_ID.getColumnName() + " LIKE '" + appcInstanceId + "%'  AND "
                 + STATE.getColumnName() + " in (?,?)";
 
         if (logger.isDebugEnabled()) {
@@ -248,19 +239,18 @@ public class TransactionRecorderImpl implements TransactionRecorder {
             logger.error(message);
             throw new RuntimeException(message, e);
         }
-        if (logger.isTraceEnabled()) {
-            logger.trace("In progress transactions marked aborted");
-        }
+        logger.trace("In progress transactions marked aborted");
     }
 
     @Override
     public List getInProgressRequests(TransactionRecord record, int interval) throws APPCException {
 
-        String IN_PROGRESS_REQUESTS_QUERY = "SELECT * FROM " +
-            TransactionConstants.TRANSACTIONS + WHERE +
-            TARGET_ID + " = ? AND " +
-            STATE.getColumnName() + " IN (?,?) AND " +
-            START_TIME.getColumnName() + " < ?";
+        String IN_PROGRESS_REQUESTS_QUERY =
+                "SELECT * FROM "
+                + TransactionConstants.TRANSACTIONS + WHERE
+                + TARGET_ID + " = ? AND "
+                + STATE.getColumnName() + " IN (?,?) AND "
+                + START_TIME.getColumnName() + " < ?";
 
         ArrayList inProgressQueryParams = new ArrayList<>();
         Instant window = record.getStartTime().minus(interval, ChronoUnit.HOURS);
@@ -273,37 +263,40 @@ public class TransactionRecorderImpl implements TransactionRecorder {
             inProgressQueryParams.add(dateToStringConverterMillis(window));
         }
 
-        try (CachedRowSet rowSet = dbLibService.getData(IN_PROGRESS_REQUESTS_QUERY, inProgressQueryParams, SCHEMA)) {
+        try (CachedRowSet rowSet =
+                dbLibService.getData(IN_PROGRESS_REQUESTS_QUERY, inProgressQueryParams, SCHEMA)) {
             List inProgressRecords = new ArrayList<>();
             TransactionRecord transaction;
-            while (rowSet.next()) {
-                transaction = new TransactionRecord();
-                transaction.setTransactionId(rowSet.getString(TRANSACTION_ID.getColumnName()));
-                transaction.setRequestId(rowSet.getString(REQUEST_ID.getColumnName()));
-                transaction.setSubRequestId(rowSet.getString(SUBREQUEST_ID.getColumnName()));
-                transaction.setOriginatorId(rowSet.getString(ORIGINATOR_ID.getColumnName()));
-                transaction.setStartTime(stringToDateConverterMillis(rowSet.getString(START_TIME.getColumnName())));
-                transaction.setTargetId(rowSet.getString(TARGET_ID.getColumnName()));
-                transaction.setTargetType(rowSet.getString(TARGET_TYPE.getColumnName()));
-                transaction.setOperation(VNFOperation.valueOf(rowSet.getString(OPERATION.getColumnName())));
-                transaction.setRequestState(RequestStatus.valueOf(rowSet.getString(STATE.getColumnName())));
-                transaction.setVnfcName(rowSet.getString(VNFC_NAME.getColumnName()));
-                transaction.setVserverId(rowSet.getString(VSERVER_ID.getColumnName()));
-                transaction.setVfModuleId(rowSet.getString(VF_MODULE_ID.getColumnName()));
-                transaction.setServiceInstanceId(rowSet.getString(SERVICE_INSTANCE_ID.getColumnName()));
-                transaction.setMode(Flags.Mode.valueOf(rowSet.getString(MODE.getColumnName())));
-                inProgressRecords.add(transaction);
-            }
-            if (logger.isTraceEnabled()) {
-                logger.trace("In progress transaction records fetched from database successfully.");
+            int count = 0;
+            if (rowSet != null) {
+                for (; rowSet.next(); ++count) {
+                    transaction = new TransactionRecord();
+                    transaction.setTransactionId(rowSet.getString(TRANSACTION_ID.getColumnName()));
+                    transaction.setRequestId(rowSet.getString(REQUEST_ID.getColumnName()));
+                    transaction.setSubRequestId(rowSet.getString(SUBREQUEST_ID.getColumnName()));
+                    transaction.setOriginatorId(rowSet.getString(ORIGINATOR_ID.getColumnName()));
+                    transaction.setStartTime(stringToDateConverterMillis(rowSet.getString(START_TIME.getColumnName())));
+                    transaction.setTargetId(rowSet.getString(TARGET_ID.getColumnName()));
+                    transaction.setTargetType(rowSet.getString(TARGET_TYPE.getColumnName()));
+                    transaction.setOperation(VNFOperation.valueOf(rowSet.getString(OPERATION.getColumnName())));
+                    transaction.setRequestState(RequestStatus.valueOf(rowSet.getString(STATE.getColumnName())));
+                    transaction.setVnfcName(rowSet.getString(VNFC_NAME.getColumnName()));
+                    transaction.setVserverId(rowSet.getString(VSERVER_ID.getColumnName()));
+                    transaction.setVfModuleId(rowSet.getString(VF_MODULE_ID.getColumnName()));
+                    transaction.setServiceInstanceId(rowSet.getString(SERVICE_INSTANCE_ID.getColumnName()));
+                    transaction.setMode(Flags.Mode.valueOf(rowSet.getString(MODE.getColumnName())));
+                    inProgressRecords.add(transaction);
+                }
             }
+            logger.trace(String.valueOf(count)
+                         + " in progress transaction records fetched from database successfully.");
             return inProgressRecords;
         } catch (ParseException e) {
             logger.error("Error parsing start date during fetching in progress records ", e);
             throw new APPCException(ERROR_ACCESSING_DATABASE, e);
         } catch (SQLException e) {
-            logger.error("Error fetching in progress records for Transaction ID = " + appcInstanceId + "~" + record
-                .getTransactionId(), e);
+            logger.error("Error fetching in progress records for Transaction ID = " + appcInstanceId + "~"
+                         + record.getTransactionId(), e);
             throw new APPCException(ERROR_ACCESSING_DATABASE, e);
         }
     }
@@ -311,12 +304,12 @@ public class TransactionRecorderImpl implements TransactionRecorder {
     @Override
     public Boolean isTransactionDuplicate(TransactionRecord record) throws APPCException {
 
-        StringBuilder duplicateRequestCheckQuery = new StringBuilder("SELECT " +
-            TRANSACTION_ID.getColumnName() + " FROM " +
-            TransactionConstants.TRANSACTIONS + WHERE +
-            TRANSACTION_ID.getColumnName() + " <> ? AND " +
-            REQUEST_ID.getColumnName() + " = ? AND " +
-            STATE.getColumnName() + " IN(?,?) ");
+        StringBuilder duplicateRequestCheckQuery = new StringBuilder()
+                .append("SELECT ").append(TRANSACTION_ID.getColumnName()).append(" FROM ")
+                .append(TransactionConstants.TRANSACTIONS).append(WHERE)
+                .append(TRANSACTION_ID.getColumnName()).append(" <> ? AND ")
+                .append(REQUEST_ID.getColumnName()).append(" = ? AND ")
+                .append(STATE.getColumnName()).append(" IN(?,?) ");
 
         ArrayList duplicateCheckParams = new ArrayList<>();
         duplicateCheckParams.add(appcInstanceId + "~" + record.getTransactionId());
@@ -339,35 +332,37 @@ public class TransactionRecorderImpl implements TransactionRecorder {
         if (logger.isDebugEnabled()) {
             logger.debug(duplicateRequestCheckQuery.toString());
         }
-        try (CachedRowSet rowSet = dbLibService.getData(duplicateRequestCheckQuery.toString(), duplicateCheckParams,
-            SCHEMA)) {
-            if (rowSet.first()) {
+        try (CachedRowSet rowSet =
+                dbLibService.getData(duplicateRequestCheckQuery.toString(), duplicateCheckParams, SCHEMA)) {
+            if (rowSet != null && rowSet.first()) {
                 String transactionId = rowSet.getString(TRANSACTION_ID.getColumnName());
                 if (logger.isErrorEnabled()) {
-                    logger.error("Duplicate request found. Transaction ID " + transactionId + " is currently in " +
-                        "progress.");
+                    logger.error("Duplicate request found. Transaction ID " + transactionId
+                            + " is currently in progress.");
                 }
                 return true;
             }
             return false;
         } catch (SQLException e) {
-            logger.error("Error checking duplicate records for Transaction ID = " + appcInstanceId + "~" + record
-                .getTransactionId(), e);
+            logger.error("Error checking duplicate records for Transaction ID = " + appcInstanceId + "~"
+                    + record.getTransactionId(), e);
             throw new APPCException(ERROR_ACCESSING_DATABASE, e);
         }
     }
 
     @Override
     public Integer getInProgressRequestsCount() throws APPCException {
-        final String inProgressRequestCountQuery = "SELECT COUNT(*) as VALUE FROM "
-            + TransactionConstants.TRANSACTIONS
-            + WHERE + STATE.getColumnName() + " IN (?,?) ";
+        final String inProgressRequestCountQuery =
+                "SELECT COUNT(*) as VALUE FROM "
+                + TransactionConstants.TRANSACTIONS
+                + WHERE + STATE.getColumnName() + " IN (?,?) ";
 
         ArrayList checkInProgressParams = new ArrayList<>();
         checkInProgressParams.add(RequestStatus.RECEIVED.name());
         checkInProgressParams.add(RequestStatus.ACCEPTED.name());
-        try(CachedRowSet rowSet=dbLibService.getData(inProgressRequestCountQuery,checkInProgressParams,SCHEMA)){
-            if (rowSet.first()) {
+        try (CachedRowSet rowSet =
+                dbLibService.getData(inProgressRequestCountQuery, checkInProgressParams, SCHEMA)) {
+            if (rowSet != null && rowSet.first()) {
                 int count = rowSet.getInt("VALUE");
                 logger.info("In progress request count fetched from database successfully.");
                 return count;
@@ -391,44 +386,51 @@ public class TransactionRecorderImpl implements TransactionRecorder {
     public List getRecords(String requestId, String subrequestId, String originatorId, String vnfId)
         throws APPCException {
         StringBuilder queryString = (new StringBuilder(1024))
-            .append("SELECT " + TRANSACTION_ATTRIBUTES.STATE.getColumnName())
-            .append(" FROM " + TRANSACTIONS)
-            .append(" WHERE " + TRANSACTION_ATTRIBUTES.REQUEST_ID.getColumnName() + "  = ? AND " +
-                TRANSACTION_ATTRIBUTES.TARGET_ID.getColumnName() + " = ?");
-
+            .append("SELECT ").append(TRANSACTION_ID.getColumnName())
+            .append(",")
+            .append(STATE.getColumnName())
+            .append(" FROM ").append(TRANSACTIONS)
+            .append(" WHERE ").append(TRANSACTION_ATTRIBUTES.REQUEST_ID.getColumnName()).append(" = ? AND ")
+            .append(TRANSACTION_ATTRIBUTES.TARGET_ID.getColumnName()).append(" = ?");
         ArrayList argList = new ArrayList<>();
         argList.add(requestId);
         argList.add(vnfId);
 
         if (subrequestId != null) {
-            queryString.append(" AND " + TRANSACTION_ATTRIBUTES.SUBREQUEST_ID.getColumnName() + " = ?");
+            queryString.append(" AND ").append(TRANSACTION_ATTRIBUTES.SUBREQUEST_ID.getColumnName()).append(" = ?");
             argList.add(subrequestId);
         }
         if (originatorId != null) {
-            queryString.append(" AND " + TRANSACTION_ATTRIBUTES.ORIGINATOR_ID.getColumnName() + " = ?");
+            queryString.append(" AND ").append(TRANSACTION_ATTRIBUTES.ORIGINATOR_ID.getColumnName()).append(" = ?");
             argList.add(originatorId);
         }
 
         List requestStatusList = new ArrayList<>();
-        try {
-            CachedRowSet resultSet = dbLibService.getData(queryString.toString(), argList, SCHEMA);
-            while (resultSet.next()) {
-                String name = resultSet.getString(TRANSACTION_ATTRIBUTES.STATE.getColumnName());
-                RequestStatus requestStatus = null;
-                try {
-                    requestStatus = RequestStatus.valueOf(name);
-                } catch (IllegalArgumentException e) {
-                    logger.error(String.format("Invalid request status (%s) using (%s) :", name, RequestStatus
-                        .UNKNOWN), e);
-                    requestStatus = RequestStatus.UNKNOWN;
+        try (CachedRowSet resultSet = dbLibService.getData(queryString.toString(), argList, SCHEMA)) {
+            if (resultSet == null) {
+                logger.error(String.format(
+                        "No results returned when retrieving record for requestID %s and vnfId %s %s",
+                        requestId, vnfId, "from the transactions table"));
+            } else {
+                while (resultSet.next()) {
+                    String name = resultSet.getString(TRANSACTION_ATTRIBUTES.STATE.getColumnName());
+                    RequestStatus requestStatus = null;
+                    try {
+                        requestStatus = RequestStatus.valueOf(name);
+                    } catch (IllegalArgumentException e) {
+                        logger.error(String.format(
+                                "Invalid request status (%s) using (%s):", name, RequestStatus.UNKNOWN), e);
+                        requestStatus = RequestStatus.UNKNOWN;
+                    }
+                    requestStatusList.add(requestStatus);
+                    logger.debug(String.format("Request Status obtained (%s).", requestStatus));
                 }
-                requestStatusList.add(requestStatus);
-                logger.debug(String.format("Request Status obtained (%s).", requestStatus));
             }
         } catch (SQLException e) {
             logger.error("Error Accessing Database ", e);
-            throw new APPCException(String.format("Error retrieving record for requestID %s and vnfId %s " +
-                "from the transactions table", requestId, vnfId), e);
+            throw new APPCException(String.format(
+                    "Error retrieving record for requestID %s and vnfId %s from the transactions table",
+                    requestId, vnfId), e);
         }
 
         return requestStatusList;
diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java
index 36cf26bb7..394aa97a1 100644
--- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java
+++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java
@@ -19,31 +19,12 @@
  * 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.appc.transactionrecorder.impl;
 
-import static org.mockito.Matchers.anyObject;
-import static org.mockito.Matchers.anyString;
-import static org.hamcrest.CoreMatchers.isA;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.text.ParseException;
-import java.time.Instant;
-import java.time.ZoneOffset;
-import java.time.format.DateTimeFormatter;
-import java.time.temporal.ChronoUnit;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import javax.sql.rowset.CachedRowSet;
+import com.sun.rowset.CachedRowSetImpl;
 import org.junit.After;
 import org.junit.Assert;
 import org.junit.Before;
@@ -51,6 +32,11 @@ import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
+
+import static org.mockito.Matchers.anyObject;
+import static org.mockito.Matchers.anyString;
+import static org.hamcrest.CoreMatchers.isA;
+
 import org.onap.appc.dao.util.dbcp.DBConnectionPool;
 import org.onap.appc.dao.util.helper.DBHelper;
 import org.onap.appc.domainmodel.lcm.Flags;
@@ -61,7 +47,22 @@ import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.transactionrecorder.objects.TransactionConstants;
 import org.onap.appc.transactionrecorder.objects.TransactionConstants.TRANSACTION_ATTRIBUTES;
 import org.onap.ccsdk.sli.core.dblib.DbLibService;
-import com.sun.rowset.CachedRowSetImpl;
+
+import javax.sql.rowset.CachedRowSet;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.time.Instant;
+import java.time.ZoneOffset;
+import java.time.format.DateTimeFormatter;
+import java.time.temporal.ChronoUnit;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
 
 /**
  * Test class for TransactionRecorder
@@ -86,26 +87,27 @@ public class TransactionRecorderImplTest {
      * 

* Please ensure this table create script is identical to the source script used in a deployment. */ - private String TRANSACTION_CREATE_TABLE = "CREATE TABLE TRANSACTIONS (" + - " TRANSACTION_ID VARCHAR(75) NOT NULL PRIMARY KEY," + - " ORIGIN_TIMESTAMP DATETIME(3) NOT NULL," + - " REQUEST_ID VARCHAR(256) NOT NULL," + - " SUBREQUEST_ID VARCHAR(256) DEFAULT NULL," + - " ORIGINATOR_ID VARCHAR(256) DEFAULT NULL," + - " START_TIME DATETIME(3) NOT NULL," + - " END_TIME DATETIME(3) DEFAULT NULL," + - " TARGET_ID VARCHAR(256) NOT NULL," + - " TARGET_TYPE VARCHAR(256) DEFAULT NULL," + - " OPERATION VARCHAR(256) NOT NULL," + - " RESULT_CODE INT(11) DEFAULT NULL," + - " DESCRIPTION TEXT," + - " STATE VARCHAR(50) NOT NULL," + - " SERVICE_INSTANCE_ID VARCHAR(256) DEFAULT NULL," + - " VNFC_NAME VARCHAR(256) DEFAULT NULL," + - " VSERVER_ID VARCHAR(256) DEFAULT NULL," + - " VF_MODULE_ID VARCHAR(256) DEFAULT NULL," + - " MODE VARCHAR(50) NOT NULL," + - ")"; + private String TRANSACTION_CREATE_TABLE = + "CREATE TABLE TRANSACTIONS (" + + " TRANSACTION_ID VARCHAR(75) NOT NULL PRIMARY KEY," + + " ORIGIN_TIMESTAMP DATETIME(3) NOT NULL," + + " REQUEST_ID VARCHAR(256) NOT NULL," + + " SUBREQUEST_ID VARCHAR(256) DEFAULT NULL," + + " ORIGINATOR_ID VARCHAR(256) DEFAULT NULL," + + " START_TIME DATETIME(3) NOT NULL," + + " END_TIME DATETIME(3) DEFAULT NULL," + + " TARGET_ID VARCHAR(256) NOT NULL," + + " TARGET_TYPE VARCHAR(256) DEFAULT NULL," + + " OPERATION VARCHAR(256) NOT NULL," + + " RESULT_CODE INT(11) DEFAULT NULL," + + " DESCRIPTION TEXT," + + " STATE VARCHAR(50) NOT NULL," + + " SERVICE_INSTANCE_ID VARCHAR(256) DEFAULT NULL," + + " VNFC_NAME VARCHAR(256) DEFAULT NULL," + + " VSERVER_ID VARCHAR(256) DEFAULT NULL," + + " VF_MODULE_ID VARCHAR(256) DEFAULT NULL," + + " MODE VARCHAR(50) NOT NULL," + + ")"; private String TRANSACTION_DROP_TABLE = "DROP TABLE IF EXISTS TRANSACTIONS"; @Rule @@ -151,8 +153,8 @@ public class TransactionRecorderImplTest { public void testStore() throws Exception { TransactionRecord input = prepareTransactionsInput(); - Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - testStoreInMemory(invocation.getArguments())); + Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> testStoreInMemory(invocation.getArguments())); transactionRecorderImpl.store(input); } @@ -175,8 +177,8 @@ public class TransactionRecorderImplTest { insertRecord(record1); TransactionRecord input = prepareTransactionsInput(); input.setStartTime(Instant.now()); - Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - inMemoryExecutionWithResultSet(invocation.getArguments())); + Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> inMemoryExecutionWithResultSet(invocation.getArguments())); Assert.assertEquals(1, transactionRecorderImpl.getInProgressRequests(input, 0).size()); } @@ -197,22 +199,22 @@ public class TransactionRecorderImplTest { @Test public void testGetInProgressRequestsWithinTimeInterval() throws SQLException, APPCException { TransactionRecord record1 = prepareTransactionsInput(); - record1.setStartTime(Instant.now().minus(4,ChronoUnit.HOURS)); + record1.setStartTime(Instant.now().minus(4, ChronoUnit.HOURS)); insertRecord(record1); TransactionRecord input = prepareTransactionsInput(); input.setStartTime(Instant.now()); - Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - inMemoryExecutionWithResultSet(invocation.getArguments())); - List aList= transactionRecorderImpl.getInProgressRequests(input,12); - Assert.assertEquals(1, transactionRecorderImpl.getInProgressRequests(input,12).size()); + Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> inMemoryExecutionWithResultSet(invocation.getArguments())); + List aList = transactionRecorderImpl.getInProgressRequests(input, 12); + Assert.assertEquals(1, transactionRecorderImpl.getInProgressRequests(input, 12).size()); } @Test public void testIsTransactionDuplicate() throws SQLException, APPCException { TransactionRecord input = prepareTransactionsInput(); - Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - inMemoryExecutionWithResultSet(invocation.getArguments())); + Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> inMemoryExecutionWithResultSet(invocation.getArguments())); Assert.assertFalse(transactionRecorderImpl.isTransactionDuplicate(input)); } @@ -274,10 +276,10 @@ public class TransactionRecorderImplTest { insertRecord(input); Map updateColumns = new HashMap<>(); updateColumns.put(TransactionConstants.TRANSACTION_ATTRIBUTES.TARGET_TYPE, "Firewall"); - Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - returnResult(invocation.getArguments())); - Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - testUpdateInMemory(invocation.getArguments())); + Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> returnResult(invocation.getArguments())); + Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> testUpdateInMemory(invocation.getArguments())); transactionRecorderImpl.update(input.getTransactionId(), input.getRequestId(), updateColumns); Mockito.verify(dbLibService).getData(anyString(), anyObject(), anyString()); Mockito.verify(dbLibService).writeData(anyString(), anyObject(), anyString()); @@ -301,11 +303,10 @@ public class TransactionRecorderImplTest { TransactionRecord input = prepareTransactionsInput(); Map updateColumns = new HashMap<>(); updateColumns.put(TransactionConstants.TRANSACTION_ATTRIBUTES.TARGET_TYPE, "Firewall"); - Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - returnPositiveResult(invocation.getArguments())); - Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> - testUpdateInMemory(invocation.getArguments())); - + Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> returnPositiveResult(invocation.getArguments())); + Mockito.when(dbLibService.writeData(anyString(), anyObject(), anyString())) + .thenAnswer(invocation -> testUpdateInMemory(invocation.getArguments())); transactionRecorderImpl.update(input.getTransactionId(), input.getRequestId(), updateColumns); Mockito.verify(dbLibService).getData(anyString(), anyObject(), anyString()); Mockito.verify(dbLibService).writeData(anyString(), anyObject(), anyString()); @@ -319,9 +320,9 @@ public class TransactionRecorderImplTest { insertNullInstanceData(args.get(0)); try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps_second = con.prepareStatement(query) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps_second = con.prepareStatement(query) + ) { for (int i = 1; i <= args.size(); i++) { ps_second.setString(i, args.get(i - 1)); } @@ -332,12 +333,13 @@ public class TransactionRecorderImplTest { } private void insertNullInstanceData(String transactionId) throws Exception { - final String nullInstanceQuery = (TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS + - " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); + final String nullInstanceQuery = + TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS + + " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(nullInstanceQuery) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(nullInstanceQuery) + ) { ArrayList input = new ArrayList(); input.add(transactionId); input.add(dateToStringConverterMillis(Instant.parse("2017-09-12T00:00:01.00Z"))); @@ -374,9 +376,9 @@ public class TransactionRecorderImplTest { ArrayList args = (ArrayList) obj[1]; System.out.println("Query: " + query + "\nArgs: " + args); try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(query) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(query) + ) { for (int i = 1; i <= args.size(); i++) { ps.setString(i, args.get(i - 1)); } @@ -430,9 +432,9 @@ public class TransactionRecorderImplTest { ArrayList args = (ArrayList) obj[1]; // System.out.println("Query: " + query + "\nArgs: " + args); try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(query) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(query) + ) { for (int i = 1; i <= args.size(); i++) { ps.setString(i, args.get(i - 1)); } @@ -446,9 +448,9 @@ public class TransactionRecorderImplTest { String query = (String) obj[0]; ArrayList args = (ArrayList) obj[1]; try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(query) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(query) + ) { for (int i = 1; i <= args.size(); i++) { ps.setString(i, args.get(i - 1)); } @@ -460,13 +462,13 @@ public class TransactionRecorderImplTest { private boolean isTransactionAborted() throws Exception { String query = "SELECT COUNT(*) FROM TRANSACTIONS WHERE STATE = ?"; try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(query) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(query) + ) { ps.setString(1, RequestStatus.ABORTED.toString()); try ( - ResultSet rs = ps.executeQuery() - ) { + ResultSet rs = ps.executeQuery() + ) { while (rs.next()) { int value = rs.getInt(1); if (value == 1) { @@ -483,9 +485,9 @@ public class TransactionRecorderImplTest { String query = (String) obj[0]; ArrayList args = (ArrayList) obj[1]; try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(query) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(query) + ) { for (int i = 1; i <= args.size(); i++) { System.out.println("Value at " + i + ": " + args.get(i - 1)); ps.setString(i, args.get(i - 1)); @@ -504,9 +506,9 @@ public class TransactionRecorderImplTest { String query = (String) obj[0]; ArrayList args = (ArrayList) obj[1]; try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(query) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(query) + ) { for (int i = 1; i <= args.size(); i++) { ps.setString(i, args.get(i - 1)); } @@ -538,12 +540,13 @@ public class TransactionRecorderImplTest { } private void insertRecord(TransactionRecord input) throws SQLException { - final String STORE_DATE_QUERY = TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS + - " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; + final String STORE_DATE_QUERY = + TransactionConstants.INSERT_INTO + TransactionConstants.TRANSACTIONS + + " values (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement(STORE_DATE_QUERY) - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement(STORE_DATE_QUERY) + ) { ArrayList args = prepareArguments(input); args.remove(0); args.add(0, "123~" + input.getTransactionId()); @@ -615,21 +618,22 @@ public class TransactionRecorderImplTest { private String checkIfValueIsUpdated(String key) throws Exception { try ( - Connection con = dbConnectionPool.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT TARGET_TYPE,TRANSACTION_ID FROM TRANSACTIONS" + - " WHERE TRANSACTION_ID = ?") - ) { + Connection con = dbConnectionPool.getConnection(); + PreparedStatement ps = con.prepareStatement( + "SELECT TARGET_TYPE, TRANSACTION_ID FROM TRANSACTIONS" + + " WHERE TRANSACTION_ID = ?") + ) { ps.setString(1, key); try ( - ResultSet rs = ps.executeQuery() - ) { - while (rs.next()) { - String value = rs.getString("TARGET_TYPE"); - String transactionId = rs.getString("TRANSACTION_ID"); - System.out.println("Updated data: TRANSACTION_ID: " + transactionId + " TARGET_TYPE: " + value); - return value; - } - throw new Exception("Value not found"); + ResultSet rs = ps.executeQuery() + ) { + while (rs.next()) { + String value = rs.getString("TARGET_TYPE"); + String transactionId = rs.getString("TRANSACTION_ID"); + System.out.println("Updated data: TRANSACTION_ID: " + transactionId + " TARGET_TYPE: " + value); + return value; + } + throw new Exception("Value not found"); } } } -- cgit 1.2.3-korg