From f9e2f54dbb36f029a41e37f6eccc3426672cb9bb Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 6 Mar 2020 13:07:08 -0500 Subject: Bug fixes to new rules Also added VdnsTest, VfwTest, and VcpeTest. Fixed a number of issues with notifications: - event data (e.g., AAI) was missing - notification was missing for the start of an operation - "message" and "history" fields should contain Target object, target entity - "message" field was missing various details (e.g., start time) Still missing subRequestId - that will require enhancements to the actors. Issue-ID: POLICY-2385 Signed-off-by: Jim Hahn Change-Id: I7fc33ebcd5939d2f33a9d209ac6119e390e0836d --- .../eventmanager/ControlLoopEventManager2Test.java | 16 ++++++++-- .../ControlLoopOperationManager2Test.java | 36 +++++++++++++++++++--- 2 files changed, 44 insertions(+), 8 deletions(-) (limited to 'controlloop/common/eventmanager/src/test') diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java index 522d9f57b..d09c2c88b 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java @@ -137,14 +137,17 @@ public class ControlLoopEventManager2Test { when(oper1.getActor()).thenReturn("First"); when(oper1.getOperation()).thenReturn("OperationA"); when(oper1.getOperationMessage()).thenReturn("message-A"); + when(oper1.getOperationHistory()).thenReturn("history-A"); when(oper2.getActor()).thenReturn("Second"); when(oper2.getOperation()).thenReturn("OperationB"); when(oper2.getOperationMessage()).thenReturn("message-B"); + when(oper2.getOperationHistory()).thenReturn("history-B"); when(oper3.getActor()).thenReturn("Third"); when(oper3.getOperation()).thenReturn("OperationC"); when(oper3.getOperationMessage()).thenReturn("message-C"); + when(oper3.getOperationHistory()).thenReturn("history-C"); when(workMem.getFactHandle(any())).thenReturn(factHandle); @@ -365,13 +368,17 @@ public class ControlLoopEventManager2Test { mgr.updated(oper1); verifyNotification(ControlLoopNotificationType.OPERATION, "Guard result for First OperationA is Deny"); + when(oper1.getState()).thenReturn(State.OPERATION_STARTED); + mgr.updated(oper1); + verifyNotification(ControlLoopNotificationType.OPERATION, "message-A"); + when(oper1.getState()).thenReturn(State.OPERATION_SUCCESS); mgr.updated(oper1); - verifyNotification(ControlLoopNotificationType.OPERATION_SUCCESS, "message-A"); + verifyNotification(ControlLoopNotificationType.OPERATION_SUCCESS, "history-A"); when(oper1.getState()).thenReturn(State.OPERATION_FAILURE); mgr.updated(oper1); - verifyNotification(ControlLoopNotificationType.OPERATION_FAILURE, "message-A"); + verifyNotification(ControlLoopNotificationType.OPERATION_FAILURE, "history-A"); // should still be active assertTrue(mgr.isActive()); @@ -427,6 +434,9 @@ public class ControlLoopEventManager2Test { @Test public void testMakeNotification() throws ControlLoopException { + // before started + assertNotNull(mgr.makeNotification()); + mgr.start(); nextStep(oper1, true, PolicyResult.SUCCESS); @@ -434,7 +444,7 @@ public class ControlLoopEventManager2Test { // check notification while running VirtualControlLoopNotification notif = mgr.getNotification(); - assertEquals("message-A", notif.getMessage()); + assertEquals("history-A", notif.getMessage()); List history = notif.getHistory(); assertNotNull(history); diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java index a14cc1708..e946d2edc 100644 --- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java +++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java @@ -187,6 +187,9 @@ public class ControlLoopOperationManager2Test { assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState()); + assertTrue(mgr.nextStep()); + assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState()); + assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState()); @@ -196,7 +199,7 @@ public class ControlLoopOperationManager2Test { assertEquals(PolicyResult.SUCCESS, outcome.getResult()); assertTrue(outcome.isFinalOutcome()); - verify(mgrctx, times(3)).updated(mgr); + verify(mgrctx, times(4)).updated(mgr); } /** @@ -204,7 +207,7 @@ public class ControlLoopOperationManager2Test { */ @Test public void testStartDetmTargetException() { - policy.setTarget(null); + policy.setTarget(new Target()); mgr.start(REMAINING_MS); runToCompletion(); @@ -453,6 +456,9 @@ public class ControlLoopOperationManager2Test { assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState()); + assertTrue(mgr.nextStep()); + assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState()); + assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState()); @@ -460,7 +466,7 @@ public class ControlLoopOperationManager2Test { assertEquals(PolicyResult.SUCCESS, mgr.getOutcomes().peek().getResult()); - verify(mgrctx, times(3)).updated(mgr); + verify(mgrctx, times(4)).updated(mgr); } @Test @@ -599,11 +605,14 @@ public class ControlLoopOperationManager2Test { assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState()); + assertTrue(mgr.nextStep()); + assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState()); + assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState()); assertFalse(mgr.nextStep()); - verify(mgrctx, times(3)).updated(mgr); + verify(mgrctx, times(4)).updated(mgr); verifyDb(1, PolicyResult.SUCCESS, null); } @@ -626,6 +635,9 @@ public class ControlLoopOperationManager2Test { assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.GUARD_PERMITTED, mgr.getState()); + assertTrue(mgr.nextStep()); + assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState()); + assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState()); verifyDb(1, PolicyResult.FAILURE, null); @@ -636,6 +648,9 @@ public class ControlLoopOperationManager2Test { genOpOutcome(false); runToCompletion(); + assertTrue(mgr.nextStep()); + assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState()); + assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState()); verifyDb(2, PolicyResult.FAILURE, null); @@ -645,6 +660,9 @@ public class ControlLoopOperationManager2Test { // and finally a success genOpOutcome(); + assertTrue(mgr.nextStep()); + assertEquals(ControlLoopOperationManager2.State.OPERATION_STARTED, mgr.getState()); + assertTrue(mgr.nextStep()); assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState()); verifyDb(3, PolicyResult.SUCCESS, null); @@ -652,7 +670,7 @@ public class ControlLoopOperationManager2Test { assertThat(mgr.toString()).contains("attempts=3"); assertFalse(mgr.nextStep()); - verify(mgrctx, times(5)).updated(mgr); + verify(mgrctx, times(8)).updated(mgr); } @Test @@ -802,8 +820,16 @@ public class ControlLoopOperationManager2Test { runToCompletion(); + // guard start assertTrue(mgr.nextStep()); + + // guard permit assertTrue(mgr.nextStep()); + + // operation start + assertTrue(mgr.nextStep()); + + // operation success assertFalse(mgr.nextStep()); } -- cgit 1.2.3-korg