aboutsummaryrefslogtreecommitdiffstats
path: root/integrity-audit/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2018-01-31 18:10:34 -0500
committerJim Hahn <jrh3@att.com>2018-02-01 10:50:48 -0500
commit0f51fa4e072aeb29f4e323cb6013fb4a873aae5c (patch)
tree1f0b28eea283e367725980e3e22acfaf89e628e2 /integrity-audit/src/test
parent9c978cea0a5af3d4a9d587a5f09b88d660bd498b (diff)
Fix sonar generic Exceptions in policy/common
IntegrityMonitor.java: Renamed variables, Ex: dep_groups => depGroups. Renamed enum constants, Ex: pdp_xacml => PDP_XACML. Merged "if" tests. Cast values to "long" before multiplying. Re-throw interrupt(). Write exception via logger instead of e.printStackTrace(). Moved constructor to top of the file. Removed most logger.isDebugEnabled() checks. Returned generic List instead of ArrayList. Used entrySet() instead of keySet(). Removed useless parentheses. Removed superfluous exceptions from "throws" declaration. DbAudit.java: Modified DbAudit to throw DbAuditException. Replaced references to HashSet and HashMap with generic Set and Map. Modified DbAudit to iterate over entrySet() instead of keySet(). ComponentAdminException: Created ComponentAdminException class. Modified ComponentAdmin methods to throw new exception class. Extracted "stateManager" String constant. Eliminated logger.isDebugEnabled() calls. Updated the license data. Eliminated double-checked locking problem from PropertyUtil: Modified code to use Initialization On Demand Holder idiom. Change-Id: Ic01288542041da26df483ce85ecaf292ac138f85 Issue-ID: POLICY-246 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'integrity-audit/src/test')
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java26
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbDAOTest.java21
2 files changed, 26 insertions, 21 deletions
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java
index d8388c58..3bedcb0b 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbAuditCompareEntriesTest.java
@@ -26,7 +26,9 @@ import java.io.FileOutputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -129,7 +131,7 @@ public class DbAuditCompareEntriesTest {
String className = null;
//There is only one entry IntegrityAuditEntity, but we will check anyway
- HashSet<String> classNameSet = dbDAO.getPersistenceClassNames();
+ Set<String> classNameSet = dbDAO.getPersistenceClassNames();
for(String c : classNameSet){
if (c.equals("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")){
className = c;
@@ -175,7 +177,7 @@ public class DbAuditCompareEntriesTest {
myEntries.put("pdp1", entry1);
theirEntries.put("pdp1", entry2);
- HashSet<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
/*
* Assert that there are no mismatches returned
@@ -235,7 +237,7 @@ public class DbAuditCompareEntriesTest {
myEntries.put("pdp1", entry1);
theirEntries.put("pdp1", entry2);
- HashSet<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
/*
* Assert that there was one mismatch
@@ -322,7 +324,7 @@ public class DbAuditCompareEntriesTest {
theirEntries.put("0", entry2);
theirEntries.put("2", entry4);
- HashSet<Object> mismatchResult = dbAudit.compareEntries(myEntries, theirEntries);
+ Set<Object> mismatchResult = dbAudit.compareEntries(myEntries, theirEntries);
/*
* Assert 3 mismatches/missing entries were found
@@ -343,8 +345,8 @@ public class DbAuditCompareEntriesTest {
dbDAO = new DbDAO(resourceName, persistenceUnit, properties);
DbAudit dbAudit = new DbAudit(dbDAO);
- HashSet<String> classNameSet = dbDAO.getPersistenceClassNames();
- HashSet<Object> mismatchResult = new HashSet<Object>();
+ Set<String> classNameSet = dbDAO.getPersistenceClassNames();
+ Set<Object> mismatchResult = new HashSet<Object>();
for(String c : classNameSet) {
if (c.equals("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")){
String resourceName1 = resourceName;
@@ -537,10 +539,10 @@ public class DbAuditCompareEntriesTest {
new DbDAO("pdp2", persistenceUnit, properties2);
// Pull all entries and compare
- HashSet<String> classNameSet = dbDAO.getPersistenceClassNames();
- HashMap<Object, Object> myEntries;
- HashMap<Object, Object> theirEntries;
- HashSet<Object> mismatchResult = new HashSet<Object>();
+ Set<String> classNameSet = dbDAO.getPersistenceClassNames();
+ Map<Object, Object> myEntries;
+ Map<Object, Object> theirEntries;
+ Set<Object> mismatchResult = new HashSet<Object>();
String className;
for(String c : classNameSet) {
className = c;
@@ -572,7 +574,7 @@ public class DbAuditCompareEntriesTest {
String className = null;
//There is only one entry IntegrityAuditEntity, but we will check anyway
- HashSet<String> classNameSet = dbDAO.getPersistenceClassNames();
+ Set<String> classNameSet = dbDAO.getPersistenceClassNames();
for(String c : classNameSet){
if (c.equals("org.onap.policy.common.ia.test.jpa.IaTestEntity")){
className = c;
@@ -608,7 +610,7 @@ public class DbAuditCompareEntriesTest {
myEntries.put("0", iate);
theirEntries.put("0", iate2);
- HashSet<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
+ Set<Object> result = dbAudit.compareEntries(myEntries, theirEntries);
/*
* Assert that there are no mismatches returned
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbDAOTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbDAOTest.java
index 4fd51f6e..ac3bc587 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbDAOTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/test/DbDAOTest.java
@@ -20,7 +20,10 @@
package org.onap.policy.common.ia.test;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
/*
* All JUnits are designed to run in the local development environment
@@ -28,10 +31,11 @@ import static org.junit.Assert.*;
* tasks.
*/
import java.util.Date;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -47,7 +51,6 @@ import javax.persistence.criteria.Root;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-
import org.onap.policy.common.ia.DbDAO;
import org.onap.policy.common.ia.DbDaoTransactionException;
import org.onap.policy.common.ia.IntegrityAuditProperties;
@@ -487,7 +490,7 @@ public class DbDAOTest {
try {
// Obtain a hash with the persisted objects
- HashMap<Object, Object> entries = d.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
+ Map<Object, Object> entries = d.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -543,7 +546,7 @@ public class DbDAOTest {
}
// Obtain a hash with the persisted objects
- HashMap<Object, Object> entries = d.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet);
+ Map<Object, Object> entries = d.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet);
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -591,7 +594,7 @@ public class DbDAOTest {
try {
// Obtain a hash with the persisted objects
- HashMap<Object, Object> entries = d.getAllEntries("integrityAuditPU", properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
+ Map<Object, Object> entries = d.getAllEntries("integrityAuditPU", properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -647,7 +650,7 @@ public class DbDAOTest {
}
// Obtain a hash with the persisted objects
- HashMap<Object, Object> entries = d.getAllEntries("integrityAuditPU", properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet);
+ Map<Object, Object> entries = d.getAllEntries("integrityAuditPU", properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet);
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -695,7 +698,7 @@ public class DbDAOTest {
try {
// Obtain a hash with the persisted objects
- HashMap<Object, Object> entries = d.getAllEntries(persistenceUnit, properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
+ Map<Object, Object> entries = d.getAllEntries(persistenceUnit, properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -733,7 +736,7 @@ public class DbDAOTest {
e.printStackTrace();
}
// Retrieve persistence class names
- HashSet<String> result = d.getPersistenceClassNames();
+ Set<String> result = d.getPersistenceClassNames();
assertEquals(1, result.size());
}
}