aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-06-19 17:31:24 -0400
committerJim Hahn <jrh3@att.com>2019-06-21 11:36:18 -0400
commitc9392e1a126de54ae8a0e1f3316729e878115300 (patch)
tree5a371d53f5e6cf8bedbb4daf94f558844037fd7d /integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
parent62463da9961f7e524559b34766baf2dd469fa910 (diff)
Fix sonar issues in integrity audit
Mostly used Eclipse Refactor->Extract Method to reduce cyclomatic complexity. Also combined a few "if" statements to reduce nesting levels. Also addressed some sonar issues in the tests (e.g., use "<>" where appropriate). Did not attempt to increase junit coverage. Change-Id: I9d6c1305ce455f0d64249b548d123bb9bf37292a Issue-ID: POLICY-1791 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java')
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java39
1 files changed, 17 insertions, 22 deletions
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
index 836aa288..27cd168f 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java
@@ -7,9 +7,9 @@
* 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.
@@ -20,17 +20,15 @@
package org.onap.policy.common.ia;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
import java.util.List;
import java.util.Properties;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -45,7 +43,7 @@ import org.onap.policy.common.utils.test.log.logback.ExtractAppender;
* All JUnits are designed to run in the local development environment
* where they have write privileges and can execute time-sensitive
* tasks.
- *
+ *
* If any have been ignored (@Ignore) they will not run at the same time
* as others. You should run them as JUnits by themselves.
*/
@@ -53,7 +51,7 @@ public class DbAuditTest extends IntegrityAuditTestBase {
private static Logger logger = FlexLogger.getLogger(DbAuditTest.class);
- private static final String resourceName = "pdp1";
+ private static final String RESOURCE_NAME = "pdp1";
private EntityManagerFactory emf2;
private EntityManager em2;
@@ -135,16 +133,13 @@ public class DbAuditTest extends IntegrityAuditTestBase {
logger.info("noEntitiesTest: Entering");
- dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
+ dbDao = new DbDao(RESOURCE_NAME, A_SEQ_PU, properties);
dbDao.deleteAllIntegrityAuditEntities();
- try {
- DbAudit dbAudit = new DbAudit(dbDao);
- dbAudit.dbAudit(resourceName, A_SEQ_PU, nodeType);
- fail("found unexpected entities");
- } catch (DbAuditException e) {
- // Ignore expected exception
- }
+ assertThatThrownBy(() -> {
+ DbAudit dbAudit = new DbAudit(dbDao);
+ dbAudit.dbAudit(RESOURCE_NAME, A_SEQ_PU, nodeType);
+ }).isInstanceOf(DbAuditException.class);
logger.info("noEntitiesTest: Exit");
}
@@ -161,9 +156,9 @@ public class DbAuditTest extends IntegrityAuditTestBase {
final ExtractAppender log = watch(debugLogger, "DbAudit: Found only (one) IntegrityAuditEntity entry:");
// Add one entry in the database
- dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
+ dbDao = new DbDao(RESOURCE_NAME, A_SEQ_PU, properties);
DbAudit dbAudit = new DbAudit(dbDao);
- dbAudit.dbAudit(resourceName, A_SEQ_PU, nodeType);
+ dbAudit.dbAudit(RESOURCE_NAME, A_SEQ_PU, nodeType);
List<IntegrityAuditEntity> iaeList = dbDao.getIntegrityAuditEntities(A_SEQ_PU, nodeType);
logger.info("List size: " + iaeList.size());
@@ -206,9 +201,9 @@ public class DbAuditTest extends IntegrityAuditTestBase {
/*
* Create entries in DB1 & DB2 for the resource of interest
*/
- dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
+ dbDao = new DbDao(RESOURCE_NAME, A_SEQ_PU, properties);
- new DbDao(resourceName, A_SEQ_PU, properties2).destroy();
+ new DbDao(RESOURCE_NAME, A_SEQ_PU, properties2).destroy();
/*
* Entries in DB1, pointing to DB2, except for pdp3
@@ -230,7 +225,7 @@ public class DbAuditTest extends IntegrityAuditTestBase {
* as DB2 it can be confirmed that the mismatch is resolved
*/
DbAudit dbAudit = new DbAudit(dbDao);
- dbAudit.dbAudit(resourceName, A_SEQ_PU, nodeType);
+ dbAudit.dbAudit(RESOURCE_NAME, A_SEQ_PU, nodeType);
// update pdp3 entry in DB1 to point to DB2
new DbDao("pdp3", A_SEQ_PU, properties, dbUrl2).destroy();
@@ -239,7 +234,7 @@ public class DbAuditTest extends IntegrityAuditTestBase {
* Run the audit again and correct the mismatch, the result should be one entry in the
* mismatchKeySet because of the missing entry from the beginning of the test
*/
- dbAudit.dbAudit(resourceName, A_SEQ_PU, nodeType);
+ dbAudit.dbAudit(RESOURCE_NAME, A_SEQ_PU, nodeType);
assertFalse(dbglog.getExtracted().isEmpty());
@@ -267,7 +262,7 @@ public class DbAuditTest extends IntegrityAuditTestBase {
/**
* Re-creates DB1, using the specified properties.
- *
+ *
* @param properties the properties
*/
private void recreateDb1(Properties properties) {