Upgrade Java 17 in policy-drools-apps
[policy/drools-applications.git] / controlloop / common / controller-usecases / src / test / java / org / onap / policy / drools / apps / controller / usecases / UsecasesEventManagerTest.java
index cce7209..3b64638 100644 (file)
@@ -2,7 +2,8 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021, 2023 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,51 +23,38 @@ package org.onap.policy.drools.apps.controller.usecases;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.ArgumentMatchers.anyLong;
-import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 
 import java.time.Instant;
 import java.util.ArrayList;
 import java.util.Arrays;
-import java.util.Collections;
-import java.util.Deque;
 import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.ExecutorService;
-import java.util.concurrent.ForkJoinPool;
 import org.drools.core.WorkingMemory;
-import org.junit.Before;
-import org.junit.Test;
-import org.kie.api.runtime.rule.FactHandle;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
+import org.drools.core.common.InternalFactHandle;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardYamlCoder;
-import org.onap.policy.common.utils.io.Serializer;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.controlloop.ControlLoopEventStatus;
 import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopResponse;
 import org.onap.policy.controlloop.ControlLoopTargetType;
 import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.controlloop.actorserviceprovider.ActorService;
 import org.onap.policy.controlloop.actorserviceprovider.Operation;
-import org.onap.policy.controlloop.actorserviceprovider.OperationFinalResult;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
@@ -76,8 +64,8 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
 import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
 import org.onap.policy.controlloop.eventmanager.ActorConstants;
+import org.onap.policy.controlloop.eventmanager.EventManagerServices;
 import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
-import org.onap.policy.drools.apps.controller.usecases.UsecasesEventManager.NewEventStatus;
 import org.onap.policy.drools.apps.controller.usecases.step.AaiCqStep2;
 import org.onap.policy.drools.apps.controller.usecases.step.AaiGetPnfStep2;
 import org.onap.policy.drools.apps.controller.usecases.step.AaiGetTenantStep2;
@@ -94,7 +82,7 @@ import org.onap.policy.sdnr.PciBody;
 import org.onap.policy.sdnr.PciMessage;
 import org.onap.policy.sdnr.PciResponse;
 
-public class UsecasesEventManagerTest {
+class UsecasesEventManagerTest {
     private static final UUID REQ_ID = UUID.randomUUID();
     private static final String CL_NAME = "my-closed-loop-name";
     private static final String POLICY_NAME = "my-policy-name";
@@ -103,36 +91,22 @@ public class UsecasesEventManagerTest {
     private static final String SIMPLE_ACTOR = "First";
     private static final String SIMPLE_OPERATION = "OperationA";
     private static final String MY_TARGET = "my-target";
-    private static final String EVENT_MGR_MULTI_YAML =
-                    "../eventmanager/src/test/resources/eventManager/event-mgr-multi.yaml";
     private static final String EVENT_MGR_SIMPLE_YAML =
                     "../eventmanager/src/test/resources/eventManager/event-mgr-simple.yaml";
     private static final Coder yamlCoder = new StandardYamlCoder();
     private static final String OUTCOME_MSG = "my outcome message";
-    private static final String MY_SINK = "my-topic-sink";
-
-    @Mock
-    private PolicyEngine engineMgr;
-    @Mock
-    private WorkingMemory workMem;
-    @Mock
-    private FactHandle factHandle;
-    @Mock
-    private Operator policyOperator;
-    @Mock
-    private Operation policyOperation;
-    @Mock
-    private Actor policyActor;
-    @Mock
-    private ActorService actors;
-    @Mock
-    private OperationHistoryDataManager dataMgr;
-    @Mock
-    private ExecutorService executor;
-    @Mock
-    private Step2 stepa;
-    @Mock
-    private Step2 stepb;
+
+    private final PolicyEngine engineMgr = mock(PolicyEngine.class);
+    private final WorkingMemory workMem = mock(WorkingMemory.class);
+    private final InternalFactHandle factHandle = mock(InternalFactHandle.class);
+    private final Operator policyOperator = mock(Operator.class);
+    private final Operation policyOperation = mock(Operation.class);
+    private final Actor policyActor = mock(Actor.class);
+    private final EventManagerServices services = mock(EventManagerServices.class);
+    private final OperationHistoryDataManager dataMgr = mock(OperationHistoryDataManager.class);
+    private final ExecutorService executor = mock(ExecutorService.class);
+    private Step2 stepa = mock(Step2.class);
+    private final Step2 stepb = mock(Step2.class);
 
     private List<LockImpl> locks;
     private ToscaPolicy tosca;
@@ -143,14 +117,9 @@ public class UsecasesEventManagerTest {
     /**
      * Sets up.
      */
-    @Before
+    @BeforeEach
     public void setUp() throws ControlLoopException, CoderException {
-        MockitoAnnotations.initMocks(this);
-
-        when(actors.getActor(SIMPLE_ACTOR)).thenReturn(policyActor);
-        when(policyActor.getOperator(SIMPLE_OPERATION)).thenReturn(policyOperator);
-        when(policyOperator.buildOperation(any())).thenReturn(policyOperation);
-        when(policyOperation.getPropertyNames()).thenReturn(Collections.emptyList());
+        when(services.getDataManager()).thenReturn(dataMgr);
 
         when(workMem.getFactHandle(any())).thenReturn(factHandle);
 
@@ -172,48 +141,48 @@ public class UsecasesEventManagerTest {
 
         locks = new ArrayList<>();
 
-        mgr = new MyManager(params, event, workMem);
+        mgr = new MyManager(services, params, event, workMem);
     }
 
     @Test
-    public void testConstructor() {
+    void testConstructor() {
         assertEquals(POLICY_NAME, mgr.getPolicyName());
         assertSame(event, mgr.getEvent());
 
-        Map<String, String> orig = event.getAai();
+        var orig = event.getAai();
 
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "true"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .hasMessage("is-closed-loop-disabled is set to true on VServer or VNF");
 
         // vserver ACTIVE
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS,
                         UsecasesConstants.PROV_STATUS_ACTIVE.toUpperCase()));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
 
         // vserver active
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS,
                         UsecasesConstants.PROV_STATUS_ACTIVE.toLowerCase()));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
 
         // vserver inactive
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "inactive"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .hasMessage("prov-status is not ACTIVE on VServer or VNF");
 
         // vnf ACTIVE
         event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS,
                         UsecasesConstants.PROV_STATUS_ACTIVE.toUpperCase()));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
 
         // vnf active
         event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS,
                         UsecasesConstants.PROV_STATUS_ACTIVE.toLowerCase()));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
 
         // vnf inactive
         event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "inactive"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .hasMessage("prov-status is not ACTIVE on VServer or VNF");
 
         // valid
@@ -222,169 +191,12 @@ public class UsecasesEventManagerTest {
 
         // invalid
         event.setTarget("unknown-target");
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .isInstanceOf(ControlLoopException.class);
     }
 
     @Test
-    public void testIsActive() throws Exception {
-        mgr = new UsecasesEventManager(params, event, workMem);
-        assertTrue(mgr.isActive());
-
-        // deserialized manager should be inactive
-        UsecasesEventManager mgr2 = Serializer.roundTrip(mgr);
-        assertFalse(mgr2.isActive());
-    }
-
-    @Test
-    public void testDestroy_testGetSteps() {
-        // add some steps to the queue
-        mgr.getSteps().add(stepa);
-        mgr.getSteps().add(stepb);
-
-        mgr.destroy();
-
-        verify(stepa).cancel();
-        verify(stepb).cancel();
-
-        // if superclass destroy() was invoked, then freeLock() should have been submitted
-        // to the executor
-        verify(executor).execute(any());
-    }
-
-    @Test
-    public void testOnStart() throws ControlLoopException {
-        OperationOutcome outcome = makeOutcome();
-
-        mgr.start();
-        mgr.onStart(outcome);
-
-        assertSame(outcome, mgr.getOutcomes().poll());
-        assertThat(mgr.getOutcomes()).isEmpty();
-
-        verify(workMem).update(factHandle, mgr);
-    }
-
-    @Test
-    public void testOnComplete() throws ControlLoopException {
-        OperationOutcome outcome = makeCompletedOutcome();
-
-        mgr.start();
-        mgr.onComplete(outcome);
-
-        assertSame(outcome, mgr.getOutcomes().poll());
-        assertThat(mgr.getOutcomes()).isEmpty();
-
-        verify(workMem).update(factHandle, mgr);
-    }
-
-    @Test
-    public void testToString() {
-        assertNotNull(mgr.toString());
-    }
-
-    @Test
-    public void testStart() throws ControlLoopException {
-        // start it
-        mgr.start();
-
-        // cannot re-start
-        assertThatCode(() -> mgr.start()).isInstanceOf(IllegalStateException.class)
-                        .hasMessage("manager already started");
-    }
-
-    /**
-     * Tests start() when the manager is not in working memory.
-     */
-    @Test
-    public void testStartNotInWorkingMemory() throws ControlLoopException {
-        when(workMem.getFactHandle(any())).thenReturn(null);
-
-        assertThatCode(() -> mgr.start()).isInstanceOf(IllegalStateException.class)
-                        .hasMessage("manager is not in working memory");
-    }
-
-    /**
-     * Tests start() when the manager is not active.
-     */
-    @Test
-    public void testStartInactive() throws Exception {
-        // make an inactive manager by deserializing it
-        mgr = Serializer.roundTrip(new UsecasesEventManager(params, event, workMem));
-
-        // cannot re-start
-        assertThatCode(() -> mgr.start()).isInstanceOf(IllegalStateException.class)
-                        .hasMessage("manager is no longer active");
-    }
-
-    @Test
-    public void testAbort() {
-        mgr.abort(UsecasesEventManager.State.DONE, OperationFinalResult.FINAL_FAILURE_GUARD, "some message");
-
-        assertEquals(UsecasesEventManager.State.DONE, mgr.getState());
-        assertEquals(OperationFinalResult.FINAL_FAILURE_GUARD, mgr.getFinalResult());
-        assertEquals("some message", mgr.getFinalMessage());
-
-        // try null state
-        assertThatThrownBy(() -> mgr.abort(null, OperationFinalResult.FINAL_FAILURE_GUARD, ""))
-                        .isInstanceOf(NullPointerException.class).hasMessageContaining("finalState");
-    }
-
-    @Test
-    public void testLoadNextPolicy_testGetFullHistory_testGetPartialHistory() throws Exception {
-        loadPolicy(EVENT_MGR_MULTI_YAML);
-        mgr = new MyManager(params, event, workMem);
-
-        // start and load step for first policy
-        mgr.start();
-        assertEquals("OperationA", mgr.getSteps().poll().getOperationName());
-        assertNull(mgr.getFinalResult());
-
-        // add an outcome
-        OperationOutcome outcome = makeOutcome();
-        mgr.addToHistory(outcome);
-
-        // indicate success and load next policy
-        mgr.loadNextPolicy(OperationResult.SUCCESS);
-        assertEquals("OperationB", mgr.getSteps().poll().getOperationName());
-        assertNull(mgr.getFinalResult());
-
-        // loadPolicy() should clear the partial history, but not the full history
-        assertThat(mgr.getPartialHistory()).isEmpty();
-        assertThat(mgr.getFullHistory()).hasSize(1);
-
-        // indicate failure - should go to final failure
-        mgr.loadNextPolicy(OperationResult.FAILURE);
-        assertEquals(OperationFinalResult.FINAL_FAILURE, mgr.getFinalResult());
-    }
-
-    @Test
-    public void testLoadPolicy() throws ControlLoopException {
-        // start() will invoke loadPolicy()
-        mgr.start();
-
-        assertNull(mgr.getFinalResult());
-
-        Step2 step = mgr.getSteps().peek();
-        assertNotNull(step);
-        assertEquals("First", step.getActorName());
-        assertEquals("OperationA", step.getOperationName());
-
-        ControlLoopOperationParams params2 = step.getParams();
-        assertSame(actors, params2.getActorService());
-        assertSame(REQ_ID, params2.getRequestId());
-        assertSame(ForkJoinPool.commonPool(), params2.getExecutor());
-        assertNotNull(params2.getTargetType());
-        assertNotNull(params2.getTargetEntityIds());
-        assertEquals(Integer.valueOf(300), params2.getTimeoutSec());
-        assertEquals(Integer.valueOf(0), params2.getRetry());
-        assertThat(params2.getPayload()).isEmpty();
-        assertNotNull(params2.getStartCallback());
-        assertNotNull(params2.getCompleteCallback());
-    }
-
-    @Test
-    public void testLoadPreprocessorSteps() {
+    void testLoadPreprocessorSteps() {
         stepa = new Step2(mgr, ControlLoopOperationParams.builder().build(), event) {
             @Override
             public List<String> getPropertyNames() {
@@ -402,7 +214,7 @@ public class UsecasesEventManagerTest {
 
         mgr.loadPreprocessorSteps();
 
-        Deque<Step2> steps = mgr.getSteps();
+        var steps = mgr.getSteps();
 
         Step2 lockStep = steps.poll();
         assertNotNull(lockStep);
@@ -414,48 +226,15 @@ public class UsecasesEventManagerTest {
         assertThat(steps).isEmpty();
     }
 
-    /**
-     * Tests loadPreprocessorSteps() when there are too many steps in the queue.
-     */
-    @Test
-    public void testLoadPreprocessorStepsTooManySteps() {
-        loadStepsWithProperties(OperationProperties.AAI_PNF);
-
-        Deque<Step2> steps = mgr.getSteps();
-        stepa = steps.getFirst();
-        steps.clear();
-
-        // load up a bunch of steps
-        for (int nsteps = 0; nsteps < UsecasesEventManager.MAX_STEPS; ++nsteps) {
-            steps.add(stepa);
-        }
-
-        // should fail
-        assertThatIllegalStateException().isThrownBy(() -> mgr.loadPreprocessorSteps()).withMessage("too many steps");
-
-        // add another step, should still fail
-        steps.add(stepa);
-        assertThatIllegalStateException().isThrownBy(() -> mgr.loadPreprocessorSteps()).withMessage("too many steps");
-
-        // remove two steps - should now succeed
-        steps.remove();
-        steps.remove();
-
-        int nsteps = steps.size();
-
-        mgr.loadPreprocessorSteps();
-        assertEquals(nsteps + 1, steps.size());
-    }
-
     /**
      * Tests loadPreprocessorSteps() when no additional steps are needed.
      */
     @Test
-    public void testLoadPreprocessorStepsNothingToLoad() {
+    void testLoadPreprocessorStepsNothingToLoad() {
         when(stepa.isPolicyStep()).thenReturn(false);
         when(stepa.getPropertyNames()).thenReturn(List.of("unknown-property"));
 
-        Deque<Step2> steps = mgr.getSteps();
+        var steps = mgr.getSteps();
         steps.add(stepa);
         steps.add(stepb);
 
@@ -471,13 +250,13 @@ public class UsecasesEventManagerTest {
      * Tests loadPreprocessorSteps() when an A&AI custom query is needed.
      */
     @Test
-    public void testLoadPreprocessorStepsCq() {
+    void testLoadPreprocessorStepsCq() {
         loadStepsWithProperties(OperationProperties.AAI_DEFAULT_CLOUD_REGION, OperationProperties.AAI_DEFAULT_TENANT);
 
         setTargetEntity();
         mgr.loadPreprocessorSteps();
 
-        Deque<Step2> steps = mgr.getSteps();
+        var steps = mgr.getSteps();
 
         assertThat(steps.poll()).isInstanceOf(AaiCqStep2.class);
         assertSame(stepa, steps.poll());
@@ -489,14 +268,14 @@ public class UsecasesEventManagerTest {
      * Tests loadPreprocessorSteps() when an A&AI PNF query is needed.
      */
     @Test
-    public void testLoadPreprocessorStepsPnf() {
+    void testLoadPreprocessorStepsPnf() {
         // doubling up the property to check both branches
         loadStepsWithProperties(OperationProperties.AAI_PNF, OperationProperties.AAI_PNF);
 
         setTargetEntity();
         mgr.loadPreprocessorSteps();
 
-        Deque<Step2> steps = mgr.getSteps();
+        var steps = mgr.getSteps();
 
         assertThat(steps.poll()).isInstanceOf(AaiGetPnfStep2.class);
         assertSame(stepa, steps.poll());
@@ -508,7 +287,7 @@ public class UsecasesEventManagerTest {
      * Tests loadPreprocessorSteps() when an A&AI Tenant query is needed.
      */
     @Test
-    public void testLoadPreprocessorStepsTenant() {
+    void testLoadPreprocessorStepsTenant() {
         // doubling up the property to check both branches
         event.getAai().put(Step2.VSERVER_VSERVER_NAME, "my-vserver");
         loadStepsWithProperties(OperationProperties.AAI_VSERVER_LINK, OperationProperties.AAI_VSERVER_LINK);
@@ -516,7 +295,7 @@ public class UsecasesEventManagerTest {
         setTargetEntity();
         mgr.loadPreprocessorSteps();
 
-        Deque<Step2> steps = mgr.getSteps();
+        var steps = mgr.getSteps();
 
         assertThat(steps.poll()).isInstanceOf(AaiGetTenantStep2.class);
         assertSame(stepa, steps.poll());
@@ -528,11 +307,10 @@ public class UsecasesEventManagerTest {
      * Tests loadPreprocessorSteps() when the target entity is unset.
      */
     @Test
-    public void testLoadPreprocessorStepsNeedTargetEntity() {
-        stepa = new Step2(mgr,
-                ControlLoopOperationParams.builder()
-                        .targetType(TargetType.toTargetType(event.getTargetType()))
-                        .targetEntityIds(Map.of()).build(), event) {
+    void testLoadPreprocessorStepsNeedTargetEntity() {
+        stepa = new Step2(mgr, ControlLoopOperationParams.builder()
+                        .targetType(TargetType.toTargetType(event.getTargetType())).targetEntityIds(Map.of()).build(),
+                        event) {
             @Override
             public List<String> getPropertyNames() {
                 return List.of(OperationProperties.AAI_TARGET_ENTITY);
@@ -549,7 +327,7 @@ public class UsecasesEventManagerTest {
             }
         };
 
-        Deque<Step2> steps = mgr.getSteps();
+        var steps = mgr.getSteps();
         steps.add(stepa);
         steps.add(stepb);
 
@@ -570,46 +348,8 @@ public class UsecasesEventManagerTest {
     }
 
     @Test
-    public void testExecuteStep() {
-        mgr.bumpAttempts();
-
-        // no steps to execute
-        assertFalse(mgr.executeStep());
-        assertEquals(0, mgr.getAttempts());
-
-        // add a step to the queue
-        mgr.getSteps().add(stepa);
-
-        // step returns false
-        when(stepa.start(anyLong())).thenReturn(false);
-        assertFalse(mgr.executeStep());
-
-        // step returns true
-        when(stepa.start(anyLong())).thenReturn(true);
-        assertTrue(mgr.executeStep());
-    }
-
-    @Test
-    public void testNextStep() {
-        mgr.getSteps().add(stepa);
-
-        mgr.nextStep();
-
-        assertThat(mgr.getSteps()).isEmpty();
-    }
-
-    @Test
-    public void testBumpAttempts() {
-        assertEquals(0, mgr.getAttempts());
-
-        mgr.bumpAttempts();
-        mgr.bumpAttempts();
-        assertEquals(2, mgr.getAttempts());
-    }
-
-    @Test
-    public void testIsAbort() {
-        OperationOutcome outcome = makeCompletedOutcome();
+    void testIsAbort() {
+        var outcome = makeCompletedOutcome();
         outcome.setResult(OperationResult.FAILURE);
 
         // closed loop timeout
@@ -626,150 +366,20 @@ public class UsecasesEventManagerTest {
     }
 
     @Test
-    public void testAddToHistory() throws ControlLoopException {
-        mgr.start();
-
-        // add a "start" outcome
-        OperationOutcome outcome = makeOutcome();
-        mgr.addToHistory(outcome);
-
-        assertThat(mgr.getPartialHistory()).hasSize(1);
-        assertThat(mgr.getFullHistory()).hasSize(1);
-
-        // add a "completion" outcome - should replace the start
-        outcome = makeCompletedOutcome();
-        mgr.addToHistory(outcome);
-
-        assertThat(mgr.getPartialHistory()).hasSize(1);
-        assertThat(mgr.getFullHistory()).hasSize(1);
-        assertSame(outcome, mgr.getPartialHistory().peek().getOutcome());
-        assertSame(outcome, mgr.getFullHistory().peek().getOutcome());
-
-        // add another start
-        outcome = makeOutcome();
-        mgr.addToHistory(outcome);
-
-        assertThat(mgr.getPartialHistory()).hasSize(2);
-        assertThat(mgr.getFullHistory()).hasSize(2);
-        assertSame(outcome, mgr.getPartialHistory().peekLast().getOutcome());
-        assertSame(outcome, mgr.getFullHistory().peekLast().getOutcome());
-
-        // remove the last item from the full history and then add a "completion"
-        mgr.getFullHistory().removeLast();
-        outcome = makeCompletedOutcome();
-        mgr.addToHistory(outcome);
-        assertThat(mgr.getPartialHistory()).hasSize(2);
-        assertThat(mgr.getFullHistory()).hasSize(2);
-
-        // add another "start"
-        outcome = makeOutcome();
-        mgr.addToHistory(outcome);
-        assertThat(mgr.getPartialHistory()).hasSize(3);
-        assertThat(mgr.getFullHistory()).hasSize(3);
-
-        // add a "completion" for a different actor - should NOT replace the start
-        outcome = makeCompletedOutcome();
-        outcome.setActor("different-actor");
-        mgr.addToHistory(outcome);
-        assertThat(mgr.getPartialHistory()).hasSize(4);
-        assertThat(mgr.getFullHistory()).hasSize(4);
-        assertSame(outcome, mgr.getPartialHistory().peekLast().getOutcome());
-        assertSame(outcome, mgr.getFullHistory().peekLast().getOutcome());
-    }
-
-    @Test
-    public void testMakeNotification() throws Exception {
-        loadPolicy(EVENT_MGR_MULTI_YAML);
-        mgr = new MyManager(params, event, workMem);
-
-        // before started
-        assertNotNull(mgr.makeNotification());
-
-        mgr.start();
-
-        mgr.addToHistory(makeCompletedOutcome());
-        mgr.addToHistory(makeCompletedOutcome());
-        mgr.addToHistory(makeCompletedOutcome());
-
-        // check notification while running
-        VirtualControlLoopNotification notif = mgr.makeNotification();
-        assertThat(notif.getMessage()).contains(SIMPLE_ACTOR);
-        assertThat(notif.getHistory()).hasSize(3);
-
-        // indicate success and load the next policy - should clear the partial history
-        mgr.loadNextPolicy(OperationResult.SUCCESS);
-
-        // check notification
-        notif = mgr.makeNotification();
-        assertNull(notif.getMessage());
-        assertThat(notif.getHistory()).isEmpty();
-
-        // add outcomes and check again
-        mgr.addToHistory(makeCompletedOutcome());
-        mgr.addToHistory(makeCompletedOutcome());
-
-        notif = mgr.makeNotification();
-        assertNotNull(notif.getMessage());
-
-        // should only have history for last two outcomes
-        assertThat(notif.getHistory()).hasSize(2);
-
-        // indicate failure - should go to final state
-        mgr.loadNextPolicy(OperationResult.FAILURE);
-
-        // check notification
-        notif = mgr.makeNotification();
-        assertNull(notif.getMessage());
-
-        // should be no history
-        assertThat(notif.getHistory()).isEmpty();
-
-        // null case
-        assertThatThrownBy(() -> mgr.loadNextPolicy(null)).isInstanceOf(NullPointerException.class)
-                        .hasMessageContaining("lastResult");
-    }
-
-    @Test
-    public void testDeliver() {
-        mgr.deliver(MY_SINK, null, "null notification", "null rule");
-        verify(engineMgr, never()).deliver(any(), any());
-
-        mgr.deliver(MY_SINK, "publishA", "A notification", "A rule");
-        verify(engineMgr).deliver(MY_SINK, "publishA");
-
-        // cause deliver() to throw an exception
-        when(engineMgr.deliver(any(), any())).thenThrow(new IllegalStateException("expected exception"));
-        assertThatCode(() -> mgr.deliver(MY_SINK, "publishB", "B notification", "B rule")).doesNotThrowAnyException();
-    }
-
-    @Test
-    public void testGetOperationMessage() throws ControlLoopException {
-        // no history yet
-        assertNull(mgr.getOperationMessage());
-
-        // add an outcome
+    void testStoreInDataBase() throws ControlLoopException {
         mgr.start();
-        OperationOutcome outcome = makeOutcome();
-        mgr.addToHistory(outcome);
-
-        assertThat(mgr.getOperationMessage()).contains("actor=" + SIMPLE_ACTOR)
-                        .contains("operation=" + SIMPLE_OPERATION);
-    }
-
-    @Test
-    public void testStoreInDataBase() throws ControlLoopException {
-        mgr.start();
-        OperationOutcome outcome = makeOutcome();
+        var outcome = makeOutcome();
         mgr.addToHistory(outcome);
 
         mgr.storeInDataBase(mgr.getPartialHistory().peekLast());
 
-        verify(dataMgr).store(REQ_ID.toString(), event, null, mgr.getPartialHistory().peekLast().getClOperation());
+        verify(dataMgr).store(REQ_ID.toString(), event.getClosedLoopControlName(), event, null,
+                        mgr.getPartialHistory().peekLast().getClOperation());
     }
 
     @Test
-    public void testMakeControlLoopResponse() {
-        final OperationOutcome outcome = new OperationOutcome();
+    void testMakeControlLoopResponse() {
+        final var outcome = new OperationOutcome();
 
         // no message - should return null
         checkResp(outcome, null);
@@ -781,13 +391,13 @@ public class UsecasesEventManagerTest {
         /*
          * now work with a PciMessage
          */
-        PciMessage msg = new PciMessage();
+        var msg = new PciMessage();
         outcome.setResponse(msg);
 
-        PciBody body = new PciBody();
+        var body = new PciBody();
         msg.setBody(body);
 
-        PciResponse output = new PciResponse();
+        var output = new PciResponse();
         body.setOutput(output);
 
         output.setPayload("my-payload");
@@ -812,27 +422,11 @@ public class UsecasesEventManagerTest {
     }
 
     @Test
-    public void testOnNewEvent() {
-        VirtualControlLoopEvent event2 = new VirtualControlLoopEvent(event);
-        assertEquals(NewEventStatus.FIRST_ONSET, mgr.onNewEvent(event2));
-
-        event2.setPayload("other payload");
-        assertEquals(NewEventStatus.SUBSEQUENT_ONSET, mgr.onNewEvent(event2));
-        assertEquals(NewEventStatus.SUBSEQUENT_ONSET, mgr.onNewEvent(event2));
-        assertEquals(NewEventStatus.FIRST_ONSET, mgr.onNewEvent(event));
-
-        event2.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
-        assertEquals(NewEventStatus.FIRST_ABATEMENT, mgr.onNewEvent(event2));
-
-        assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, mgr.onNewEvent(event2));
-        assertEquals(NewEventStatus.SUBSEQUENT_ABATEMENT, mgr.onNewEvent(event2));
-
-        event2.setClosedLoopEventStatus(null);
-        assertEquals(NewEventStatus.SYNTAX_ERROR, mgr.onNewEvent(event2));
-    }
+    void testCheckEventSyntax() {
+        /*
+         * only need to check one success and one failure from the super class method
+         */
 
-    @Test
-    public void testCheckEventSyntax() {
         // initially, it's valid
         assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
 
@@ -844,34 +438,26 @@ public class UsecasesEventManagerTest {
         assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
                         .hasMessage("No target field");
 
-        // abated supersedes previous errors - so it shouldn't throw an exception
-        event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
-        assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
-
         event.setRequestId(null);
         assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
                         .hasMessage("No request ID");
-
-        event.setClosedLoopControlName(null);
-        assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
-                        .hasMessage("No control loop name");
     }
 
     @Test
-    public void testValidateStatus() {
+    void testValidateStatus() {
+        /*
+         * only need to check one success and one failure from the super class method
+         */
         event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
         assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
 
-        event.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
-        assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
-
         event.setClosedLoopEventStatus(null);
         assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
                         .hasMessage("Invalid value in closedLoopEventStatus");
     }
 
     @Test
-    public void testValidateAaiData() {
+    void testValidateAaiData() {
         event.setTargetType("unknown-target-type");
         assertThatCode(() -> mgr.checkEventSyntax(event)).isInstanceOf(ControlLoopException.class)
                         .hasMessage("The target type is not supported");
@@ -910,7 +496,7 @@ public class UsecasesEventManagerTest {
     }
 
     @Test
-    public void testValidateAaiVmVnfData() {
+    void testValidateAaiVmVnfData() {
         event.setTargetType(ControlLoopTargetType.VM);
         event.setAai(Map.of(UsecasesConstants.GENERIC_VNF_VNF_ID, MY_TARGET));
         assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
@@ -927,7 +513,7 @@ public class UsecasesEventManagerTest {
     }
 
     @Test
-    public void testValidateAaiPnfData() {
+    void testValidateAaiPnfData() {
         event.setTargetType(ControlLoopTargetType.PNF);
         event.setAai(Map.of(UsecasesConstants.PNF_NAME, MY_TARGET));
         assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
@@ -938,59 +524,60 @@ public class UsecasesEventManagerTest {
     }
 
     @Test
-    public void testIsClosedLoopDisabled() {
-        Map<String, String> orig = event.getAai();
+    void testIsClosedLoopDisabled() {
+        var orig = event.getAai();
 
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "true"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .isInstanceOf(IllegalStateException.class);
 
         event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, "true"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .isInstanceOf(IllegalStateException.class);
 
         event.setAai(addAai(orig, UsecasesConstants.PNF_IS_IN_MAINT, "true"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void testIsProvStatusInactive() {
-        Map<String, String> orig = event.getAai();
+    void testIsProvStatusInactive() {
+        var orig = event.getAai();
 
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "ACTIVE"));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
 
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "inactive"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .isInstanceOf(IllegalStateException.class);
 
         event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "ACTIVE"));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
 
         event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "inactive"));
-        assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+        assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                         .isInstanceOf(IllegalStateException.class);
     }
 
     @Test
-    public void testIsAaiTrue() {
-        Map<String, String> orig = event.getAai();
+    void testIsAaiTrue() {
+        var orig = event.getAai();
 
-        for (String value : Arrays.asList("yes", "y", "true", "t", "yEs", "trUe")) {
+        for (var value : Arrays.asList("yes", "y", "true", "t", "yEs", "trUe")) {
             event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, value));
-            assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+            assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
                             .isInstanceOf(IllegalStateException.class);
         }
 
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "false"));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
 
         event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "no"));
-        assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+        assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
     }
 
 
+
     private Map<String, String> addAai(Map<String, String> original, String key, String value) {
         Map<String, String> map = new TreeMap<>(original);
         map.put(key, value);
@@ -998,8 +585,7 @@ public class UsecasesEventManagerTest {
     }
 
     private void loadPolicy(String fileName) throws CoderException {
-        ToscaServiceTemplate template =
-                        yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
+        var template = yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
         tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
 
         params.setToscaPolicy(tosca);
@@ -1029,14 +615,14 @@ public class UsecasesEventManagerTest {
     }
 
     private OperationOutcome makeCompletedOutcome() {
-        OperationOutcome outcome = makeOutcome();
+        var outcome = makeOutcome();
         outcome.setEnd(outcome.getStart());
 
         return outcome;
     }
 
     private OperationOutcome makeOutcome() {
-        OperationOutcome outcome = new OperationOutcome();
+        var outcome = new OperationOutcome();
         outcome.setActor(SIMPLE_ACTOR);
         outcome.setOperation(SIMPLE_OPERATION);
         outcome.setMessage(OUTCOME_MSG);
@@ -1048,7 +634,7 @@ public class UsecasesEventManagerTest {
     }
 
     private void checkResp(OperationOutcome outcome, String expectedPayload) {
-        ControlLoopResponse resp = mgr.makeControlLoopResponse(outcome);
+        var resp = mgr.makeControlLoopResponse(outcome);
         assertNotNull(resp);
         assertEquals(REQ_ID, resp.getRequestId());
         assertEquals(expectedPayload, resp.getPayload());
@@ -1065,10 +651,10 @@ public class UsecasesEventManagerTest {
     private class MyManager extends UsecasesEventManager {
         private static final long serialVersionUID = 1L;
 
-        public MyManager(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
-                        throws ControlLoopException {
+        public MyManager(EventManagerServices services, ControlLoopParams params, VirtualControlLoopEvent event,
+                        WorkingMemory workMem) throws ControlLoopException {
 
-            super(params, event, workMem);
+            super(services, params, event, workMem);
         }
 
         @Override
@@ -1078,21 +664,11 @@ public class UsecasesEventManagerTest {
 
         @Override
         protected void makeLock(String targetEntity, String requestId, int holdSec, LockCallback callback) {
-            LockImpl lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
+            var lock = new LockImpl(LockState.ACTIVE, targetEntity, requestId, holdSec, callback);
             locks.add(lock);
             callback.lockAvailable(lock);
         }
 
-        @Override
-        public ActorService getActorService() {
-            return actors;
-        }
-
-        @Override
-        public OperationHistoryDataManager getDataManager() {
-            return dataMgr;
-        }
-
         @Override
         protected PolicyEngine getPolicyEngineManager() {
             return engineMgr;