From 5d526310e8d2f3c729af4c6a8b1eec0f0a79008d Mon Sep 17 00:00:00 2001 From: jhh Date: Wed, 4 Sep 2019 21:26:56 -0500 Subject: Split Engine start method into "start" and "open" "open" meaning to open external configuration interfaces to external provisioning systems. Issue-ID: POLICY-2055 Signed-off-by: jhh Change-Id: Ic984f0ebccd088503b6b13620c3b80ed8e640899 Signed-off-by: jhh --- .../drools/system/PolicyEngineManagerTest.java | 71 +++++++++++++++++++--- 1 file changed, 63 insertions(+), 8 deletions(-) (limited to 'policy-management/src/test/java/org') diff --git a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java index e9f0b48a..5e0ead9d 100644 --- a/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java +++ b/policy-management/src/test/java/org/onap/policy/drools/system/PolicyEngineManagerTest.java @@ -670,11 +670,11 @@ public class PolicyEngineManagerTest { // servlet wait fails - still does everything testStart(false, () -> when(server1.waitedStart(anyLong())).thenReturn(false)); - // topic source fails to start - still does everything - testStart(false, () -> when(source1.start()).thenReturn(false)); + // topic source is not started with start + testStart(true, () -> when(source1.start()).thenReturn(false)); - // topic sink fails to start - still does everything - testStart(false, () -> when(sink1.start()).thenReturn(false)); + // topic sink is not started with start + testStart(true, () -> when(sink1.start()).thenReturn(false)); // controller fails to start - still does everything testStart(false, () -> when(controller.start()).thenReturn(false)); @@ -735,11 +735,11 @@ public class PolicyEngineManagerTest { verify(server1).waitedStart(anyLong()); verify(server2).waitedStart(anyLong()); - verify(source1).start(); - verify(source2).start(); + verify(source1, never()).start(); + verify(source2, never()).start(); - verify(sink1).start(); - verify(sink2).start(); + verify(sink1, never()).start(); + verify(sink2, never()).start(); verify(controller).start(); verify(controller2).start(); @@ -1483,6 +1483,61 @@ public class PolicyEngineManagerTest { verify(prov2).afterDeactivate(mgr); } + @Test + public void testOpen() throws Throwable { + when(prov1.beforeOpen(mgr)).thenThrow(new RuntimeException(EXPECTED)); + when(prov1.afterOpen(mgr)).thenThrow(new RuntimeException(EXPECTED)); + + assertTrue(mgr.lock()); + assertThatIllegalStateException().isThrownBy(() -> mgr.open()); + unsuccessfulOpen(); + + assertTrue(mgr.unlock()); + unsuccessfulOpen(); + + setUp(); + mgr.configure(properties); + assertTrue(mgr.start()); + + verify(source1, never()).start(); + verify(source2, never()).start(); + + assertTrue(mgr.open()); + + verify(prov1).beforeOpen(mgr); + verify(prov2).beforeOpen(mgr); + + verify(source1).start(); + verify(source2).start(); + + verify(prov1).afterOpen(mgr); + verify(prov2).afterOpen(mgr); + + when(source1.start()).thenReturn(false); + assertFalse(mgr.open()); + when(source1.start()).thenReturn(true); + + when(sink1.start()).thenReturn(false); + assertFalse(mgr.open()); + when(sink1.start()).thenReturn(true); + + assertTrue(mgr.open()); + } + + private void unsuccessfulOpen() { + verify(prov1).beforeOpen(mgr); + verify(prov2).beforeOpen(mgr); + + verify(prov1, never()).afterOpen(mgr); + verify(prov2, never()).afterOpen(mgr); + + verify(source1, never()).start(); + verify(source2, never()).start(); + + verify(sink1, never()).start(); + verify(sink2, never()).start(); + } + @Test public void testControllerConfig() throws Exception { mgr.configure(properties); -- cgit 1.2.3-korg