From 7a5e85e17d58e4d75812a3015adc7cbc06e4e49c Mon Sep 17 00:00:00 2001 From: liamfallon Date: Sat, 6 Oct 2018 13:33:26 +0100 Subject: Unit test for Apex engine Coverage for unit test of engie state and state machine handling. Added coverage of the facade and executor context classes Added coverage for executors Added coverage for the remainder of the core engine Issue-ID: POLICY-1034 Change-Id: I85c66005dfdffdf2b4ee5672473a3ae4823d0d9c Signed-off-by: liamfallon --- .../engine/runtime/impl/EngineServiceImplTest.java | 8 ++++- .../engine/runtime/impl/EngineWorkerTest.java | 34 +++++++++++++++++----- 2 files changed, 33 insertions(+), 9 deletions(-) (limited to 'services/services-engine/src') diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java index 582e61948..f68a4872b 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineServiceImplTest.java @@ -171,7 +171,13 @@ public class EngineServiceImplTest { esImpl.registerActionListener(null, new DummyApexEventListener()); esImpl.registerActionListener("DummyListener", new DummyApexEventListener()); - esImpl.deregisterActionListener(null); + try { + esImpl.deregisterActionListener(null); + fail("test should throw an exception"); + } catch (Exception apEx) { + assertEquals("removeEventListener()<-Engine-0:0.0.1,STOPPED, listenerName is null", apEx.getMessage()); + } + esImpl.deregisterActionListener("DummyListener"); assertEquals(esImpl, esImpl.getEngineServiceEventInterface()); diff --git a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java index 5ffda6ed6..1f8052d4a 100644 --- a/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java +++ b/services/services-engine/src/test/java/org/onap/policy/apex/service/engine/runtime/impl/EngineWorkerTest.java @@ -143,7 +143,7 @@ public class EngineWorkerTest { ParameterService.deregister(ContextParameterConstants.MAIN_GROUP_NAME); ParameterService.deregister(EngineParameterConstants.MAIN_GROUP_NAME); } - + @After public void cleardownTest() { ModelService.clear(); @@ -155,12 +155,31 @@ public class EngineWorkerTest { EngineWorker worker = new EngineWorker(new AxArtifactKey("Worker", "0.0.1"), eventQueue, atFactory); - worker.registerActionListener(null, null); + try { + worker.registerActionListener(null, null); + fail("test should throw an exception"); + } catch (Exception apEx) { + assertEquals("addEventListener()<-Worker:0.0.1,STOPPED, listenerName is null", apEx.getMessage()); + } + worker.registerActionListener("DummyListener", null); - worker.registerActionListener(null, new DummyApexEventListener()); + + try { + worker.registerActionListener(null, new DummyApexEventListener()); + fail("test should throw an exception"); + } catch (Exception apEx) { + assertEquals("addEventListener()<-Worker:0.0.1,STOPPED, listenerName is null", apEx.getMessage()); + } worker.registerActionListener("DummyListener", new DummyApexEventListener()); - worker.deregisterActionListener(null); + + try { + worker.deregisterActionListener(null); + fail("test should throw an exception"); + } catch (Exception apEx) { + assertEquals("removeEventListener()<-Worker:0.0.1,STOPPED, listenerName is null", apEx.getMessage()); + } + worker.deregisterActionListener("DummyListener"); try { @@ -308,7 +327,6 @@ public class EngineWorkerTest { apEx.getMessage()); } } - @Test public void testApexImplModelWIthModel() throws ApexException { @@ -322,7 +340,7 @@ public class EngineWorkerTest { } catch (ApexException apEx) { fail("test should not throw an exception"); } - + eventQueue.add(new ApexEvent("SomeEvent", "0.0.1", "the.event.namespace", "EventSource", "EventTarget")); try { @@ -352,7 +370,7 @@ public class EngineWorkerTest { assertEquals(AxEngineState.STOPPED, worker.getState()); worker.startAll(); - + assertEquals(AxEngineState.READY, worker.getState()); String status = worker.getStatus(worker.getEngineKeys().iterator().next()); @@ -425,7 +443,7 @@ public class EngineWorkerTest { } catch (ApexException apEx) { fail("test should not throw an exception"); } - + assertNotNull(worker.getApexModelKey()); } } -- cgit 1.2.3-korg