summaryrefslogtreecommitdiffstats
path: root/controlloop/common/feature-controlloop-trans/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-08-05 14:17:01 -0400
committerJim Hahn <jrh3@att.com>2019-08-13 09:24:52 -0400
commit9e8023a455633c7daf0dd291c6268986e39352d7 (patch)
treedc25ae63c4a042a7f16c53d8c50ebcdb4493f5cb /controlloop/common/feature-controlloop-trans/src/test
parent177b67a70f99e0125fec7732f39c18840409f968 (diff)
Fix sonar issues in drools-applications
Addressed sonar issue, "Move constants to a class or enum.", by moving the "manager" object from the ControlLoopMetrics interface into a utility class, ControlLoopMetricsManager. Addressed sonar issue, "duplicated blocks of code must be removed.", by refactoring PolicyGuardYamlToXacml, extracing common functions. Addressed sonar issue, "Remove this unused import", in RestControlLoopManager. Addressed sonar issue, "Refactor this method to throw at most one checked exception", in event manager. Fixed likely new sonar issue with assigning to a parameter. Moved logging line to more appropriate place. Addressed reviewer comment: Use "replace" instead of "replaceAll", thus avoiding escaping Change-Id: I47db957c83c1b3e2bd2330474e261987c6f0aac6 Issue-ID: POLICY-1967 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/feature-controlloop-trans/src/test')
-rw-r--r--controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java82
1 files changed, 44 insertions, 38 deletions
diff --git a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
index abc5db8e6..bbbcc132f 100644
--- a/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
+++ b/controlloop/common/feature-controlloop-trans/src/test/java/org/onap/policy/drools/apps/controlloop/feature/trans/ControlLoopMetricsFeatureTest.java
@@ -66,9 +66,9 @@ public class ControlLoopMetricsFeatureTest {
@Test
public void cacheDefaults() {
- assertEquals(3, ControlLoopMetrics.manager.getCacheSize());
- assertEquals(2, ControlLoopMetrics.manager.getTransactionTimeout());
- assertEquals(0, ControlLoopMetrics.manager.getCacheOccupancy());
+ assertEquals(3, ControlLoopMetricsManager.getManager().getCacheSize());
+ assertEquals(2, ControlLoopMetricsManager.getManager().getTransactionTimeout());
+ assertEquals(0, ControlLoopMetricsManager.getManager().getCacheOccupancy());
}
@Test
@@ -82,7 +82,7 @@ public class ControlLoopMetricsFeatureTest {
notification.setRequestId(requestId);
feature.beforeDeliver(testController, CommInfrastructure.DMAAP, POLICY_CL_MGT, notification);
- assertNull(ControlLoopMetrics.manager.getTransaction(requestId));
+ assertNull(ControlLoopMetricsManager.getManager().getTransaction(requestId));
this.cacheDefaults();
}
@@ -95,14 +95,15 @@ public class ControlLoopMetricsFeatureTest {
notification.setNotification(ControlLoopNotificationType.ACTIVE);
feature.beforeDeliver(testController, CommInfrastructure.DMAAP, POLICY_CL_MGT, notification);
- assertNotNull(ControlLoopMetrics.manager.getTransaction(requestId));
- assertTrue(ControlLoopMetrics.manager.getTransaction(requestId).getFrom().contains(testController.getName()));
- assertNotNull(ControlLoopMetrics.manager.getTransaction(requestId).getNotificationTime());
- assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == 1);
+ assertNotNull(ControlLoopMetricsManager.getManager().getTransaction(requestId));
+ assertTrue(ControlLoopMetricsManager.getManager().getTransaction(requestId).getFrom()
+ .contains(testController.getName()));
+ assertNotNull(ControlLoopMetricsManager.getManager().getTransaction(requestId).getNotificationTime());
+ assertTrue(ControlLoopMetricsManager.getManager().getCacheOccupancy() == 1);
/* wait for the entries to expire */
- await().atMost(ControlLoopMetrics.manager.getTransactionTimeout() + 1, TimeUnit.SECONDS)
- .until(() -> ControlLoopMetrics.manager.getTransaction(requestId) == null);
+ await().atMost(ControlLoopMetricsManager.getManager().getTransactionTimeout() + 1, TimeUnit.SECONDS)
+ .until(() -> ControlLoopMetricsManager.getManager().getTransaction(requestId) == null);
this.cacheDefaults();
}
@@ -113,56 +114,61 @@ public class ControlLoopMetricsFeatureTest {
new ControlLoopMetricsFeature().beforeDeliver(testController, CommInfrastructure.DMAAP, POLICY_CL_MGT,
notification);
- assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId()));
+ assertNotNull(ControlLoopMetricsManager.getManager().getTransaction(notification.getRequestId()));
- ControlLoopMetrics.manager.resetCache(ControlLoopMetrics.manager.getCacheSize(),
- ControlLoopMetrics.manager.getTransactionTimeout());
- assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId()));
+ ControlLoopMetricsManager.getManager().resetCache(ControlLoopMetricsManager.getManager().getCacheSize(),
+ ControlLoopMetricsManager.getManager().getTransactionTimeout());
+ assertNull(ControlLoopMetricsManager.getManager().getTransaction(notification.getRequestId()));
this.cacheDefaults();
}
@Test
public void removeTransaction() {
VirtualControlLoopNotification notification = this.generateNotification();
- assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId()));
- ControlLoopMetrics.manager.removeTransaction(notification.getRequestId());
+ assertNull(ControlLoopMetricsManager.getManager().getTransaction(notification.getRequestId()));
+ ControlLoopMetricsManager.getManager().removeTransaction(notification.getRequestId());
- ControlLoopMetrics.manager.transactionEvent(testController, notification);
- assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId()));
- ControlLoopMetrics.manager.removeTransaction(notification.getRequestId());
- assertNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId()));
+ ControlLoopMetricsManager.getManager().transactionEvent(testController, notification);
+ assertNotNull(ControlLoopMetricsManager.getManager().getTransaction(notification.getRequestId()));
+ ControlLoopMetricsManager.getManager().removeTransaction(notification.getRequestId());
+ assertNull(ControlLoopMetricsManager.getManager().getTransaction(notification.getRequestId()));
}
@Test
public void eviction() throws InterruptedException {
ControlLoopMetricsFeature feature = new ControlLoopMetricsFeature();
- for (int i = 0; i < ControlLoopMetrics.manager.getCacheSize(); i++) {
+ for (int i = 0; i < ControlLoopMetricsManager.getManager().getCacheSize(); i++) {
VirtualControlLoopNotification notification = generateNotification();
feature.beforeDeliver(testController, CommInfrastructure.DMAAP, POLICY_CL_MGT, notification);
- assertNotNull(ControlLoopMetrics.manager.getTransaction(notification.getRequestId()));
+ assertNotNull(ControlLoopMetricsManager.getManager().getTransaction(notification.getRequestId()));
}
- assertEquals(ControlLoopMetrics.manager.getCacheOccupancy(), ControlLoopMetrics.manager.getCacheOccupancy());
+ assertEquals(ControlLoopMetricsManager.getManager().getCacheOccupancy(),
+ ControlLoopMetricsManager.getManager().getCacheOccupancy());
VirtualControlLoopNotification overflowNotification = generateNotification();
feature.beforeDeliver(testController, CommInfrastructure.DMAAP, POLICY_CL_MGT, overflowNotification);
- assertEquals(ControlLoopMetrics.manager.getCacheOccupancy(), ControlLoopMetrics.manager.getCacheOccupancy());
- assertNotNull(ControlLoopMetrics.manager.getTransaction(overflowNotification.getRequestId()));
- assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager.getCacheSize());
- assertTrue(ControlLoopMetrics.manager.getCacheOccupancy() == ControlLoopMetrics.manager.getCacheSize());
- assertFalse(ControlLoopMetrics.manager.getTransactionIds().isEmpty());
- assertFalse(ControlLoopMetrics.manager.getTransactions().isEmpty());
+ assertEquals(ControlLoopMetricsManager.getManager().getCacheOccupancy(),
+ ControlLoopMetricsManager.getManager().getCacheOccupancy());
+ assertNotNull(ControlLoopMetricsManager.getManager().getTransaction(overflowNotification.getRequestId()));
+ assertTrue(ControlLoopMetricsManager.getManager().getTransactionIds().size() == ControlLoopMetricsManager
+ .getManager().getCacheSize());
+ assertTrue(ControlLoopMetricsManager.getManager().getCacheOccupancy() == ControlLoopMetricsManager.getManager()
+ .getCacheSize());
+ assertFalse(ControlLoopMetricsManager.getManager().getTransactionIds().isEmpty());
+ assertFalse(ControlLoopMetricsManager.getManager().getTransactions().isEmpty());
/* wait for the entries to expire */
- await().atMost(ControlLoopMetrics.manager.getTransactionTimeout() + 1, TimeUnit.SECONDS)
- .until(() -> ControlLoopMetrics.manager.getTransactions().isEmpty());
-
- ControlLoopMetrics.manager.refresh();
- assertTrue(ControlLoopMetrics.manager.getTransactionIds().size() == ControlLoopMetrics.manager
- .getCacheOccupancy());
- assertFalse(ControlLoopMetrics.manager.getCacheOccupancy() == ControlLoopMetrics.manager.getCacheSize());
- assertTrue(ControlLoopMetrics.manager.getTransactionIds().isEmpty());
- assertTrue(ControlLoopMetrics.manager.getTransactions().isEmpty());
+ await().atMost(ControlLoopMetricsManager.getManager().getTransactionTimeout() + 1, TimeUnit.SECONDS)
+ .until(() -> ControlLoopMetricsManager.getManager().getTransactions().isEmpty());
+
+ ControlLoopMetricsManager.getManager().refresh();
+ assertTrue(ControlLoopMetricsManager.getManager().getTransactionIds().size() == ControlLoopMetricsManager
+ .getManager().getCacheOccupancy());
+ assertFalse(ControlLoopMetricsManager.getManager().getCacheOccupancy() == ControlLoopMetricsManager.getManager()
+ .getCacheSize());
+ assertTrue(ControlLoopMetricsManager.getManager().getTransactionIds().isEmpty());
+ assertTrue(ControlLoopMetricsManager.getManager().getTransactions().isEmpty());
this.cacheDefaults();
}