summaryrefslogtreecommitdiffstats
path: root/integrity-audit
diff options
context:
space:
mode:
Diffstat (limited to 'integrity-audit')
-rw-r--r--integrity-audit/pom.xml5
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java457
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java247
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java109
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java154
-rw-r--r--integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java6
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java23
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java79
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditTest.java39
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java51
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java14
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java29
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java94
-rw-r--r--integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java30
14 files changed, 702 insertions, 635 deletions
diff --git a/integrity-audit/pom.xml b/integrity-audit/pom.xml
index 006687a3..b740d53d 100644
--- a/integrity-audit/pom.xml
+++ b/integrity-audit/pom.xml
@@ -68,6 +68,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.assertj</groupId>
+ <artifactId>assertj-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.onap.policy.common</groupId>
<artifactId>ONAP-Logging</artifactId>
<version>${project.version}</version>
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java
index df979286..25bafdc4 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/AuditThread.java
@@ -147,146 +147,7 @@ public class AuditThread extends Thread {
/*
* Triggers change in designation, unless no other viable candidate.
*/
- boolean auditCompleted = false;
-
- DbAudit dbAudit = new DbAudit(dbDao);
-
- IntegrityAuditEntity entityCurrentlyDesignated;
- IntegrityAuditEntity thisEntity;
- integrityAudit.setThreadInitialized(true); // An exception will set it to false
-
- while (true) {
- try {
- /*
- * It may have been awhile since we last cycled through this loop, so refresh
- * the list of IntegrityAuditEntities.
- */
- List<IntegrityAuditEntity> integrityAuditEntityList = getIntegrityAuditEntityList();
-
- /*
- * We could've set entityCurrentlyDesignated as a side effect of
- * getIntegrityAuditEntityList(), but then we would've had to make
- * entityCurrentlyDesignated a class level attribute. Using this approach, we
- * can keep it local to the run() method.
- */
- entityCurrentlyDesignated = getEntityCurrentlyDesignated(integrityAuditEntityList);
-
- /*
- * Need to refresh thisEntity each time through loop, because we need a fresh
- * version of lastUpdated.
- */
- thisEntity = getThisEntity(integrityAuditEntityList);
-
- /*
- * If we haven't done the audit yet, note that we're current and see if we're
- * designated.
- */
- if (!auditCompleted) {
- dbDao.setLastUpdated();
-
- /*
- * If no current designation or currently designated node is stale, see if
- * we're the next node to be designated.
- */
- if (entityCurrentlyDesignated == null || isStale(entityCurrentlyDesignated)) {
- IntegrityAuditEntity designationCandidate =
- getDesignationCandidate(integrityAuditEntityList);
-
- /*
- * If we're the next node to be designated, run the audit.
- */
- if (designationCandidate.getResourceName().equals(this.resourceName)) {
- runAudit(dbAudit);
- auditCompleted = true;
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("AuditThread.run: designationCandidate, "
- + designationCandidate.getResourceName() + ", not this entity, "
- + thisEntity.getResourceName());
- }
- }
-
- /*
- * Application may have been stopped and restarted, in which case we
- * might be designated but auditCompleted will have been reset to false,
- * so account for this.
- */
- } else if (thisEntity.getResourceName().equals(entityCurrentlyDesignated.getResourceName())) {
-
- if (logger.isDebugEnabled()) {
- logger.debug("AuditThread.run: Re-running audit for " + thisEntity.getResourceName());
- }
- runAudit(dbAudit);
- auditCompleted = true;
-
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("AuditThread.run: Currently designated node, "
- + entityCurrentlyDesignated.getResourceName()
- + ", not yet stale and not this node");
- }
- }
-
-
- /*
- * Audit already completed on this node, so allow the node to go stale until
- * twice the AUDIT_COMPLETION_PERIOD has elapsed. This should give plenty of
- * time for another node (if another node is out there) to pick up
- * designation.
- */
- } else {
-
- auditCompleted = resetAuditCompleted(auditCompleted, thisEntity);
-
- }
-
- /*
- * If we've just run audit, sleep per the integrity_audit_period_seconds
- * property, otherwise just sleep the normal interval.
- */
- if (auditCompleted) {
- // for junit testing: indicate that an audit has completed
- auditCompleted();
-
- if (logger.isDebugEnabled()) {
- logger.debug("AuditThread.run: Audit completed; resourceName=" + this.resourceName
- + " sleeping " + integrityAuditPeriodSeconds + "s");
- }
- AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
- if (logger.isDebugEnabled()) {
- logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + " awaking from "
- + integrityAuditPeriodSeconds + "s sleep");
- }
-
- } else {
-
- if (logger.isDebugEnabled()) {
- logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Sleeping "
- + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms");
- }
- AuditorTime.getInstance().sleep(AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS);
- if (logger.isDebugEnabled()) {
- logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Awaking from "
- + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms sleep");
- }
-
- }
-
- } catch (Exception e) {
- if (isInterruptedException(e)) {
- String msg = "AuditThread.run loop - Exception thrown: " + e.getMessage() + "; Stopping.";
- logger.error(MessageCodes.EXCEPTION_ERROR, e, msg);
- break;
- }
-
- String msg = "AuditThread.run loop - Exception thrown: " + e.getMessage()
- + "; Will try audit again in " + integrityAuditPeriodSeconds + " seconds";
- logger.error(MessageCodes.EXCEPTION_ERROR, e, msg);
- // Sleep and try again later
- AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
- }
-
- }
+ runUntilInterrupted();
} catch (Exception e) {
String msg = "AuditThread.run: Could not start audit loop. Exception thrown; message=" + e.getMessage();
@@ -299,6 +160,156 @@ public class AuditThread extends Thread {
logger.info("AuditThread.run: Exiting");
}
+ private void runUntilInterrupted() throws InterruptedException {
+ boolean auditCompleted = false;
+
+ DbAudit dbAudit = new DbAudit(dbDao);
+
+ IntegrityAuditEntity entityCurrentlyDesignated;
+ IntegrityAuditEntity thisEntity;
+ integrityAudit.setThreadInitialized(true); // An exception will set it to false
+
+ while (true) {
+ try {
+ /*
+ * It may have been awhile since we last cycled through this loop, so refresh
+ * the list of IntegrityAuditEntities.
+ */
+ List<IntegrityAuditEntity> integrityAuditEntityList = getIntegrityAuditEntityList();
+
+ /*
+ * We could've set entityCurrentlyDesignated as a side effect of
+ * getIntegrityAuditEntityList(), but then we would've had to make
+ * entityCurrentlyDesignated a class level attribute. Using this approach, we
+ * can keep it local to the run() method.
+ */
+ entityCurrentlyDesignated = getEntityCurrentlyDesignated(integrityAuditEntityList);
+
+ /*
+ * Need to refresh thisEntity each time through loop, because we need a fresh
+ * version of lastUpdated.
+ */
+ thisEntity = getThisEntity(integrityAuditEntityList);
+
+ /*
+ * If we haven't done the audit yet, note that we're current and see if we're
+ * designated.
+ */
+ auditCompleted = doAudit(auditCompleted, dbAudit, entityCurrentlyDesignated, thisEntity,
+ integrityAuditEntityList);
+
+ /*
+ * If we've just run audit, sleep per the integrity_audit_period_seconds
+ * property, otherwise just sleep the normal interval.
+ */
+ sleepAfterAudit(auditCompleted);
+
+ } catch (Exception e) {
+ if (isInterruptedException(e)) {
+ String msg = "AuditThread.run loop - Exception thrown: " + e.getMessage() + "; Stopping.";
+ logger.error(MessageCodes.EXCEPTION_ERROR, e, msg);
+ break;
+ }
+
+ String msg = "AuditThread.run loop - Exception thrown: " + e.getMessage()
+ + "; Will try audit again in " + integrityAuditPeriodSeconds + " seconds";
+ logger.error(MessageCodes.EXCEPTION_ERROR, e, msg);
+ // Sleep and try again later
+ AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
+ }
+
+ }
+ }
+
+ private boolean doAudit(boolean auditCompleted, DbAudit dbAudit, IntegrityAuditEntity entityCurrentlyDesignated,
+ IntegrityAuditEntity thisEntity, List<IntegrityAuditEntity> integrityAuditEntityList)
+ throws IntegrityAuditException {
+
+ if (!auditCompleted) {
+ dbDao.setLastUpdated();
+
+ /*
+ * If no current designation or currently designated node is stale, see if
+ * we're the next node to be designated.
+ */
+ if (entityCurrentlyDesignated == null || isStale(entityCurrentlyDesignated)) {
+ IntegrityAuditEntity designationCandidate =
+ getDesignationCandidate(integrityAuditEntityList);
+
+ /*
+ * If we're the next node to be designated, run the audit.
+ */
+ if (designationCandidate.getResourceName().equals(this.resourceName)) {
+ runAudit(dbAudit);
+ auditCompleted = true;
+ } else if (logger.isDebugEnabled()) {
+ logger.debug("AuditThread.run: designationCandidate, " + designationCandidate.getResourceName()
+ + ", not this entity, " + thisEntity.getResourceName());
+ }
+
+ /*
+ * Application may have been stopped and restarted, in which case we
+ * might be designated but auditCompleted will have been reset to false,
+ * so account for this.
+ */
+ } else if (thisEntity.getResourceName().equals(entityCurrentlyDesignated.getResourceName())) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("AuditThread.run: Re-running audit for " + thisEntity.getResourceName());
+ }
+ runAudit(dbAudit);
+ auditCompleted = true;
+
+ } else if (logger.isDebugEnabled()) {
+ logger.debug("AuditThread.run: Currently designated node, "
+ + entityCurrentlyDesignated.getResourceName() + ", not yet stale and not this node");
+ }
+
+
+ /*
+ * Audit already completed on this node, so allow the node to go stale until
+ * twice the AUDIT_COMPLETION_PERIOD has elapsed. This should give plenty of
+ * time for another node (if another node is out there) to pick up
+ * designation.
+ */
+ } else {
+
+ auditCompleted = resetAuditCompleted(auditCompleted, thisEntity);
+
+ }
+ return auditCompleted;
+ }
+
+ private void sleepAfterAudit(boolean auditCompleted) throws InterruptedException {
+ if (auditCompleted) {
+ // for junit testing: indicate that an audit has completed
+ auditCompleted();
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("AuditThread.run: Audit completed; resourceName=" + this.resourceName
+ + " sleeping " + integrityAuditPeriodSeconds + "s");
+ }
+ AuditorTime.getInstance().sleep(integrityAuditPeriodSeconds * 1000L);
+ if (logger.isDebugEnabled()) {
+ logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + " awaking from "
+ + integrityAuditPeriodSeconds + "s sleep");
+ }
+
+ } else {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Sleeping "
+ + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms");
+ }
+ AuditorTime.getInstance().sleep(AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS);
+ if (logger.isDebugEnabled()) {
+ logger.debug(AUDIT_THREAD_MESSAGE + this.resourceName + ": Awaking from "
+ + AuditThread.AUDIT_THREAD_SLEEP_INTERVAL_MS + "ms sleep");
+ }
+
+ }
+ }
+
/**
* Determines if an exception is an InterruptedException or was caused by an
* InterruptedException.
@@ -332,7 +343,6 @@ public class AuditThread extends Thread {
+ integrityAuditEntityList.size());
}
- IntegrityAuditEntity designationCandidate;
IntegrityAuditEntity thisEntity = null;
int designatedEntityIndex = -1;
@@ -346,94 +356,112 @@ public class AuditThread extends Thread {
logIntegrityAuditEntity(integrityAuditEntity);
}
- if (integrityAuditEntity.getResourceName().equals(this.resourceName)) {
- if (logger.isDebugEnabled()) {
- logger.debug("getDesignationCandidate: thisEntity=" + integrityAuditEntity.getResourceName());
- }
- thisEntity = integrityAuditEntity;
- }
+ thisEntity = detmEntity(integrityAuditEntity, thisEntity);
if (integrityAuditEntity.isDesignated()) {
if (logger.isDebugEnabled()) {
logger.debug("getDesignationCandidate: Currently designated entity resourceName="
- + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
- + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
- + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
}
designatedEntityIndex = entityIndex;
/*
* Entity not currently designated
*/
- } else {
+ } else if (isStale(integrityAuditEntity)) {
+ /*
+ * Non-designated entity is stale.
+ */
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("getDesignationCandidate: Entity is stale; resourceName="
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
+ }
/*
- * See if non-designated entity is stale.
+ * Entity is current.
*/
- if (isStale(integrityAuditEntity)) {
+ } else if (designatedEntityIndex == -1) {
+ priorCandidateIndex = detmPriorCandidate(entityIndex, integrityAuditEntity, priorCandidateIndex);
- if (logger.isDebugEnabled()) {
- logger.debug("getDesignationCandidate: Entity is stale; resourceName="
- + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
- + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
- + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
- }
-
- /*
- * Entity is current.
- */
- } else {
-
- if (designatedEntityIndex == -1) {
-
- if (priorCandidateIndex == -1) {
- if (logger.isDebugEnabled()) {
- logger.debug("getDesignationCandidate: Prior candidate found, resourceName="
- + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
- + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
- + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
- }
- priorCandidateIndex = entityIndex;
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug(
- "getDesignationCandidate: Prior entity current but prior candidate already "
- + "found; resourceName=" + integrityAuditEntity.getResourceName()
- + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit()
- + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated()
- + ENTITY_INDEX_MESSAGE + entityIndex);
- }
- }
- } else {
- if (subsequentCandidateIndex == -1) {
- if (logger.isDebugEnabled()) {
- logger.debug("getDesignationCandidate: Subsequent candidate found, resourceName="
- + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
- + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
- + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
- }
- subsequentCandidateIndex = entityIndex;
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug(
- "getDesignationCandidate: Subsequent entity current but subsequent candidate "
- + "already found; resourceName="
- + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
- + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
- + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE
- + entityIndex);
- }
- }
- }
-
- } // end entity is current
-
- } // end entity not currently designated
+ } else {
+ subsequentCandidateIndex =
+ detmSubsequentCandidate(entityIndex, integrityAuditEntity, subsequentCandidateIndex);
+ }
entityIndex++;
} // end for loop
+ return detmDesignationCandidate(integrityAuditEntityList, thisEntity, priorCandidateIndex,
+ subsequentCandidateIndex);
+ }
+
+ private IntegrityAuditEntity detmEntity(IntegrityAuditEntity integrityAuditEntity,
+ IntegrityAuditEntity thisEntity) {
+ if (integrityAuditEntity.getResourceName().equals(this.resourceName)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getDesignationCandidate: thisEntity=" + integrityAuditEntity.getResourceName());
+ }
+ thisEntity = integrityAuditEntity;
+ }
+ return thisEntity;
+ }
+
+ private int detmPriorCandidate(int entityIndex, IntegrityAuditEntity integrityAuditEntity,
+ int priorCandidateIndex) {
+ if (priorCandidateIndex == -1) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getDesignationCandidate: Prior candidate found, resourceName="
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
+ }
+ priorCandidateIndex = entityIndex;
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug(
+ "getDesignationCandidate: Prior entity current but prior candidate already "
+ + "found; resourceName=" + integrityAuditEntity.getResourceName()
+ + PERSISTENCE_MESSAGE + integrityAuditEntity.getPersistenceUnit()
+ + LAST_UPDATED_MESSAGE + integrityAuditEntity.getLastUpdated()
+ + ENTITY_INDEX_MESSAGE + entityIndex);
+ }
+ }
+ return priorCandidateIndex;
+ }
+
+ private int detmSubsequentCandidate(int entityIndex, IntegrityAuditEntity integrityAuditEntity,
+ int subsequentCandidateIndex) {
+ if (subsequentCandidateIndex == -1) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("getDesignationCandidate: Subsequent candidate found, resourceName="
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE + entityIndex);
+ }
+ subsequentCandidateIndex = entityIndex;
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug(
+ "getDesignationCandidate: Subsequent entity current but subsequent candidate "
+ + "already found; resourceName="
+ + integrityAuditEntity.getResourceName() + PERSISTENCE_MESSAGE
+ + integrityAuditEntity.getPersistenceUnit() + LAST_UPDATED_MESSAGE
+ + integrityAuditEntity.getLastUpdated() + ENTITY_INDEX_MESSAGE
+ + entityIndex);
+ }
+ }
+ return subsequentCandidateIndex;
+ }
+
+ private IntegrityAuditEntity detmDesignationCandidate(List<IntegrityAuditEntity> integrityAuditEntityList,
+ IntegrityAuditEntity thisEntity, int priorCandidateIndex, int subsequentCandidateIndex) {
+ IntegrityAuditEntity designationCandidate;
/*
* Per round robin algorithm, if a current entity is found that is lexicographically after
* the currently designated entity, this entity becomes the designation candidate. If no
@@ -454,15 +482,18 @@ public class AuditThread extends Thread {
logger.debug("getDesignationCandidate: Exiting and returning prior designationCandidate="
+ designationCandidate.getResourceName());
}
- } else {
+ } else if (thisEntity != null) {
logger.debug("getDesignationCandidate: No subsequent or prior candidate found; designating thisEntity, "
- + "resourceName=" + thisEntity.getResourceName());
+ + "resourceName=" + thisEntity.getResourceName());
designationCandidate = thisEntity;
+ } else {
+ // this shouldn't happen, but adding it to make sonar happy
+ logger.debug("getDesignationCandidate: No entities available");
+ designationCandidate = null;
}
}
return designationCandidate;
-
}
/**
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
index 9a73b79c..4e718a60 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbAudit.java
@@ -144,6 +144,23 @@ public class DbAudit {
*/
Map<String, Set<Object>> misMatchedMap = new HashMap<>();
+ compareList(persistenceUnit, iaeList, myIae, classNameSet, misMatchedMap);
+
+ // If misMatchedMap is not empty, retrieve the entries in each misMatched list and compare
+ // again
+ recompareList(resourceName, persistenceUnit, iaeList, myIae, misMatchedMap);
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: Exiting");
+ }
+
+ return; // all done
+ }
+
+ private void compareList(String persistenceUnit, List<IntegrityAuditEntity> iaeList, IntegrityAuditEntity myIae,
+ Set<String> classNameSet, Map<String, Set<Object>> misMatchedMap)
+ throws IntegrityAuditException {
+
// We need to keep track of how long the audit is taking
long startTime = AuditorTime.getInstance().getMillis();
@@ -161,52 +178,7 @@ public class DbAudit {
Map<Object, Object> myEntries = dbDao.getAllMyEntries(clazzName);
// get a map of the objects indexed by id. Does not necessarily have any entries
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Traversing iaeList, size=" + iaeList.size());
- }
- for (IntegrityAuditEntity iae : iaeList) {
- if (iae.getId() == myIae.getId()) {
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: My Id=" + iae.getId() + COMMA_RESOURCE_NAME + iae.getResourceName());
- }
- continue; // no need to compare with self
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Id=" + iae.getId() + COMMA_RESOURCE_NAME + iae.getResourceName());
- }
- }
- // Create properties for the other db node
- Properties theirProperties = new Properties();
- theirProperties.put(IntegrityAuditProperties.DB_DRIVER, iae.getJdbcDriver());
- theirProperties.put(IntegrityAuditProperties.DB_URL, iae.getJdbcUrl());
- theirProperties.put(IntegrityAuditProperties.DB_USER, iae.getJdbcUser());
- theirProperties.put(IntegrityAuditProperties.DB_PWD, iae.getJdbcPassword());
- theirProperties.put(IntegrityAuditProperties.SITE_NAME, iae.getSite());
- theirProperties.put(IntegrityAuditProperties.NODE_TYPE, iae.getNodeType());
-
- // get a map of the instances for their iae indexed by id
- Map<Object, Object> theirEntries = dbDao.getAllEntries(persistenceUnit, theirProperties, clazzName);
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: For persistenceUnit=" + persistenceUnit + ", clazzName=" + clazzName
- + ", theirEntries.size()=" + theirEntries.size());
- }
-
- /*
- * Compare myEntries with theirEntries and get back a set of mismatched IDs. Collect
- * the IDs for the class where a mismatch occurred. We will check them again for all
- * nodes later.
- */
- Set<Object> misMatchedKeySet = compareEntries(myEntries, theirEntries);
- if (!misMatchedKeySet.isEmpty()) {
- Set<Object> misMatchedEntry = misMatchedMap.get(clazzName);
- if (misMatchedEntry == null) {
- misMatchedMap.put(clazzName, misMatchedKeySet);
- } else {
- misMatchedEntry.addAll(misMatchedKeySet);
- misMatchedMap.put(clazzName, misMatchedEntry);
- }
- }
- } // end for (IntegrityAuditEntity iae : iaeList)
+ compareMineWithTheirs(persistenceUnit, iaeList, myIae, misMatchedMap, clazzName, myEntries);
// Time check
if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) {
@@ -239,9 +211,84 @@ public class DbAudit {
logger.debug("dbAudit: Doing another comparison; misMatchedMap.size()=" + misMatchedMap.size());
}
}
+ }
- // If misMatchedMap is not empty, retrieve the entries in each misMatched list and compare
- // again
+ private void compareMineWithTheirs(String persistenceUnit, List<IntegrityAuditEntity> iaeList,
+ IntegrityAuditEntity myIae, Map<String, Set<Object>> misMatchedMap, String clazzName,
+ Map<Object, Object> myEntries) {
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: Traversing iaeList, size=" + iaeList.size());
+ }
+ for (IntegrityAuditEntity iae : iaeList) {
+ if (iae.getId() == myIae.getId()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: My Id=" + iae.getId() + COMMA_RESOURCE_NAME + iae.getResourceName());
+ }
+ continue; // no need to compare with self
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: Id=" + iae.getId() + COMMA_RESOURCE_NAME + iae.getResourceName());
+ }
+
+ // get a map of the instances for their iae indexed by id
+ Map<Object, Object> theirEntries =
+ dbDao.getAllEntries(persistenceUnit, getTheirDaoProperties(iae), clazzName);
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: For persistenceUnit=" + persistenceUnit + ", clazzName=" + clazzName
+ + ", theirEntries.size()=" + theirEntries.size());
+ }
+
+ /*
+ * Compare myEntries with theirEntries and get back a set of mismatched IDs.
+ * Collect the IDs for the class where a mismatch occurred. We will check them
+ * again for all nodes later.
+ */
+ compareMineWithTheirs(myEntries, theirEntries, clazzName, misMatchedMap);
+ } // end for (IntegrityAuditEntity iae : iaeList)
+ }
+
+ private void compareMineWithTheirs(Map<Object, Object> myEntries, Map<Object, Object> theirEntries,
+ String clazzName, Map<String, Set<Object>> misMatchedMap) {
+
+ Set<Object> misMatchedKeySet = compareEntries(myEntries, theirEntries);
+ if (misMatchedKeySet.isEmpty()) {
+ return;
+ }
+
+ Set<Object> misMatchedEntry = misMatchedMap.get(clazzName);
+ if (misMatchedEntry == null) {
+ misMatchedMap.put(clazzName, misMatchedKeySet);
+ } else {
+ misMatchedEntry.addAll(misMatchedKeySet);
+ }
+ }
+
+ /**
+ * Creates properties for the other db node.
+ * @param iae target DB node
+ * @return DAO properties for the given DB node
+ */
+ private Properties getTheirDaoProperties(IntegrityAuditEntity iae) {
+ Properties theirProperties = new Properties();
+
+ theirProperties.put(IntegrityAuditProperties.DB_DRIVER, iae.getJdbcDriver());
+ theirProperties.put(IntegrityAuditProperties.DB_URL, iae.getJdbcUrl());
+ theirProperties.put(IntegrityAuditProperties.DB_USER, iae.getJdbcUser());
+ theirProperties.put(IntegrityAuditProperties.DB_PWD, iae.getJdbcPassword());
+ theirProperties.put(IntegrityAuditProperties.SITE_NAME, iae.getSite());
+ theirProperties.put(IntegrityAuditProperties.NODE_TYPE, iae.getNodeType());
+
+ return theirProperties;
+ }
+
+ private void recompareList(String resourceName, String persistenceUnit, List<IntegrityAuditEntity> iaeList,
+ IntegrityAuditEntity myIae, Map<String, Set<Object>> misMatchedMap)
+ throws IntegrityAuditException {
+
+ Set<String> classNameSet;
+ long startTime;
classNameSet = new HashSet<>(misMatchedMap.keySet());
// We need to keep track of how long the audit is taking
startTime = AuditorTime.getInstance().getMillis();
@@ -267,53 +314,8 @@ public class DbAudit {
if (logger.isDebugEnabled()) {
logger.debug("dbAudit: Second comparison; traversing iaeList, size=" + iaeList.size());
}
- for (IntegrityAuditEntity iae : iaeList) {
- if (iae.getId() == myIae.getId()) {
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; My Id=" + iae.getId() + COMMA_RESOURCE_NAME
- + iae.getResourceName());
- }
- continue; // no need to compare with self
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Second comparison; Id=" + iae.getId() + COMMA_RESOURCE_NAME
- + iae.getResourceName());
- }
- }
- // Create properties for the other db node
- Properties theirProperties = new Properties();
- theirProperties.put(IntegrityAuditProperties.DB_DRIVER, iae.getJdbcDriver());
- theirProperties.put(IntegrityAuditProperties.DB_URL, iae.getJdbcUrl());
- theirProperties.put(IntegrityAuditProperties.DB_USER, iae.getJdbcUser());
- theirProperties.put(IntegrityAuditProperties.DB_PWD, iae.getJdbcPassword());
- theirProperties.put(IntegrityAuditProperties.SITE_NAME, iae.getSite());
- theirProperties.put(IntegrityAuditProperties.NODE_TYPE, iae.getNodeType());
-
- // get a map of the instances for their iae indexed by id
- Map<Object, Object> theirEntries =
- dbDao.getAllEntries(persistenceUnit, theirProperties, clazzName, keySet);
-
- /*
- * Compare myEntries with theirEntries and get back a set of mismatched IDs. Collect
- * the IDs for the class where a mismatch occurred. We will now write an error log
- * for each.
- */
- Set<Object> misMatchedKeySet = compareEntries(myEntries, theirEntries);
- if (!misMatchedKeySet.isEmpty()) {
- String keysString = "";
- for (Object key : misMatchedKeySet) {
- keysString = keysString.concat(key.toString() + ", ");
- errorCount++;
- }
- writeAuditSummaryLog(clazzName, resourceName, iae.getResourceName(), keysString);
- if (logger.isDebugEnabled()) {
- for (Object key : misMatchedKeySet) {
- writeAuditDebugLog(clazzName, resourceName, iae.getResourceName(), myEntries.get(key),
- theirEntries.get(key));
- }
- }
- }
- }
+ errorCount += recompareMineWithTheirs(resourceName, persistenceUnit, iaeList, myIae, clazzName,
+ keySet, myEntries);
// Time check
if ((AuditorTime.getInstance().getMillis() - startTime) >= DB_AUDIT_UPDATE_MS) {
// update the timestamp
@@ -337,12 +339,61 @@ public class DbAudit {
+ " errors found. A large number of errors may indicate DB replication has stopped";
logger.error(MessageCodes.ERROR_AUDIT, msg);
}
+ }
- if (logger.isDebugEnabled()) {
- logger.debug("dbAudit: Exiting");
+ private int recompareMineWithTheirs(String resourceName, String persistenceUnit, List<IntegrityAuditEntity> iaeList,
+ IntegrityAuditEntity myIae, String clazzName, Set<Object> keySet, Map<Object, Object> myEntries)
+ throws IntegrityAuditException {
+
+ int errorCount = 0;
+ for (IntegrityAuditEntity iae : iaeList) {
+ if (iae.getId() == myIae.getId()) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: Second comparison; My Id=" + iae.getId() + COMMA_RESOURCE_NAME
+ + iae.getResourceName());
+ }
+ continue; // no need to compare with self
+ }
+
+ if (logger.isDebugEnabled()) {
+ logger.debug("dbAudit: Second comparison; Id=" + iae.getId() + COMMA_RESOURCE_NAME
+ + iae.getResourceName());
+ }
+
+ // get a map of the instances for their iae indexed by id
+ Map<Object, Object> theirEntries =
+ dbDao.getAllEntries(persistenceUnit, getTheirDaoProperties(iae), clazzName, keySet);
+
+ /*
+ * Compare myEntries with theirEntries and get back a set of mismatched IDs.
+ * Collect the IDs for the class where a mismatch occurred. We will now write
+ * an error log for each.
+ */
+ errorCount += recompareMineWithTheirs(resourceName, clazzName, myEntries, iae, theirEntries);
}
+ return errorCount;
+ }
- return; // all done
+ private int recompareMineWithTheirs(String resourceName, String clazzName, Map<Object, Object> myEntries,
+ IntegrityAuditEntity iae, Map<Object, Object> theirEntries) throws IntegrityAuditException {
+ Set<Object> misMatchedKeySet = compareEntries(myEntries, theirEntries);
+ if (misMatchedKeySet.isEmpty()) {
+ return 0;
+ }
+
+ StringBuilder keyBuilder = new StringBuilder();
+ for (Object key : misMatchedKeySet) {
+ keyBuilder.append(key.toString());
+ keyBuilder.append(", ");
+ }
+ writeAuditSummaryLog(clazzName, resourceName, iae.getResourceName(), keyBuilder.toString());
+ if (logger.isDebugEnabled()) {
+ for (Object key : misMatchedKeySet) {
+ writeAuditDebugLog(clazzName, resourceName, iae.getResourceName(), myEntries.get(key),
+ theirEntries.get(key));
+ }
+ }
+ return misMatchedKeySet.size();
}
/**
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java
index 08243310..4833733c 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/DbDao.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.
@@ -29,7 +29,6 @@ import java.util.Set;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
-import javax.persistence.LockTimeoutException;
import javax.persistence.Persistence;
import javax.persistence.PersistenceUnitUtil;
import javax.persistence.Query;
@@ -45,11 +44,11 @@ import org.onap.policy.common.logging.flexlogger.Logger;
/**
* class DbDao provides the inteface to the DBs for the purpose of audits.
- *
+ *
*/
public class DbDao {
private static final Logger logger = FlexLogger.getLogger(DbDao.class.getName());
-
+
private String resourceName;
private String persistenceUnit;
private String dbDriver;
@@ -65,7 +64,7 @@ public class DbDao {
* Supports designation serialization.
*/
private static final Object lock = new Object();
-
+
/*
* Common strings.
*/
@@ -73,7 +72,7 @@ public class DbDao {
private static final String WITH_PERSISTENCE_MESSAGE = " with PersistenceUnit: ";
private static final String DBDAO_MESSAGE = "DbDao: ";
private static final String ENCOUNTERED_MESSAGE = "ecountered a problem in execution: ";
-
+
/*
* DB SELECT String.
*/
@@ -82,7 +81,7 @@ public class DbDao {
/**
* DbDao Constructor.
- *
+ *
* @param resourceName the resource name
* @param persistenceUnit the persistence unit
* @param properties the properties
@@ -94,7 +93,7 @@ public class DbDao {
/**
* DbDao Constructor.
- *
+ *
* @param resourceName the resource name
* @param persistenceUnit the persistence unit
* @param properties the properties
@@ -124,7 +123,7 @@ public class DbDao {
/**
* validateProperties will validate the properties.
- *
+ *
* @param resourceName the rseource name
* @param persistenceUnit the persistence unit
* @param properties the properties
@@ -151,7 +150,7 @@ public class DbDao {
/**
* getAllMyEntries gets all the DB entries for a particular class.
- *
+ *
* @param className the class name
* @return all the DB entries for the given class
*/
@@ -183,7 +182,7 @@ public class DbDao {
/**
* getAllMyEntries gets all entries for a class.
- *
+ *
* @param className the name of the class
* @param keySet the keys to get the entries for
* @return the map of requested entries
@@ -210,7 +209,7 @@ public class DbDao {
/**
* getAllEntries gets all entriesfor a particular persistence unit adn className.
- *
+ *
* @param persistenceUnit the persistence unit
* @param properties the properties
* @param className the class name
@@ -250,7 +249,7 @@ public class DbDao {
/**
* getAllEntries gets all entries for a persistence unit.
- *
+ *
* @param persistenceUnit the persistence unit
* @param properties the properties
* @param className the class name
@@ -284,7 +283,7 @@ public class DbDao {
/**
* getIntegrityAuditEntities() Get all the IntegrityAuditEntities for a particular persistence
* unit and node type.
- *
+ *
* @param persistenceUnit the persistence unit
* @param nodeType the node type
* @return the list of IntegrityAuditEntity
@@ -326,7 +325,7 @@ public class DbDao {
/**
* getMyIntegrityAuditEntity() gets my IntegrityAuditEntity.
- *
+ *
* @return the IntegrityAuditEntity
* @throws DbDaoTransactionException if an error occurs
*/
@@ -378,7 +377,7 @@ public class DbDao {
/**
* getIntegrityAuditEntity() gets the IntegrityAuditEntity with a particular ID.
- *
+ *
* @param id the ID
* @return the IntegrityAuditEntity
* @throws DbDaoTransactionException if an error occurs
@@ -407,7 +406,7 @@ public class DbDao {
/**
* getPersistenceClassNames() gets all the persistence class names.
- *
+ *
* @return the persistence class names
*/
public Set<String> getPersistenceClassNames() {
@@ -426,7 +425,7 @@ public class DbDao {
/**
* Register the IntegrityAudit instance.
- *
+ *
* @param altDbUrl alternate DB URL to be placed into the record, or {@code null} to use the
* default
*/
@@ -497,7 +496,7 @@ public class DbDao {
/**
* Set designated.
- *
+ *
* @param resourceName the resource name
* @param persistenceUnit the persistence unit
* @param desig true if is designated
@@ -559,7 +558,7 @@ public class DbDao {
/**
* Set last updated.
- *
+ *
* @throws DbDaoTransactionException if an error occurs
*/
public void setLastUpdated() throws DbDaoTransactionException {
@@ -659,20 +658,20 @@ public class DbDao {
/**
* Changes designation to specified resourceName
- *
+ *
* <p>static lock object in conjunction with synchronized keyword ensures that designation
* changes are done serially within a resource. I.e. static lock ensures that multiple
* instantiations of DbDao don't interleave changeDesignated() invocations and potentially
* produce simultaneous designations.
- *
+ *
* <p>Optimistic locking (the default, versus pessimistic) is sufficient to avoid simultaneous
* designations from interleaved changeDesignated() invocations from different resources
* (entities), because it prevents "dirty" and "non-repeatable" reads.
- *
+ *
* <p>See http://www.objectdb.com/api/java/jpa/LockModeType
- *
+ *
* <p>and
- *
+ *
* <p>http://stackoverflow.com/questions/2120248/how-to-synchronize-a-static-
* variable-among-threads-running-different-instances-o
*/
@@ -706,26 +705,7 @@ public class DbDao {
* Execute query using pessimistic write lock. This ensures that if anyone else is
* currently reading the records we'll throw a LockTimeoutException.
*/
- @SuppressWarnings("unchecked")
- List<IntegrityAuditEntity> integrityAuditEntityList = query.getResultList();
- for (Object o : integrityAuditEntityList) {
- if (o instanceof IntegrityAuditEntity) {
- IntegrityAuditEntity integrityAuditEntity = (IntegrityAuditEntity) o;
- if (integrityAuditEntity.getResourceName().equals(resourceName)) {
- if (logger.isDebugEnabled()) {
- logger.debug("changeDesignated: Designating resourceName="
- + integrityAuditEntity.getResourceName());
- }
- integrityAuditEntity.setDesignated(true);
- } else {
- if (logger.isDebugEnabled()) {
- logger.debug("changeDesignated: Removing designation from resourceName="
- + integrityAuditEntity.getResourceName());
- }
- integrityAuditEntity.setDesignated(false);
- }
- }
- }
+ setDesignatedEntity(resourceName, query);
if (logger.isDebugEnabled()) {
logger.debug("changeDesignated: Committing designation to resourceName=" + resourceName);
@@ -739,20 +719,6 @@ public class DbDao {
* read/update are pretty slim (we're only in this method for two or three
* milliseconds)
*/
- } catch (LockTimeoutException e) {
- if (em != null) {
- em.getTransaction().rollback();
-
- String msg = "DbDao: changeDesignated() caught LockTimeoutException, message="
- + e.getMessage();
- logger.error(msg + e);
- throw new DbDaoTransactionException(msg, e);
- } else {
- String msg = "DbDao: changeDesignated() caught LockTimeoutException, message="
- + e.getMessage() + ". Error rolling back transaction.";
- logger.error(msg + e);
- throw new DbDaoTransactionException(msg, e);
- }
} catch (Exception e) {
if (em != null) {
em.getTransaction().rollback();
@@ -777,4 +743,27 @@ public class DbDao {
}
+ private void setDesignatedEntity(String resourceName, Query query) {
+ for (Object o : query.getResultList()) {
+ if (!(o instanceof IntegrityAuditEntity)) {
+ continue;
+ }
+
+ IntegrityAuditEntity integrityAuditEntity = (IntegrityAuditEntity) o;
+ if (integrityAuditEntity.getResourceName().equals(resourceName)) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("changeDesignated: Designating resourceName="
+ + integrityAuditEntity.getResourceName());
+ }
+ integrityAuditEntity.setDesignated(true);
+ } else {
+ if (logger.isDebugEnabled()) {
+ logger.debug("changeDesignated: Removing designation from resourceName="
+ + integrityAuditEntity.getResourceName());
+ }
+ integrityAuditEntity.setDesignated(false);
+ }
+ }
+ }
+
}
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
index d50c7059..02e4c70b 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAudit.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
@@ -21,6 +21,7 @@
package org.onap.policy.common.ia;
import java.util.Properties;
+import org.apache.commons.lang3.StringUtils;
import org.onap.policy.common.ia.IntegrityAuditProperties.NodeTypeEnum;
import org.onap.policy.common.logging.flexlogger.FlexLogger;
import org.onap.policy.common.logging.flexlogger.Logger;
@@ -46,18 +47,18 @@ public class IntegrityAudit {
/*
* This is the audit period in milliseconds. For example, if it had a value of 3600000, the
* audit can only run once per hour. If it has a value of 6000, it can run once per minute.
- *
+ *
* Values: integrityAuditPeriodSeconds < 0 (negative number) indicates the audit is off
* integrityAuditPeriodSeconds == 0 indicates the audit is to run continuously
* integrityAuditPeriodSeconds > 0 indicates the audit is to run at most once during the
* indicated period
- *
+ *
*/
private int integrityAuditPeriodSeconds;
/**
* IntegrityAudit constructor.
- *
+ *
* @param resourceName the resource name
* @param persistenceUnit the persistence unit
* @param properties the properties
@@ -118,100 +119,97 @@ public class IntegrityAudit {
public static boolean parmsAreBad(String resourceName, String persistenceUnit, Properties properties,
StringBuilder badparams) {
- boolean parmsAreBad = false;
-
- if (resourceName == null || resourceName.isEmpty()) {
- badparams.append("resourceName ");
- parmsAreBad = true;
- }
-
- if (persistenceUnit == null || persistenceUnit.isEmpty()) {
- badparams.append("persistenceUnit ");
- parmsAreBad = true;
- }
+ boolean parmsAreBad = checkEmpty(badparams, "resourceName", resourceName);
+ parmsAreBad = checkEmpty(badparams, "persistenceUnit", persistenceUnit) || parmsAreBad;
if (properties == null || properties.isEmpty()) {
badparams.append("properties ");
parmsAreBad = true;
} else {
- String dbDriver = properties.getProperty(IntegrityAuditProperties.DB_DRIVER);
- if (dbDriver == null || dbDriver.isEmpty()) {
- badparams.append("dbDriver ");
- parmsAreBad = true;
- }
+ parmsAreBad = checkProperties(properties, badparams) || parmsAreBad;
+ } // End else
+ logger.debug("parmsAreBad: exit:" + "\nresourceName: " + resourceName + "\npersistenceUnit: " + persistenceUnit
+ + "\nproperties: " + properties);
- String dbUrl = properties.getProperty(IntegrityAuditProperties.DB_URL);
- if (dbUrl == null || dbUrl.isEmpty()) {
- badparams.append("dbUrl ");
- parmsAreBad = true;
- }
+ return parmsAreBad;
+ }
- String dbUser = properties.getProperty(IntegrityAuditProperties.DB_USER);
- if (dbUser == null || dbUser.isEmpty()) {
- badparams.append("dbUser ");
- parmsAreBad = true;
- }
+ private static boolean checkEmpty(StringBuilder builder, String name, String value) {
+ if (StringUtils.isEmpty(value)) {
+ builder.append(name);
+ builder.append(' ');
+ return true;
- String dbPwd = properties.getProperty(IntegrityAuditProperties.DB_PWD);
- if (dbPwd == null) { // may be empty
- badparams.append("dbPwd ");
- parmsAreBad = true;
- }
+ } else {
+ return false;
+ }
+ }
- String siteName = properties.getProperty(IntegrityAuditProperties.SITE_NAME);
- if (siteName == null || siteName.isEmpty()) {
- badparams.append("siteName ");
- parmsAreBad = true;
- }
+ private static boolean checkProperties(Properties properties, StringBuilder badparams) {
+ boolean parmsAreBad =
+ checkEmpty(badparams, "dbDriver", properties.getProperty(IntegrityAuditProperties.DB_DRIVER));
+ parmsAreBad = checkEmpty(badparams, "dbUrl", properties.getProperty(IntegrityAuditProperties.DB_URL))
+ || parmsAreBad;
+ parmsAreBad = checkEmpty(badparams, "dbUser", properties.getProperty(IntegrityAuditProperties.DB_USER))
+ || parmsAreBad;
+ parmsAreBad = checkEmpty(badparams, "dbPwd", properties.getProperty(IntegrityAuditProperties.DB_PWD))
+ || parmsAreBad;
+ parmsAreBad = checkEmpty(badparams, "siteName", properties.getProperty(IntegrityAuditProperties.SITE_NAME))
+ || parmsAreBad;
+ parmsAreBad = checkNodeType(properties, badparams) || parmsAreBad;
+
+ return checkAuditPeriod(properties, badparams) || parmsAreBad;
+ }
- String nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE);
- if (nodeType == null || nodeType.isEmpty()) {
- badparams.append("nodeType ");
- parmsAreBad = true;
- } else {
- nodeType = nodeType.trim();
- if (!isNodeTypeEnum(nodeType)) {
- String nodetypes = "nodeType must be one of[";
- for (NodeTypeEnum n : NodeTypeEnum.values()) {
- nodetypes = nodetypes.concat(n.toString() + " ");
- }
- badparams.append(nodetypes + "] ");
- parmsAreBad = true;
- }
- }
- // IntegrityAuditProperties.AUDIT_PERIOD_SECONDS and
- // IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS are allowed to be null
- if (properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS) != null) {
- try {
- Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
- } catch (NumberFormatException nfe) {
- badparams.append(", auditPeriodSeconds="
- + properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
- parmsAreBad = true;
+ private static boolean checkNodeType(Properties properties, StringBuilder badparams) {
+ String nodeType = properties.getProperty(IntegrityAuditProperties.NODE_TYPE);
+ if (nodeType == null || nodeType.isEmpty()) {
+ badparams.append("nodeType ");
+ return true;
+ } else {
+ nodeType = nodeType.trim();
+ if (!isNodeTypeEnum(nodeType)) {
+ String nodetypes = "nodeType must be one of[";
+ for (NodeTypeEnum n : NodeTypeEnum.values()) {
+ nodetypes = nodetypes.concat(n.toString() + " ");
}
+ badparams.append(nodetypes + "] ");
+ return true;
}
- } // End else
- logger.debug("parmsAreBad: exit:" + "\nresourceName: " + resourceName + "\npersistenceUnit: " + persistenceUnit
- + "\nproperties: " + properties);
+ }
+ return false;
+ }
- return parmsAreBad;
+ private static boolean checkAuditPeriod(Properties properties, StringBuilder badparams) {
+ // IntegrityAuditProperties.AUDIT_PERIOD_SECONDS and
+ // IntegrityAuditProperties.AUDIT_PERIOD_MILLISECONDS are allowed to be null
+ if (properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS) != null) {
+ try {
+ Integer.parseInt(properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
+ } catch (NumberFormatException nfe) {
+ badparams.append(", auditPeriodSeconds="
+ + properties.getProperty(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS).trim());
+ return true;
+ }
+ }
+ return false;
}
/**
* Starts the audit thread.
- *
+ *
* @throws IntegrityAuditException if an error occurs
*/
public void startAuditThread() throws IntegrityAuditException {
logger.info("startAuditThread: Entering");
if (integrityAuditPeriodSeconds >= 0) {
- this.auditThread = makeAuditThread(this.resourceName, this.persistenceUnit,
+ this.auditThread = makeAuditThread(this.resourceName, this.persistenceUnit,
this.properties, integrityAuditPeriodSeconds);
- logger.info("startAuditThread: Audit started and will run every " + integrityAuditPeriodSeconds
+ logger.info("startAuditThread: Audit started and will run every " + integrityAuditPeriodSeconds
+ " seconds");
this.auditThread.start();
-
+
} else {
logger.info("startAuditThread: Suppressing integrity audit, integrityAuditPeriodSeconds="
+ integrityAuditPeriodSeconds);
@@ -255,7 +253,7 @@ public class IntegrityAudit {
/**
* Waits a bit for the AuditThread to complete. Used by JUnit tests.
- *
+ *
* @param twaitms wait time, in milliseconds
* @return {@code true} if the thread stopped within the given time, {@code false} otherwise
* @throws InterruptedException if the thread is interrupted
@@ -272,7 +270,7 @@ public class IntegrityAudit {
/**
* Return if audit thread.
- *
+ *
* @return {@code true} if an audit thread exists, {@code false} otherwise
*/
protected boolean haveAuditThread() {
@@ -281,12 +279,12 @@ public class IntegrityAudit {
/**
* Creates an audit thread. May be overridden by junit tests.
- *
+ *
* @param resourceName2 the resource name
* @param persistenceUnit2 the persistence unit
* @param properties2 properties
* @param integrityAuditPeriodSeconds2
- *
+ *
* @return a new audit thread
* @throws IntegrityAuditException audit exception
*/
diff --git a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
index 3afab61f..2ca5dd58 100644
--- a/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
+++ b/integrity-audit/src/main/java/org/onap/policy/common/ia/IntegrityAuditProperties.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java
index 9aad6863..b5a4eeea 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/AuditPeriodTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
@@ -25,9 +25,6 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;
-
-//import org.apache.commons.logging.Log;
-//import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -100,7 +97,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase {
/*
* Sleep long enough to allow
- *
+ *
* 1) audit to immediately terminate.
*/
waitThread(integrityAudit);
@@ -129,7 +126,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase {
/*
* Wait for
- *
+ *
* 1) audit to generate a bunch of sleep wake sequences.
*/
String[] awakings = new String[10];
@@ -170,12 +167,12 @@ public class AuditPeriodTest extends IntegrityAuditTestBase {
/**
* Verifies that audits actually take as long as expected, even with multiple auditors running
* simultaneously.
- *
+ *
* @param periodSec audit period, in seconds
* @throws Exception if an error occurs
* @throws InterruptedException if the thread is interrupted
*/
- private void testAuditPeriod(long periodSec) throws Exception, InterruptedException {
+ private void testAuditPeriod(long periodSec) throws Exception {
properties.put(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS, String.valueOf(periodSec));
@@ -207,7 +204,7 @@ public class AuditPeriodTest extends IntegrityAuditTestBase {
/**
* Runs simultaneous audits on several auditors.
- *
+ *
* @param auditors the auditors
* @return the minimum time, in milliseconds, elapsed for any given auditor
* @throws InterruptedException if the thread is interrupted
@@ -226,13 +223,13 @@ public class AuditPeriodTest extends IntegrityAuditTestBase {
long tbegin = p.getTimeInMillis();
runAudit(p);
long elapsed = p.getTimeInMillis() - tbegin;
-
+
synchronized (tmin) {
tmin.set(Math.min(tmin.get(), elapsed));
}
} catch (InterruptedException e) {
- ;
+ Thread.currentThread().interrupt();
}
}
};
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java
index a5d0ef1b..965712a2 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbAuditCompareEntriesTest.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.
@@ -49,6 +49,7 @@ import org.onap.policy.common.logging.flexlogger.Logger;
* tasks.
*/
public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
+ private static final String ZAPHOD = "Zaphod";
private static Logger logger = FlexLogger.getLogger(DbAuditCompareEntriesTest.class);
@@ -113,7 +114,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
// anyway
Set<String> classNameSet = dbDao.getPersistenceClassNames();
for (String c : classNameSet) {
- if (c.equals("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")) {
+ if ("org.onap.policy.common.ia.jpa.IntegrityAuditEntity".equals(c)) {
className = c;
}
}
@@ -129,7 +130,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
*/
entry1.setDesignated(false);
entry1.setJdbcDriver(dbDriver);
- entry1.setJdbcPassword(dbPwd);
+ entry1.setJdbcPassword(dbPass);
entry1.setJdbcUrl(dbUrl);
entry1.setJdbcUser(dbUser);
entry1.setLastUpdated(date);
@@ -140,7 +141,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry2.setDesignated(false);
entry2.setJdbcDriver(dbDriver);
- entry2.setJdbcPassword(dbPwd);
+ entry2.setJdbcPassword(dbPass);
entry2.setJdbcUrl(dbUrl);
entry2.setJdbcUser(dbUser);
entry2.setLastUpdated(date);
@@ -151,8 +152,8 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
dbAudit.writeAuditDebugLog(className, resourceName1, resourceName2, entry1, entry2);
- HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
- HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
myEntries.put("pdp1", entry1);
theirEntries.put("pdp1", entry2);
@@ -190,7 +191,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
*/
entry1.setDesignated(false);
entry1.setJdbcDriver(dbDriver);
- entry1.setJdbcPassword(dbPwd);
+ entry1.setJdbcPassword(dbPass);
entry1.setJdbcUrl(dbUrl);
entry1.setJdbcUser(dbUser);
entry1.setLastUpdated(date);
@@ -201,7 +202,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry2.setDesignated(true);
entry2.setJdbcDriver(dbDriver);
- entry2.setJdbcPassword(dbPwd);
+ entry2.setJdbcPassword(dbPass);
entry2.setJdbcUrl(dbUrl);
entry2.setJdbcUser(dbUser);
entry2.setLastUpdated(date);
@@ -210,8 +211,8 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry2.setResourceName(resourceName2);
entry2.setSite(siteName);
- HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
- HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
myEntries.put("pdp1", entry1);
theirEntries.put("pdp1", entry2);
@@ -253,7 +254,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
*/
entry1.setDesignated(false);
entry1.setJdbcDriver(dbDriver);
- entry1.setJdbcPassword(dbPwd);
+ entry1.setJdbcPassword(dbPass);
entry1.setJdbcUrl(dbUrl);
entry1.setJdbcUser(dbUser);
entry1.setLastUpdated(date);
@@ -264,7 +265,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry2.setDesignated(true);
entry2.setJdbcDriver(dbDriver);
- entry2.setJdbcPassword(dbPwd);
+ entry2.setJdbcPassword(dbPass);
entry2.setJdbcUrl(dbUrl);
entry2.setJdbcUser(dbUser);
entry2.setLastUpdated(date);
@@ -275,7 +276,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry3.setDesignated(false);
entry3.setJdbcDriver(dbDriver);
- entry3.setJdbcPassword(dbPwd);
+ entry3.setJdbcPassword(dbPass);
entry3.setJdbcUrl(dbUrl);
entry3.setJdbcUser(dbUser);
entry3.setLastUpdated(date);
@@ -286,7 +287,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry4.setDesignated(false);
entry4.setJdbcDriver(dbDriver);
- entry4.setJdbcPassword(dbPwd);
+ entry4.setJdbcPassword(dbPass);
entry4.setJdbcUrl(dbUrl);
entry4.setJdbcUser(dbUser);
entry4.setLastUpdated(date);
@@ -295,8 +296,8 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry4.setResourceName(resourceName2);
entry4.setSite("SiteB");
- HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
- HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
myEntries.put("0", entry1);
myEntries.put("1", entry3);
@@ -325,9 +326,8 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
DbAudit dbAudit = new DbAudit(dbDao);
Set<String> classNameSet = dbDao.getPersistenceClassNames();
- Set<Object> mismatchResult = new HashSet<Object>();
for (String className : classNameSet) {
- if (className.equals("org.onap.policy.common.ia.jpa.IntegrityAuditEntity")) {
+ if ("org.onap.policy.common.ia.jpa.IntegrityAuditEntity".equals(className)) {
final String resourceName1 = resourceName;
final String resourceName2 = resourceName;
@@ -340,7 +340,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
*/
entry1.setDesignated(false);
entry1.setJdbcDriver(dbDriver);
- entry1.setJdbcPassword(dbPwd);
+ entry1.setJdbcPassword(dbPass);
entry1.setJdbcUrl(dbUrl);
entry1.setJdbcUser(dbUser);
entry1.setLastUpdated(date);
@@ -351,7 +351,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry2.setDesignated(false);
entry2.setJdbcDriver(dbDriver);
- entry2.setJdbcPassword(dbPwd);
+ entry2.setJdbcPassword(dbPass);
entry2.setJdbcUrl(dbUrl);
entry2.setJdbcUser(dbUser);
entry2.setLastUpdated(date);
@@ -360,19 +360,17 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
entry2.setResourceName(resourceName2);
entry2.setSite(siteName);
- HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
- HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
myEntries.put("pdp1", entry1);
theirEntries.put("pdp1", entry2);
- mismatchResult = dbAudit.compareEntries(myEntries, theirEntries);
-
/*
* Assert there was no mismatches
*/
- assertTrue(mismatchResult.isEmpty());
- } else if (className.equals("org.onap.policy.common.ia.jpa.IaTestEntity")) {
+ assertTrue(dbAudit.compareEntries(myEntries, theirEntries).isEmpty());
+ } else if ("org.onap.policy.common.ia.jpa.IaTestEntity".equals(className)) {
final IaTestEntity iate = new IaTestEntity();
final IaTestEntity iate2 = new IaTestEntity();
final IaTestEntity iate3 = new IaTestEntity();
@@ -388,10 +386,10 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
iate.setModifiedDate(date);
iate2.setCreatedBy("Ford");
- iate2.setModifiedBy("Zaphod");
+ iate2.setModifiedBy(ZAPHOD);
iate2.setModifiedDate(date);
- iate3.setCreatedBy("Zaphod");
+ iate3.setCreatedBy(ZAPHOD);
iate3.setModifiedBy("Ford");
iate3.setModifiedDate(date);
@@ -399,20 +397,19 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
iate4.setModifiedBy("Ford");
iate4.setModifiedDate(date);
- HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
- HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
myEntries.put("0", iate);
myEntries.put("1", iate2);
theirEntries.put("0", iate3);
theirEntries.put("1", iate4);
- mismatchResult = dbAudit.compareEntries(myEntries, theirEntries);
/*
* Assert that there is 2 mismatches
*/
- assertEquals(2, mismatchResult.size());
+ assertEquals(2, dbAudit.compareEntries(myEntries, theirEntries).size());
}
}
@@ -454,7 +451,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
Set<String> classNameSet = dbDao.getPersistenceClassNames();
Map<Object, Object> myEntries;
Map<Object, Object> theirEntries;
- Set<Object> mismatchResult = new HashSet<Object>();
+ Set<Object> mismatchResult = new HashSet<>();
for (String className : classNameSet) {
logger.info("classNameSet entry = " + className);
myEntries = dbDao.getAllEntries(A_SEQ_PU, properties, className);
@@ -475,7 +472,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
/**
* Truncate the tables.
- *
+ *
* @param properties the properties
*/
private void truncateTables(Properties properties) {
@@ -499,7 +496,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
// anyway
Set<String> classNameSet = dbDao.getPersistenceClassNames();
for (String classNameInClassNameSet : classNameSet) {
- if (classNameInClassNameSet.equals("org.onap.policy.common.ia.jpa.IaTestEntity")) {
+ if ("org.onap.policy.common.ia.jpa.IaTestEntity".equals(classNameInClassNameSet)) {
className = classNameInClassNameSet;
}
}
@@ -510,7 +507,7 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
final Date date = new Date();
PersonSample person = new PersonSample("Ford", "Prefect", 21);
- PersonSample person2 = new PersonSample("Zaphod", "Beeblebrox", 25);
+ PersonSample person2 = new PersonSample(ZAPHOD, "Beeblebrox", 25);
/*
* Silly tests to bump coverage stats, not sure why they are counting PersonSample to begin
@@ -527,19 +524,19 @@ public class DbAuditCompareEntriesTest extends IntegrityAuditTestBase {
* Two entries, 1 mismatch
*/
iate.setCreatedBy("Ford");
- iate.setModifiedBy("Zaphod");
+ iate.setModifiedBy(ZAPHOD);
iate.setModifiedDate(date);
iate.setPersonTest(person);
iate2.setCreatedBy("Ford");
- iate2.setModifiedBy("Zaphod");
+ iate2.setModifiedBy(ZAPHOD);
iate2.setModifiedDate(date);
iate2.setPersonTest(person2);
dbAudit.writeAuditDebugLog(className, "resource1", "resource2", iate, iate2);
- HashMap<Object, Object> myEntries = new HashMap<Object, Object>();
- HashMap<Object, Object> theirEntries = new HashMap<Object, Object>();
+ HashMap<Object, Object> myEntries = new HashMap<>();
+ HashMap<Object, Object> theirEntries = new HashMap<>();
myEntries.put("0", iate);
theirEntries.put("0", iate2);
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) {
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java
index 357e638c..ef21e831 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/DbDaoTest.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.
@@ -60,6 +60,11 @@ import org.onap.policy.common.utils.time.TestTime;
* tasks.
*/
public class DbDaoTest extends IntegrityAuditTestBase {
+ private static final String SELECT_ENTITIES =
+ "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu";
+ private static final String SITE_B = "SiteB";
+ private static final String ENTITY_CLASS_NAME = "org.onap.policy.common.ia.jpa.IntegrityAuditEntity";
+
private static String resourceName = "pdp0";
private DbDao dbDao;
@@ -103,8 +108,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
// Find the proper entry in the database
- Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ Query iaequery = em.createQuery(SELECT_ENTITIES);
iaequery.setParameter("rn", DbDaoTest.resourceName);
iaequery.setParameter("pu", DbDaoTest.A_SEQ_PU);
@@ -131,13 +135,12 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// Change site_name in properties to test that an update was made to
// an existing entry in the table
- properties.put(IntegrityAuditProperties.SITE_NAME, "SiteB");
+ properties.put(IntegrityAuditProperties.SITE_NAME, SITE_B);
dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) {
// Find the proper entry in the database
- Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ Query iaequery = em.createQuery(SELECT_ENTITIES);
iaequery.setParameter("rn", DbDaoTest.resourceName);
iaequery.setParameter("pu", DbDaoTest.A_SEQ_PU);
@@ -158,7 +161,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
et.commit();
// Assert that the site_name for the existing entry was updated
- assertEquals("SiteB", iae.getSite());
+ assertEquals(SITE_B, iae.getSite());
}
}
}
@@ -187,7 +190,6 @@ public class DbDaoTest extends IntegrityAuditTestBase {
dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
IntegrityAuditEntity iae = dbDao.getMyIntegrityAuditEntity();
- // assertEquals("integrityAuditPU", iae.getPersistenceUnit());
assertEquals(A_SEQ_PU, iae.getPersistenceUnit());
}
@@ -200,8 +202,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
// Find the proper database entry
- Query iaequery = em
- .createQuery("Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ Query iaequery = em.createQuery(SELECT_ENTITIES);
iaequery.setParameter("rn", DbDaoTest.resourceName);
iaequery.setParameter("pu", DbDaoTest.A_SEQ_PU);
@@ -239,8 +240,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
dbDao.setDesignated(resourceName, A_SEQ_PU, true);
// Find the proper entry in the database
- Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ Query iaequery = em.createQuery(SELECT_ENTITIES);
iaequery.setParameter("rn", resourceName);
iaequery.setParameter("pu", A_SEQ_PU);
@@ -275,13 +275,12 @@ public class DbDaoTest extends IntegrityAuditTestBase {
try (EntityTransCloser et = new EntityTransCloser(em.getTransaction())) {
TestTime testTime = getTestTime();
-
+
// Create an entry
dbDao = new DbDao(resourceName, A_SEQ_PU, properties);
// Find the proper entry in the database
- Query iaequery = em.createQuery(
- "Select i from IntegrityAuditEntity i where i.resourceName=:rn and i.persistenceUnit=:pu");
+ Query iaequery = em.createQuery(SELECT_ENTITIES);
iaequery.setParameter("rn", resourceName);
iaequery.setParameter("pu", A_SEQ_PU);
@@ -301,7 +300,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// ensure dates are different by sleeping for a bit
testTime.sleep(1);
- iae.setSite("SiteB");
+ iae.setSite(SITE_B);
iae.setLastUpdated(testTime.getDate());
final Date newDate = iae.getLastUpdated();
@@ -328,7 +327,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
new DbDao("pdp2", A_SEQ_PU, properties).destroy();
// Obtain a hash with the persisted objects
- Map<Object, Object> entries = dbDao.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
+ Map<Object, Object> entries = dbDao.getAllMyEntries(ENTITY_CLASS_NAME);
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -349,11 +348,11 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// Obtain all entity keys
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object> cq = cb.createQuery();
- Root<?> rootEntry = cq.from(Class.forName("org.onap.policy.common.ia.jpa.IntegrityAuditEntity"));
+ Root<?> rootEntry = cq.from(Class.forName(ENTITY_CLASS_NAME));
CriteriaQuery<Object> all = cq.select(rootEntry);
TypedQuery<Object> allQuery = em.createQuery(all);
List<Object> objectList = allQuery.getResultList();
- HashSet<Object> resultSet = new HashSet<Object>();
+ HashSet<Object> resultSet = new HashSet<>();
PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
for (Object o : objectList) {
Object key = util.getIdentifier(o);
@@ -362,7 +361,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// Obtain a hash with the persisted objects
Map<Object, Object> entries =
- dbDao.getAllMyEntries("org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet);
+ dbDao.getAllMyEntries(ENTITY_CLASS_NAME, resultSet);
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -383,7 +382,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// Obtain a hash with the persisted objects
Map<Object, Object> entries = dbDao.getAllEntries("integrityAuditPU", properties,
- "org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
+ ENTITY_CLASS_NAME);
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -405,11 +404,11 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// Obtain all entity keys
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object> cq = cb.createQuery();
- Root<?> rootEntry = cq.from(Class.forName("org.onap.policy.common.ia.jpa.IntegrityAuditEntity"));
+ Root<?> rootEntry = cq.from(Class.forName(ENTITY_CLASS_NAME));
CriteriaQuery<Object> all = cq.select(rootEntry);
TypedQuery<Object> allQuery = em.createQuery(all);
List<Object> objectList = allQuery.getResultList();
- HashSet<Object> resultSet = new HashSet<Object>();
+ HashSet<Object> resultSet = new HashSet<>();
PersistenceUnitUtil util = emf.getPersistenceUnitUtil();
for (Object o : objectList) {
Object key = util.getIdentifier(o);
@@ -418,7 +417,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// Obtain a hash with the persisted objects
Map<Object, Object> entries = dbDao.getAllEntries("integrityAuditPU", properties,
- "org.onap.policy.common.ia.jpa.IntegrityAuditEntity", resultSet);
+ ENTITY_CLASS_NAME, resultSet);
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
@@ -439,7 +438,7 @@ public class DbDaoTest extends IntegrityAuditTestBase {
// Obtain a hash with the persisted objects
Map<Object, Object> entries =
- dbDao.getAllEntries(A_SEQ_PU, properties, "org.onap.policy.common.ia.jpa.IntegrityAuditEntity");
+ dbDao.getAllEntries(A_SEQ_PU, properties, ENTITY_CLASS_NAME);
// Assert there were 3 entries for that class
assertEquals(3, entries.size());
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java
index 3c8ce528..40f7a738 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/ExceptionsTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Monitor
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
@@ -31,22 +31,22 @@ import org.onap.policy.common.utils.test.ExceptionsTester;
public class ExceptionsTest extends ExceptionsTester {
@Test
- public void testDbAuditException() throws Exception {
+ public void testDbAuditException() {
assertEquals(4, test(DbAuditException.class));
}
@Test
- public void testDbDaoTransactionException() throws Exception {
+ public void testDbDaoTransactionException() {
assertEquals(4, test(DbDaoTransactionException.class));
}
@Test
- public void testIntegrityAuditException() throws Exception {
+ public void testIntegrityAuditException() {
assertEquals(4, test(IntegrityAuditException.class));
}
@Test
- public void testIntegrityAuditPropertiesException() throws Exception {
+ public void testIntegrityAuditPropertiesException() {
assertEquals(4, test(IntegrityAuditPropertiesException.class));
}
}
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java
index 5adbb561..34a9364f 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
@@ -28,6 +28,9 @@ import java.util.Properties;
import org.junit.Test;
public class IntegrityAuditTest {
+ private static final String PROPERTIES = "properties";
+ private static final String RESOURCE_NAME = "resourceName";
+ private static final String SOMETHING = "something";
@Test
/**
@@ -36,33 +39,33 @@ public class IntegrityAuditTest {
public void parmsAreBadTest() {
// Try with 2 null params
StringBuilder badParams = new StringBuilder();
- IntegrityAudit.parmsAreBad(null, "something", null, badParams);
+ IntegrityAudit.parmsAreBad(null, SOMETHING, null, badParams);
assertFalse("".equals(badParams.toString()));
- assertTrue(badParams.toString().contains("resourceName"));
- assertTrue(badParams.toString().contains("properties"));
+ assertTrue(badParams.toString().contains(RESOURCE_NAME));
+ assertTrue(badParams.toString().contains(PROPERTIES));
// Try with 1 null params
badParams = new StringBuilder();
Properties props = new Properties();
props.put(IntegrityAuditProperties.DB_DRIVER, "test_db_driver");
- IntegrityAudit.parmsAreBad(null, "something", props, badParams);
+ IntegrityAudit.parmsAreBad(null, SOMETHING, props, badParams);
assertFalse("".equals(badParams.toString()));
- assertTrue(badParams.toString().contains("resourceName"));
- assertFalse(badParams.toString().contains("properties"));
+ assertTrue(badParams.toString().contains(RESOURCE_NAME));
+ assertFalse(badParams.toString().contains(PROPERTIES));
// Try with 0 null params
badParams = new StringBuilder();
- IntegrityAudit.parmsAreBad("someting", "something", props, badParams);
+ IntegrityAudit.parmsAreBad("someting", SOMETHING, props, badParams);
assertFalse("".equals(badParams.toString()));
- assertFalse(badParams.toString().contains("resourceName"));
- assertFalse(badParams.toString().contains("properties"));
+ assertFalse(badParams.toString().contains(RESOURCE_NAME));
+ assertFalse(badParams.toString().contains(PROPERTIES));
// Try with invalid node type
props.put(IntegrityAuditProperties.NODE_TYPE, "bogus");
badParams = new StringBuilder();
- IntegrityAudit.parmsAreBad("someting", "something", props, badParams);
+ IntegrityAudit.parmsAreBad("someting", SOMETHING, props, badParams);
assertFalse("".equals(badParams.toString()));
assertTrue(badParams.toString().contains("nodeType"));
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java
index 9324dfb4..0edaaa78 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/IntegrityAuditTestBase.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
@@ -52,12 +52,12 @@ import org.slf4j.LoggerFactory;
/**
* All JUnits are designed to run in the local development environment where they have write
* privileges and can execute time-sensitive tasks.
- *
+ *
* <p>Many of the test verification steps are performed by scanning for items written to the log
* file. Rather than actually scan the log file, an {@link ExtractAppender} is used to monitor
* events that are logged and extract relevant items. In order to attach the appender to the debug
* log, it assumes that the debug log is a <i>logback</i> Logger configured per EELF.
- *
+ *
* <p>These tests use a temporary, in-memory DB, which is dropped once the tests complete.
*/
public class IntegrityAuditTestBase {
@@ -77,7 +77,7 @@ public class IntegrityAuditTestBase {
*/
private static final String LOG_DIR = "testingLogs/common-modules/integrity-audit";
-
+
/**
* Name of the field within the AuditorTime class that supplies the time.
*/
@@ -88,7 +88,7 @@ public class IntegrityAuditTestBase {
* Max time, in milliseconds, to wait for a semaphore.
*/
protected static final long WAIT_MS = 5000L;
-
+
/**
* Number of seconds in an audit period.
*/
@@ -98,7 +98,7 @@ public class IntegrityAuditTestBase {
protected static final String dbDriver = "org.h2.Driver";
protected static final String dbUser = "testu";
- protected static final String dbPwd = "testp";
+ protected static final String dbPass = "testp";
protected static final String siteName = "SiteA";
protected static final String nodeType = "pdp_xacml";
@@ -173,7 +173,7 @@ public class IntegrityAuditTestBase {
/**
* Saves current configuration information and then sets new values.
- *
+ *
* @param dbDriver the name of the DB Driver class
* @param dbUrl the URL to the DB
* @throws IOException if an IO error occurs
@@ -199,7 +199,7 @@ public class IntegrityAuditTestBase {
properties.put(IntegrityAuditProperties.DB_DRIVER, dbDriver);
properties.put(IntegrityAuditProperties.DB_URL, dbUrl);
properties.put(IntegrityAuditProperties.DB_USER, dbUser);
- properties.put(IntegrityAuditProperties.DB_PWD, dbPwd);
+ properties.put(IntegrityAuditProperties.DB_PWD, dbPass);
properties.put(IntegrityAuditProperties.SITE_NAME, siteName);
properties.put(IntegrityAuditProperties.NODE_TYPE, nodeType);
@@ -218,7 +218,7 @@ public class IntegrityAuditTestBase {
* Restores the configuration to what it was before the test.
*/
protected static void tearDownAfterClass() {
-
+
IntegrityAudit.setUnitTesting(false);
Whitebox.setInternalState(AuditorTime.class, TIME_SUPPLY_FIELD, savedTime);
@@ -238,7 +238,7 @@ public class IntegrityAuditTestBase {
appenders = new LinkedList<>();
properties.put(IntegrityAuditProperties.AUDIT_PERIOD_SECONDS, String.valueOf(AUDIT_PERIOD_SEC));
-
+
TestTime time = new TestTime();
testTime.set(time);
@@ -269,7 +269,7 @@ public class IntegrityAuditTestBase {
/**
* Get the test time.
- *
+ *
* @return the {@link TestTime} in use by this thread
*/
public static TestTime getTestTime() {
@@ -278,7 +278,7 @@ public class IntegrityAuditTestBase {
/**
* Truncate the table.
- *
+ *
* @param properties the properties
* @param persistenceUnit the persistence unit
* @param tableName the name of the table
@@ -290,21 +290,21 @@ public class IntegrityAuditTestBase {
EntityMgrCloser emc = new EntityMgrCloser(emfc.getFactory().createEntityManager());
EntityTransCloser etc = new EntityTransCloser(emc.getManager().getTransaction())) {
- EntityManager em = emc.getManager();
- EntityTransaction et = etc.getTransation();
+ EntityManager entmgr = emc.getManager();
+ EntityTransaction entrans = etc.getTransation();
// Clean up the DB
- em.createQuery("Delete from " + tableName).executeUpdate();
+ entmgr.createQuery("Delete from " + tableName).executeUpdate();
// commit transaction
- et.commit();
+ entrans.commit();
}
}
/**
* Verifies that items appear within the log, in order. A given item may appear more than once.
* In addition, the log may contain extra items; those are ignored.
- *
+ *
* @param textre regular expression used to extract an item from a line in the log. The first
* "capture" group of the regular expression is assumed to contain the extracted item
* @param items items that should be matched by the items extracted from the log, in order
@@ -343,7 +343,7 @@ public class IntegrityAuditTestBase {
/**
* Gets the remaining items from an iterator.
- *
+ *
* @param current the current item, to be included within the list
* @param it iterator from which to get the remaining items
* @return a list of the remaining items
@@ -361,7 +361,7 @@ public class IntegrityAuditTestBase {
/**
* Waits for a thread to stop. If the thread doesn't complete in the allotted time, then it
* interrupts it and waits again.
- *
+ *
* @param auditor the thread for which to wait
* @return {@code true} if the thread stopped, {@code false} otherwise
*/
@@ -371,7 +371,7 @@ public class IntegrityAuditTestBase {
auditor.interrupt();
if (!auditor.joinAuditThread(WAIT_MS)) {
- System.out.println("failed to stop audit thread");
+ errorLogger.error("failed to stop audit thread");
return false;
}
@@ -385,7 +385,7 @@ public class IntegrityAuditTestBase {
/**
* Makes a new auditor.
- *
+ *
* @param resourceName2 the name of the resource
* @param persistenceUnit2 the persistence unit
* @return a new auditor
@@ -394,16 +394,16 @@ public class IntegrityAuditTestBase {
protected MyIntegrityAudit makeAuditor(String resourceName2, String persistenceUnit2) throws Exception {
// each auditor gets its own notion of time
TestTime time = new TestTime();
-
+
// use the auditor-specific time while this thread constructs things
testTime.set(time);
-
+
return new MyIntegrityAudit(resourceName2, persistenceUnit2, makeProperties(), time);
}
/**
* Watches for patterns in a logger by attaching a ExtractAppender to it.
- *
+ *
* @param logger the logger to watch
* @param regex regular expression used to extract relevant text
* @return a new appender
@@ -417,7 +417,7 @@ public class IntegrityAuditTestBase {
/**
* Makes a new Property set that's a clone of {@link #properties}.
- *
+ *
* @return a new Property set containing all of a copy of all of the {@link #properties}
*/
protected static Properties makeProperties() {
@@ -428,7 +428,7 @@ public class IntegrityAuditTestBase {
/**
* Waits for data to become stale and then runs an audit on several auditors in parallel.
- *
+ *
* @param auditors the auditors
* @throws InterruptedException if a thread is interrupted
*/
@@ -439,7 +439,7 @@ public class IntegrityAuditTestBase {
/**
* Runs an audit on several auditors in parallel.
- *
+ *
* @param auditors the auditors
* @throws InterruptedException if a thread is interrupted
*/
@@ -459,7 +459,7 @@ public class IntegrityAuditTestBase {
/**
* Waits for a semaphore to be released.
- *
+ *
* @param sem the semaphore for which to wait
* @throws InterruptedException if the thread is interrupted
* @throws AssertionError if the semaphore did not reach zero in the allotted time
@@ -467,10 +467,10 @@ public class IntegrityAuditTestBase {
protected void waitSem(Semaphore sem) throws InterruptedException {
assertTrue(sem.tryAcquire(WAIT_MS, TimeUnit.MILLISECONDS));
}
-
+
/**
* Sleep a bit so that the currently designated pdp becomes stale.
- *
+ *
* @throws InterruptedException if the thread is interrupted
*/
protected void waitStale() throws InterruptedException {
@@ -505,14 +505,14 @@ public class IntegrityAuditTestBase {
* Manages audits by inserting semaphores into a queue for the AuditThread to count.
*/
protected class MyIntegrityAudit extends IntegrityAudit {
-
+
private final TestTime myTime;
-
+
/**
* Semaphore on which the audit thread should wait.
*/
private Semaphore auditSem = null;
-
+
/**
* Semaphore on which the junit management thread should wait.
*/
@@ -520,17 +520,17 @@ public class IntegrityAuditTestBase {
/**
* Constructs an auditor and starts the AuditThread.
- *
+ *
* @param resourceName the resource name
* @param persistenceUnit the persistence unit
* @param properties the properties
* @param time the time
* @throws Exception if an error occurs
*/
- public MyIntegrityAudit(String resourceName, String persistenceUnit,
+ public MyIntegrityAudit(String resourceName, String persistenceUnit,
Properties properties, TestTime time) throws Exception {
super(resourceName, persistenceUnit, properties);
-
+
myTime = time;
testTime.set(myTime);
@@ -538,10 +538,10 @@ public class IntegrityAuditTestBase {
startAuditThread();
}
-
+
/**
* Get time in milliseconds.
- *
+ *
* @return the "current" time for the auditor
*/
public long getTimeInMillis() {
@@ -550,7 +550,7 @@ public class IntegrityAuditTestBase {
/**
* Sleeps for a period of time.
- *
+ *
* @param sleepMs time to sleep
* @throws InterruptedException can be interrupted
*/
@@ -567,7 +567,7 @@ public class IntegrityAuditTestBase {
/**
* Triggers an audit by releasing the audit thread's semaphore.
- *
+ *
* @return the semaphore on which to wait
* @throws InterruptedException if the thread is interrupted
*/
@@ -586,10 +586,10 @@ public class IntegrityAuditTestBase {
// release a bunch of semaphores, in case a thread is still running
auditSem.release(1000);
}
-
+
auditSem = new Semaphore(0);
junitSem = new Semaphore(0);
-
+
super.startAuditThread();
if (haveAuditThread()) {
@@ -609,7 +609,7 @@ public class IntegrityAuditTestBase {
/**
* Stops the AuditThread and waits for it to stop.
- *
+ *
* @throws AssertionError if the thread is still running
*/
@Override
@@ -641,7 +641,7 @@ public class IntegrityAuditTestBase {
@Override
public void runStarted() throws InterruptedException {
auditSem.acquire();
-
+
junitSem.release();
auditSem.acquire();
}
@@ -651,7 +651,7 @@ public class IntegrityAuditTestBase {
junitSem.release();
auditSem.acquire();
}
-
+
};
}
}
diff --git a/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java b/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java
index 36b9ef66..4a4824c5 100644
--- a/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java
+++ b/integrity-audit/src/test/java/org/onap/policy/common/ia/jpa/IaTestEntity.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* Integrity Audit
* ================================================================================
- * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* 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.
@@ -66,7 +66,9 @@ public class IaTestEntity implements Serializable {
@Column(name = "modified_date", nullable = false)
private Date modifiedDate;
- public IaTestEntity() {}
+ public IaTestEntity() {
+ super();
+ }
/**
* PrePersist call back method.
@@ -85,7 +87,7 @@ public class IaTestEntity implements Serializable {
/**
* The the Im test Id.
- *
+ *
* @return the Id
*/
public long getImTestId() {
@@ -94,7 +96,7 @@ public class IaTestEntity implements Serializable {
/**
* Get the createdBy.
- *
+ *
* @return the createdBy
*/
public String getCreatedBy() {
@@ -103,7 +105,7 @@ public class IaTestEntity implements Serializable {
/**
* Set the createdBy.
- *
+ *
* @param createdBy the createdBy to set
*/
public void setCreatedBy(String createdBy) {
@@ -112,7 +114,7 @@ public class IaTestEntity implements Serializable {
/**
* Get the modifiedBy.
- *
+ *
* @return the modifiedBy
*/
public String getModifiedBy() {
@@ -121,7 +123,7 @@ public class IaTestEntity implements Serializable {
/**
* Set the ModifiedBy.
- *
+ *
* @param modifiedBy the modifiedBy to set
*/
public void setModifiedBy(String modifiedBy) {
@@ -130,7 +132,7 @@ public class IaTestEntity implements Serializable {
/**
* Get the ModifiedDate.
- *
+ *
* @return the modifiedDate
*/
public Date getModifiedDate() {
@@ -139,7 +141,7 @@ public class IaTestEntity implements Serializable {
/**
* Set the ModifiedDate.
- *
+ *
* @param modifiedDate the modifiedDate to set
*/
public void setModifiedDate(Date modifiedDate) {
@@ -148,7 +150,7 @@ public class IaTestEntity implements Serializable {
/**
* Get the CreatedDate.
- *
+ *
* @return the createdDate
*/
public Date getCreatedDate() {
@@ -157,7 +159,7 @@ public class IaTestEntity implements Serializable {
/**
* Set the person.
- *
+ *
* @param person the person to set
*/
public void setPersonTest(PersonSample person) {
@@ -166,7 +168,7 @@ public class IaTestEntity implements Serializable {
/**
* Get the person.
- *
+ *
* @return the person
*/
public PersonSample getPersonTest() {