diff options
Diffstat (limited to 'controlloop/common/eventmanager/src/test/java')
2 files changed, 44 insertions, 8 deletions
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<ControlLoopOperation> 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 @@ -188,6 +188,9 @@ public class ControlLoopOperationManager2Test { 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()); @@ -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(); @@ -454,13 +457,16 @@ public class ControlLoopOperationManager2Test { 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()); assertEquals(PolicyResult.SUCCESS, mgr.getOutcomes().peek().getResult()); - verify(mgrctx, times(3)).updated(mgr); + verify(mgrctx, times(4)).updated(mgr); } @Test @@ -600,10 +606,13 @@ public class ControlLoopOperationManager2Test { 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); } @@ -627,6 +636,9 @@ public class ControlLoopOperationManager2Test { 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); @@ -637,6 +649,9 @@ public class ControlLoopOperationManager2Test { 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); @@ -646,13 +661,16 @@ public class ControlLoopOperationManager2Test { 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); 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()); } |