summaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src/test')
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java28
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java30
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java39
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java33
4 files changed, 62 insertions, 68 deletions
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
index 1a4c1b5b2..759ec90b1 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java
@@ -104,6 +104,8 @@ public class ClEventManagerWithEventTest {
@Mock
private Actor policyActor;
@Mock
+ private EventManagerServices services;
+ @Mock
private ActorService actors;
@Mock
private OperationHistoryDataManager dataMgr;
@@ -125,6 +127,9 @@ public class ClEventManagerWithEventTest {
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getActorService()).thenReturn(actors);
+ when(services.getDataManager()).thenReturn(dataMgr);
+
when(workMem.getFactHandle(any())).thenReturn(factHandle);
event = new VirtualControlLoopEvent();
@@ -145,7 +150,7 @@ public class ClEventManagerWithEventTest {
locks = new ArrayList<>();
- mgr = new MyManager(params, event, workMem);
+ mgr = new MyManager(services, params, event, workMem);
}
@Test
@@ -158,13 +163,14 @@ public class ClEventManagerWithEventTest {
// invalid
event.setTarget("");
- assertThatThrownBy(() -> new MyManager(params, event, workMem)).isInstanceOf(ControlLoopException.class);
+ assertThatThrownBy(() -> new MyManager(services, params, event, workMem))
+ .isInstanceOf(ControlLoopException.class);
}
@Test
public void testPopulateNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, event, workMem);
+ mgr = new MyManager(services, params, event, workMem);
// before started
assertNotNull(mgr.makeNotification());
@@ -333,10 +339,10 @@ public class ClEventManagerWithEventTest {
private class MyManager extends ClEventManagerWithEvent<MyStep> {
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
@@ -352,16 +358,6 @@ public class ClEventManagerWithEventTest {
}
@Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
- @Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java
index d64d2bbc5..ba293c1b5 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java
@@ -51,7 +51,6 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopResponse;
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.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
@@ -59,7 +58,6 @@ import org.onap.policy.controlloop.actorserviceprovider.Operator;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
-import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
@@ -97,9 +95,7 @@ public class ClEventManagerWithOutcomeTest {
@Mock
private Actor policyActor;
@Mock
- private ActorService actors;
- @Mock
- private OperationHistoryDataManager dataMgr;
+ private EventManagerServices services;
@Mock
private ExecutorService executor;
@Mock
@@ -129,7 +125,7 @@ public class ClEventManagerWithOutcomeTest {
locks = new ArrayList<>();
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
}
@Test
@@ -137,13 +133,14 @@ public class ClEventManagerWithOutcomeTest {
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
- assertThatThrownBy(() -> new MyManager(params, null, workMem)).isInstanceOf(ControlLoopException.class);
+ assertThatThrownBy(() -> new MyManager(services, params, null, workMem))
+ .isInstanceOf(ControlLoopException.class);
}
@Test
public void testLoadNextPolicy_testGetFullHistory_testGetPartialHistory() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
// start and load step for first policy
mgr.start();
@@ -249,7 +246,7 @@ public class ClEventManagerWithOutcomeTest {
@Test
public void testMakeNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
// before started
assertNotNull(mgr.makeNotification());
@@ -353,9 +350,10 @@ public class ClEventManagerWithOutcomeTest {
private class MyManager extends ClEventManagerWithOutcome<MyStep> {
private static final long serialVersionUID = 1L;
- public MyManager(ControlLoopParams params, UUID requestId, WorkingMemory workMem) throws ControlLoopException {
+ public MyManager(EventManagerServices services, ControlLoopParams params, UUID requestId, WorkingMemory workMem)
+ throws ControlLoopException {
- super(params, requestId, workMem);
+ super(services, params, requestId, workMem);
}
@Override
@@ -371,16 +369,6 @@ public class ClEventManagerWithOutcomeTest {
}
@Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
- @Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java
index 06dc838e2..3a22d0cf5 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java
@@ -66,7 +66,6 @@ import org.onap.policy.controlloop.actorserviceprovider.Operator;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
-import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
@@ -105,11 +104,11 @@ public class ClEventManagerWithStepsTest {
@Mock
private Actor policyActor;
@Mock
- private ActorService actors;
+ private ExecutorService executor;
@Mock
- private OperationHistoryDataManager dataMgr;
+ private EventManagerServices services;
@Mock
- private ExecutorService executor;
+ private ActorService actors;
@Mock
private MyStep stepa;
@Mock
@@ -125,6 +124,8 @@ public class ClEventManagerWithStepsTest {
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getActorService()).thenReturn(actors);
+
when(workMem.getFactHandle(any())).thenReturn(factHandle);
params = new ControlLoopParams();
@@ -137,7 +138,7 @@ public class ClEventManagerWithStepsTest {
locks = new ArrayList<>();
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
}
@Test
@@ -145,7 +146,8 @@ public class ClEventManagerWithStepsTest {
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
- assertThatThrownBy(() -> new MyManager(params, null, workMem)).isInstanceOf(ControlLoopException.class);
+ assertThatThrownBy(() -> new MyManager(services, params, null, workMem))
+ .isInstanceOf(ControlLoopException.class);
}
@Test
@@ -222,7 +224,7 @@ public class ClEventManagerWithStepsTest {
@Test
public void testStartInactive() throws Exception {
// make an inactive manager by deserializing it
- RealManager mgr2 = Serializer.roundTrip(new RealManager(params, REQ_ID, workMem));
+ RealManager mgr2 = Serializer.roundTrip(new RealManager(services, params, REQ_ID, workMem));
mgr = mgr2;
// cannot re-start
@@ -246,7 +248,7 @@ public class ClEventManagerWithStepsTest {
@Test
public void testLoadNextPolicy() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
// start and load step for first policy
mgr.start();
@@ -420,9 +422,10 @@ public class ClEventManagerWithStepsTest {
private class MyManager extends ClEventManagerWithSteps<MyStep> {
private static final long serialVersionUID = 1L;
- public MyManager(ControlLoopParams params, UUID requestId, WorkingMemory workMem) throws ControlLoopException {
+ public MyManager(EventManagerServices services, ControlLoopParams params, UUID requestId, WorkingMemory workMem)
+ throws ControlLoopException {
- super(params, requestId, workMem);
+ super(services, params, requestId, workMem);
}
@Override
@@ -438,16 +441,6 @@ public class ClEventManagerWithStepsTest {
}
@Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
- @Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
}
@@ -462,10 +455,10 @@ public class ClEventManagerWithStepsTest {
private static class RealManager extends ClEventManagerWithSteps<MyStep> {
private static final long serialVersionUID = 1L;
- public RealManager(ControlLoopParams params, UUID requestId, WorkingMemory workMem)
- throws ControlLoopException {
+ public RealManager(EventManagerServices services, ControlLoopParams params, UUID requestId,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, requestId, workMem);
+ super(services, params, requestId, workMem);
}
@Override
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
index b930f57f8..ece13611b 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
@@ -28,6 +28,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.ArrayList;
@@ -50,6 +51,7 @@ import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
+import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerStub;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
@@ -72,6 +74,10 @@ public class ControlLoopEventManagerTest {
@Mock
private ExecutorService executor;
+ @Mock
+ private EventManagerServices services;
+ @Mock
+ private OperationHistoryDataManager dataMgr;
private long preCreateTimeMs;
private List<LockImpl> locks;
@@ -84,6 +90,8 @@ public class ControlLoopEventManagerTest {
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getDataManager()).thenReturn(dataMgr);
+
params = new ControlLoopParams();
params.setClosedLoopControlName(CL_NAME);
params.setPolicyName(POLICY_NAME);
@@ -99,7 +107,7 @@ public class ControlLoopEventManagerTest {
MyManager.executor = executor;
MyManager.locks = locks;
- mgr = new MyManager(params, REQ_ID);
+ mgr = new MyManager(services, params, REQ_ID);
}
@Test
@@ -119,16 +127,16 @@ public class ControlLoopEventManagerTest {
public void testGetCreateCount() throws ControlLoopException {
long original = ControlLoopEventManager.getCreateCount();
- new MyManager(params, REQ_ID);
+ new MyManager(services, params, REQ_ID);
assertEquals(original + 1, ControlLoopEventManager.getCreateCount());
- new MyManager(params, REQ_ID);
+ new MyManager(services, params, REQ_ID);
assertEquals(original + 2, ControlLoopEventManager.getCreateCount());
}
@Test
public void testIsActive() throws Exception {
- mgr = new ControlLoopEventManager(params, REQ_ID);
+ mgr = new ControlLoopEventManager(services, params, REQ_ID);
assertTrue(mgr.isActive());
ControlLoopEventManager mgr2 = Serializer.roundTrip(mgr);
@@ -236,7 +244,7 @@ public class ControlLoopEventManagerTest {
*/
@Test
public void testReleaseLockException() throws ControlLoopException {
- mgr = new MyManager(params, REQ_ID) {
+ mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@Override
@@ -325,11 +333,19 @@ public class ControlLoopEventManagerTest {
}
/**
+ * Tests getDataManager() when not disabled.
+ */
+ @Test
+ public void testGetDataManagerNotDisabled() throws ControlLoopException {
+ assertThat(mgr.getDataManager()).isSameAs(dataMgr);
+ }
+
+ /**
* Tests getDataManager() when guard.disabled=true.
*/
@Test
public void testGetDataManagerDisabled() throws ControlLoopException {
- mgr = new MyManager(params, REQ_ID) {
+ mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@Override
@@ -368,8 +384,9 @@ public class ControlLoopEventManagerTest {
private static ExecutorService executor;
private static List<LockImpl> locks;
- public MyManager(ControlLoopParams params, UUID requestId) throws ControlLoopException {
- super(params, requestId);
+ public MyManager(EventManagerServices services, ControlLoopParams params, UUID requestId)
+ throws ControlLoopException {
+ super(services, params, requestId);
}
@Override