aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager')
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithEventTest.java85
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithOutcomeTest.java99
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ClEventManagerWithStepsTest.java114
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java105
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java34
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java72
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java84
7 files changed, 263 insertions, 330 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 ad01fee78..3b16f465b 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 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.
@@ -23,11 +24,12 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -41,18 +43,14 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import org.drools.core.WorkingMemory;
import org.drools.core.common.InternalFactHandle;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+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.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;
@@ -73,8 +71,7 @@ import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ClEventManagerWithEventTest {
+class ClEventManagerWithEventTest {
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";
@@ -91,30 +88,18 @@ public class ClEventManagerWithEventTest {
private static final Coder yamlCoder = new StandardYamlCoder();
private static final String OUTCOME_MSG = "my outcome message";
- @Mock
- private PolicyEngine engineMgr;
- @Mock
- private WorkingMemory workMem;
- @Mock
- private InternalFactHandle factHandle;
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private EventManagerServices services;
- @Mock
- private ActorService actors;
- @Mock
- private OperationHistoryDataManager dataMgr;
- @Mock
- private ExecutorService executor;
- @Mock
- private MyStep stepa;
- @Mock
- private MyStep 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 ActorService actors = mock(ActorService.class);
+ private final OperationHistoryDataManager dataMgr = mock(OperationHistoryDataManager.class);
+ private final ExecutorService executor = mock(ExecutorService.class);
+ private final MyStep stepa = mock(MyStep.class);
+ private final MyStep stepb = mock(MyStep.class);
private List<LockImpl> locks;
private ToscaPolicy tosca;
@@ -125,7 +110,7 @@ public class ClEventManagerWithEventTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(services.getActorService()).thenReturn(actors);
when(services.getDataManager()).thenReturn(dataMgr);
@@ -154,7 +139,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
assertSame(event, mgr.getEvent());
@@ -168,7 +153,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testPopulateNotification() throws Exception {
+ void testPopulateNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
mgr = new MyManager(services, params, event, workMem);
@@ -228,7 +213,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testStoreInDataBase() throws ControlLoopException {
+ void testStoreInDataBase() throws ControlLoopException {
mgr.start();
OperationOutcome outcome = makeOutcome();
mgr.addToHistory(outcome);
@@ -240,10 +225,10 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testMakeControlLoopResponse() {
- final OperationOutcome outcome = new OperationOutcome();
+ void testMakeControlLoopResponse() {
+ final var outcome = new OperationOutcome();
- ControlLoopResponse resp = mgr.makeControlLoopResponse(outcome);
+ var resp = mgr.makeControlLoopResponse(outcome);
assertNotNull(resp);
assertEquals("DCAE", resp.getTarget());
assertEquals(event.getClosedLoopControlName(), resp.getClosedLoopControlName());
@@ -254,8 +239,8 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testOnNewEvent() {
- VirtualControlLoopEvent event2 = new VirtualControlLoopEvent(event);
+ void testOnNewEvent() {
+ var event2 = new VirtualControlLoopEvent(event);
assertEquals(NewEventStatus.FIRST_ONSET, mgr.onNewEvent(event2));
event2.setPayload("other payload");
@@ -274,7 +259,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testCheckEventSyntax() {
+ void testCheckEventSyntax() {
// initially, it's valid
assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
@@ -296,7 +281,7 @@ public class ClEventManagerWithEventTest {
}
@Test
- public void testValidateStatus() {
+ void testValidateStatus() {
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
assertThatCode(() -> mgr.checkEventSyntax(event)).doesNotThrowAnyException();
@@ -309,7 +294,7 @@ public class ClEventManagerWithEventTest {
}
private void loadPolicy(String fileName) throws CoderException {
- ToscaServiceTemplate template =
+ var template =
yamlCoder.decode(ResourceUtils.getResourceAsString(fileName), ToscaServiceTemplate.class);
tosca = template.getToscaTopologyTemplate().getPolicies().get(0).values().iterator().next();
@@ -317,14 +302,14 @@ public class ClEventManagerWithEventTest {
}
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);
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 7534635d1..17e81044d 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 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,13 +23,14 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThat;
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.assertNull;
+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.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.Instant;
@@ -39,18 +41,13 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.atomic.AtomicReference;
import org.drools.core.WorkingMemory;
import org.drools.core.common.InternalFactHandle;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+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.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.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
@@ -65,8 +62,7 @@ import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ClEventManagerWithOutcomeTest {
+class ClEventManagerWithOutcomeTest {
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";
@@ -82,26 +78,16 @@ public class ClEventManagerWithOutcomeTest {
private static final Coder yamlCoder = new StandardYamlCoder();
private static final String OUTCOME_MSG = "my outcome message";
- @Mock
- private PolicyEngine engineMgr;
- @Mock
- private WorkingMemory workMem;
- @Mock
- private InternalFactHandle factHandle;
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private EventManagerServices services;
- @Mock
- private ExecutorService executor;
- @Mock
- private MyStep stepa;
- @Mock
- private MyStep 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 ExecutorService executor = mock(ExecutorService.class);
+ private final MyStep stepa = mock(MyStep.class);
+ private final MyStep stepb = mock(MyStep.class);
private List<LockImpl> locks;
private ToscaPolicy tosca;
@@ -111,7 +97,7 @@ public class ClEventManagerWithOutcomeTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(workMem.getFactHandle(any())).thenReturn(factHandle);
@@ -129,7 +115,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
@@ -138,7 +124,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testLoadNextPolicy_testGetFullHistory_testGetPartialHistory() throws Exception {
+ void testLoadNextPolicy_testGetFullHistory_testGetPartialHistory() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
mgr = new MyManager(services, params, REQ_ID, workMem);
@@ -148,7 +134,7 @@ public class ClEventManagerWithOutcomeTest {
assertNull(mgr.getFinalResult());
// add an outcome
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
mgr.addToHistory(outcome);
// indicate success and load next policy
@@ -162,7 +148,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testExecuteStep() {
+ void testExecuteStep() {
mgr.bumpAttempts();
// no steps to execute
@@ -171,7 +157,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testBumpAttempts() {
+ void testBumpAttempts() {
assertEquals(0, mgr.getAttempts());
mgr.bumpAttempts();
@@ -180,8 +166,8 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testIsAbort() {
- OperationOutcome outcome = makeCompletedOutcome();
+ void testIsAbort() {
+ var outcome = makeCompletedOutcome();
outcome.setResult(OperationResult.FAILURE);
assertTrue(mgr.isAbort(outcome));
@@ -192,11 +178,11 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testAddToHistory() throws ControlLoopException {
+ void testAddToHistory() throws ControlLoopException {
mgr.start();
// add a "start" outcome
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
mgr.addToHistory(outcome);
assertThat(mgr.getPartialHistory()).hasSize(1);
@@ -244,7 +230,7 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testMakeNotification() throws Exception {
+ void testMakeNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
mgr = new MyManager(services, params, REQ_ID, workMem);
@@ -258,7 +244,7 @@ public class ClEventManagerWithOutcomeTest {
mgr.addToHistory(makeCompletedOutcome());
// check notification while running
- VirtualControlLoopNotification notif = mgr.makeNotification();
+ var notif = mgr.makeNotification();
assertThat(notif.getMessage()).contains(SIMPLE_ACTOR);
assertThat(notif.getHistory()).hasSize(3);
@@ -296,13 +282,13 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testGetOperationMessage() throws ControlLoopException {
+ void testGetOperationMessage() throws ControlLoopException {
// no history yet
assertNull(mgr.getOperationMessage());
// add an outcome
mgr.start();
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
mgr.addToHistory(outcome);
assertThat(mgr.getOperationMessage()).contains("actor=" + SIMPLE_ACTOR)
@@ -310,32 +296,31 @@ public class ClEventManagerWithOutcomeTest {
}
@Test
- public void testMakeControlLoopResponse() {
- final OperationOutcome outcome = new OperationOutcome();
+ void testMakeControlLoopResponse() {
+ final var outcome = new OperationOutcome();
outcome.setActor(SIMPLE_ACTOR);
- ControlLoopResponse resp = mgr.makeControlLoopResponse(outcome);
+ var resp = mgr.makeControlLoopResponse(outcome);
assertNotNull(resp);
assertEquals(SIMPLE_ACTOR, resp.getFrom());
}
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);
}
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);
@@ -363,7 +348,7 @@ public class ClEventManagerWithOutcomeTest {
@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);
}
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 76e8167f4..95d4046ce 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 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.
@@ -24,21 +25,21 @@ 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.assertNull;
+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.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.time.Instant;
import java.util.ArrayList;
-import java.util.Deque;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
@@ -46,11 +47,8 @@ import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicReference;
import org.drools.core.WorkingMemory;
import org.drools.core.common.InternalFactHandle;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+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;
@@ -73,8 +71,7 @@ import org.onap.policy.drools.system.PolicyEngine;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ClEventManagerWithStepsTest {
+class ClEventManagerWithStepsTest {
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";
@@ -91,28 +88,17 @@ public class ClEventManagerWithStepsTest {
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 InternalFactHandle factHandle;
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private ExecutorService executor;
- @Mock
- private EventManagerServices services;
- @Mock
- private ActorService actors;
- @Mock
- private MyStep stepa;
- @Mock
- private MyStep 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 ExecutorService executor = mock(ExecutorService.class);
+ private final EventManagerServices services = mock(EventManagerServices.class);
+ private final ActorService actors = mock(ActorService.class);
+ private MyStep stepa = mock(MyStep.class);
+ private final MyStep stepb = mock(MyStep.class);
private List<LockImpl> locks;
private ToscaPolicy tosca;
@@ -122,7 +108,7 @@ public class ClEventManagerWithStepsTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(services.getActorService()).thenReturn(actors);
@@ -142,7 +128,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
@@ -151,7 +137,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testDestroy_testGetSteps() {
+ void testDestroy_testGetSteps() {
// add some steps to the queue
mgr.getSteps().add(stepa);
mgr.getSteps().add(stepb);
@@ -167,8 +153,8 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testOnStart() throws ControlLoopException {
- OperationOutcome outcome = makeOutcome();
+ void testOnStart() throws ControlLoopException {
+ var outcome = makeOutcome();
mgr.start();
mgr.onStart(outcome);
@@ -180,8 +166,8 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testOnComplete() throws ControlLoopException {
- OperationOutcome outcome = makeCompletedOutcome();
+ void testOnComplete() throws ControlLoopException {
+ var outcome = makeCompletedOutcome();
mgr.start();
mgr.onComplete(outcome);
@@ -193,12 +179,12 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(mgr.toString());
}
@Test
- public void testStart() throws ControlLoopException {
+ void testStart() throws ControlLoopException {
// start it
mgr.start();
@@ -211,7 +197,7 @@ public class ClEventManagerWithStepsTest {
* Tests start() when the manager is not in working memory.
*/
@Test
- public void testStartNotInWorkingMemory() throws ControlLoopException {
+ void testStartNotInWorkingMemory() throws ControlLoopException {
when(workMem.getFactHandle(any())).thenReturn(null);
assertThatCode(() -> mgr.start()).isInstanceOf(IllegalStateException.class)
@@ -222,10 +208,9 @@ public class ClEventManagerWithStepsTest {
* Tests start() when the manager is not active.
*/
@Test
- public void testStartInactive() throws Exception {
+ void testStartInactive() throws Exception {
// make an inactive manager by deserializing it
- RealManager mgr2 = Serializer.roundTrip(new RealManager(services, params, REQ_ID, workMem));
- mgr = mgr2;
+ mgr = Serializer.roundTrip(new RealManager(services, params, REQ_ID, workMem));
// cannot re-start
assertThatCode(() -> mgr.start()).isInstanceOf(IllegalStateException.class)
@@ -233,7 +218,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testAbort() {
+ void testAbort() {
mgr.abort(ClEventManagerWithSteps.State.DONE, OperationFinalResult.FINAL_FAILURE_GUARD, "some message");
assertEquals(ClEventManagerWithSteps.State.DONE, mgr.getState());
@@ -266,18 +251,18 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testLoadPolicy() throws ControlLoopException {
+ void testLoadPolicy() throws ControlLoopException {
// start() will invoke loadPolicy()
mgr.start();
assertNull(mgr.getFinalResult());
- MyStep step = mgr.getSteps().peek();
+ var step = mgr.getSteps().peek();
assertNotNull(step);
assertEquals("First", step.getActorName());
assertEquals("OperationA", step.getOperationName());
- ControlLoopOperationParams params2 = step.getParams();
+ var params2 = step.getParams();
assertSame(actors, params2.getActorService());
assertSame(REQ_ID, params2.getRequestId());
assertSame(ForkJoinPool.commonPool(), params2.getExecutor());
@@ -291,7 +276,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testLoadPreprocessorSteps() {
+ void testLoadPreprocessorSteps() {
stepa = new MyStep(mgr, ControlLoopOperationParams.builder().build()) {
@Override
protected Operation buildOperation() {
@@ -299,7 +284,7 @@ public class ClEventManagerWithStepsTest {
}
};
- Deque<MyStep> steps = mgr.getSteps();
+ var steps = mgr.getSteps();
steps.add(stepa);
steps.add(stepb);
@@ -320,7 +305,7 @@ public class ClEventManagerWithStepsTest {
* Tests loadPreprocessorSteps() when there are too many steps in the queue.
*/
@Test
- public void testLoadPreprocessorStepsTooManySteps() {
+ void testLoadPreprocessorStepsTooManySteps() {
stepa = new MyStep(mgr, ControlLoopOperationParams.builder().build()) {
@Override
protected Operation buildOperation() {
@@ -328,7 +313,7 @@ public class ClEventManagerWithStepsTest {
}
};
- Deque<MyStep> steps = mgr.getSteps();
+ var steps = mgr.getSteps();
// load up a bunch of steps
for (int nsteps = 0; nsteps < ClEventManagerWithSteps.MAX_STEPS; ++nsteps) {
@@ -353,7 +338,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testExecuteStep() {
+ void testExecuteStep() {
// no steps to execute
assertFalse(mgr.executeStep());
@@ -370,7 +355,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testNextStep() {
+ void testNextStep() {
mgr.getSteps().add(stepa);
mgr.nextStep();
@@ -379,7 +364,7 @@ public class ClEventManagerWithStepsTest {
}
@Test
- public void testDeliver() {
+ void testDeliver() {
mgr.deliver(MY_SINK, null, "null notification", "null rule");
verify(engineMgr, never()).deliver(any(), any());
@@ -392,22 +377,21 @@ public class ClEventManagerWithStepsTest {
}
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);
}
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);
@@ -435,7 +419,7 @@ public class ClEventManagerWithStepsTest {
@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);
}
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 ece13611b..d83c3fe78 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
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 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,11 +23,12 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-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.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -34,14 +36,10 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardYamlCoder;
@@ -59,8 +57,7 @@ import org.onap.policy.drools.core.lock.LockState;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
-@RunWith(MockitoJUnitRunner.class)
-public class ControlLoopEventManagerTest {
+class ControlLoopEventManagerTest {
private static final UUID REQ_ID = UUID.randomUUID();
private static final String EXPECTED_EXCEPTION = "expected exception";
private static final String CL_NAME = "my-closed-loop-name";
@@ -72,12 +69,9 @@ public class ControlLoopEventManagerTest {
private static final Coder yamlCoder = new StandardYamlCoder();
private static final String MY_KEY = "def";
- @Mock
- private ExecutorService executor;
- @Mock
- private EventManagerServices services;
- @Mock
- private OperationHistoryDataManager dataMgr;
+ private final ExecutorService executor = mock(ExecutorService.class);
+ private final EventManagerServices services = mock(EventManagerServices.class);
+ private final OperationHistoryDataManager dataMgr = mock(OperationHistoryDataManager.class);
private long preCreateTimeMs;
private List<LockImpl> locks;
@@ -88,7 +82,7 @@ public class ControlLoopEventManagerTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(services.getDataManager()).thenReturn(dataMgr);
@@ -111,7 +105,7 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
assertTrue(mgr.isActive());
@@ -124,7 +118,7 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testGetCreateCount() throws ControlLoopException {
+ void testGetCreateCount() throws ControlLoopException {
long original = ControlLoopEventManager.getCreateCount();
new MyManager(services, params, REQ_ID);
@@ -135,26 +129,26 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testIsActive() throws Exception {
+ void testIsActive() throws Exception {
mgr = new ControlLoopEventManager(services, params, REQ_ID);
assertTrue(mgr.isActive());
- ControlLoopEventManager mgr2 = Serializer.roundTrip(mgr);
+ var mgr2 = Serializer.roundTrip(mgr);
assertFalse(mgr2.isActive());
}
@Test
- public void testDestroy() throws IOException {
+ void testDestroy() throws IOException {
mgr.requestLock(LOCK1);
mgr.requestLock(LOCK2);
mgr.requestLock(LOCK1);
// ensure destroy() doesn't throw an exception if the object is deserialized
- ControlLoopEventManager mgr2 = Serializer.roundTrip(mgr);
+ var mgr2 = Serializer.roundTrip(mgr);
assertThatCode(() -> mgr2.destroy()).doesNotThrowAnyException();
// locks should not have been freed
- for (LockImpl lock : locks) {
+ for (var lock : locks) {
assertFalse(lock.isUnavailable());
}
@@ -162,24 +156,24 @@ public class ControlLoopEventManagerTest {
runExecutor();
- for (LockImpl lock : locks) {
+ for (var lock : locks) {
assertTrue(lock.isUnavailable());
}
}
@Test
- public void testDetmControlLoopTimeoutMs() throws Exception {
+ void testDetmControlLoopTimeoutMs() throws Exception {
long timeMs = 1200 * 1000L;
long end = mgr.getEndTimeMs();
assertThat(end).isGreaterThanOrEqualTo(preCreateTimeMs + timeMs).isLessThan(preCreateTimeMs + timeMs + 5000);
}
@Test
- public void testRequestLock() {
- final CompletableFuture<OperationOutcome> future1 = mgr.requestLock(LOCK1);
+ void testRequestLock() {
+ final var future1 = mgr.requestLock(LOCK1);
assertTrue(mgr.getOutcomes().isEmpty());
- final CompletableFuture<OperationOutcome> future2 = mgr.requestLock(LOCK2);
+ final var future2 = mgr.requestLock(LOCK2);
assertTrue(mgr.getOutcomes().isEmpty());
assertSame(future1, mgr.requestLock(LOCK1));
@@ -198,18 +192,18 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testReleaseLock() {
+ void testReleaseLock() {
mgr.requestLock(LOCK1);
mgr.requestLock(LOCK2);
// release one lock
- final CompletableFuture<OperationOutcome> future = mgr.releaseLock(LOCK1);
+ final var future = mgr.releaseLock(LOCK1);
// asynchronous, thus should not have executed yet
assertThat(future.isDone()).isFalse();
// asynchronous, thus everything should still be locked
- for (LockImpl lock : locks) {
+ for (var lock : locks) {
assertThat(lock.isUnavailable()).isFalse();
}
@@ -229,8 +223,8 @@ public class ControlLoopEventManagerTest {
* Tests releaseLock() when there is no lock.
*/
@Test
- public void testReleaseLockNotLocked() {
- final CompletableFuture<OperationOutcome> future = mgr.releaseLock(LOCK1);
+ void testReleaseLockNotLocked() {
+ final var future = mgr.releaseLock(LOCK1);
// lock didn't exist, so the request should already be complete
assertThat(future.isDone()).isTrue();
@@ -243,14 +237,14 @@ public class ControlLoopEventManagerTest {
* Tests releaseLock() when lock.free() throws an exception.
*/
@Test
- public void testReleaseLockException() throws ControlLoopException {
+ void testReleaseLockException() throws ControlLoopException {
mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@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) {
private static final long serialVersionUID = 1L;
@Override
@@ -267,7 +261,7 @@ public class ControlLoopEventManagerTest {
mgr.requestLock(LOCK1);
// release the lock
- final CompletableFuture<OperationOutcome> future = mgr.releaseLock(LOCK1);
+ final var future = mgr.releaseLock(LOCK1);
// asynchronous, thus should not have executed yet
assertThat(future.isDone()).isFalse();
@@ -279,7 +273,7 @@ public class ControlLoopEventManagerTest {
}
private void verifyLock(OperationResult result, String lockOperation) {
- OperationOutcome outcome = mgr.getOutcomes().poll();
+ var outcome = mgr.getOutcomes().poll();
assertNotNull(outcome);
assertEquals(ActorConstants.LOCK_ACTOR, outcome.getActor());
assertEquals(lockOperation, outcome.getOperation());
@@ -289,9 +283,9 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testOnStart() {
- OperationOutcome outcome1 = new OperationOutcome();
- OperationOutcome outcome2 = new OperationOutcome();
+ void testOnStart() {
+ var outcome1 = new OperationOutcome();
+ var outcome2 = new OperationOutcome();
mgr.onStart(outcome1);
mgr.onStart(outcome2);
@@ -302,9 +296,9 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testOnComplete() {
- OperationOutcome outcome1 = new OperationOutcome();
- OperationOutcome outcome2 = new OperationOutcome();
+ void testOnComplete() {
+ var outcome1 = new OperationOutcome();
+ var outcome2 = new OperationOutcome();
mgr.onComplete(outcome1);
mgr.onComplete(outcome2);
@@ -315,14 +309,14 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testContains_testGetProperty_testSetProperty_testRemoveProperty() {
+ void testContains_testGetProperty_testSetProperty_testRemoveProperty() {
mgr.setProperty("abc", "a string");
mgr.setProperty(MY_KEY, 100);
assertTrue(mgr.contains(MY_KEY));
assertFalse(mgr.contains("ghi"));
- String strValue = mgr.getProperty("abc");
+ var strValue = mgr.getProperty("abc");
assertEquals("a string", strValue);
int intValue = mgr.getProperty(MY_KEY);
@@ -336,7 +330,7 @@ public class ControlLoopEventManagerTest {
* Tests getDataManager() when not disabled.
*/
@Test
- public void testGetDataManagerNotDisabled() throws ControlLoopException {
+ void testGetDataManagerNotDisabled() throws ControlLoopException {
assertThat(mgr.getDataManager()).isSameAs(dataMgr);
}
@@ -344,7 +338,7 @@ public class ControlLoopEventManagerTest {
* Tests getDataManager() when guard.disabled=true.
*/
@Test
- public void testGetDataManagerDisabled() throws ControlLoopException {
+ void testGetDataManagerDisabled() throws ControlLoopException {
mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@@ -358,20 +352,19 @@ public class ControlLoopEventManagerTest {
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(mgr.toString());
}
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);
}
private void runExecutor() {
- ArgumentCaptor<Runnable> runCaptor = ArgumentCaptor.forClass(Runnable.class);
+ var runCaptor = ArgumentCaptor.forClass(Runnable.class);
verify(executor).execute(runCaptor.capture());
runCaptor.getValue().run();
@@ -396,7 +389,7 @@ public class ControlLoopEventManagerTest {
@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);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
index a2f01344f..4af45e56c 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020 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,24 +23,23 @@ package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.util.Properties;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerImpl;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerStub;
import org.onap.policy.drools.persistence.SystemPersistenceConstants;
-public class EventManagerServicesTest {
+class EventManagerServicesTest {
private static final String FILEPFX = "eventService/";
private static final IllegalArgumentException EXPECTED_EXCEPTION =
new IllegalArgumentException("expected exception");
@@ -49,29 +49,29 @@ public class EventManagerServicesTest {
/**
* Configures HTTP clients.
*/
- @BeforeClass
+ @BeforeAll
public static void setUpBeforeClass() throws Exception {
// start with a clean slate
HttpClientFactoryInstance.getClientFactory().destroy();
SystemPersistenceConstants.getManager().setConfigurationDir("src/test/resources");
- Properties props = SystemPersistenceConstants.getManager().getProperties("eventService/event-svc-http-client");
+ var props = SystemPersistenceConstants.getManager().getProperties("eventService/event-svc-http-client");
HttpClientFactoryInstance.getClientFactory().build(props);
}
- @AfterClass
+ @AfterAll
public static void teatDownBeforeClass() {
HttpClientFactoryInstance.getClientFactory().destroy();
}
- @After
+ @AfterEach
public void tearDown() {
closeDb();
}
@Test
- public void testEventManagerServices_testGetActorService() {
+ void testEventManagerServices_testGetActorService() {
// try with guard disabled - should use DB stub
services = new EventManagerServices(FILEPFX + "event-svc-guard-disabled");
assertTrue(services.getDataManager() instanceof OperationHistoryDataManagerStub);
@@ -84,13 +84,13 @@ public class EventManagerServicesTest {
}
@Test
- public void testStartActorService() {
+ void testStartActorService() {
// config file not found
assertThatIllegalStateException().isThrownBy(() -> new EventManagerServices("missing-config-file"));
}
@Test
- public void testIsGuardEnabled() {
+ void testIsGuardEnabled() {
// cannot check guard
services = new EventManagerServices(FILEPFX + "event-svc-no-guard-actor");
assertTrue(services.getDataManager() instanceof OperationHistoryDataManagerStub);
@@ -99,7 +99,7 @@ public class EventManagerServicesTest {
services = new EventManagerServices(FILEPFX + "event-svc-with-db") {
@Override
public ActorService getActorService() {
- ActorService svc = mock(ActorService.class);
+ var svc = mock(ActorService.class);
when(svc.getActor(any())).thenThrow(EXPECTED_EXCEPTION);
return svc;
}
@@ -108,7 +108,7 @@ public class EventManagerServicesTest {
}
@Test
- public void testMakeDataManager() {
+ void testMakeDataManager() {
assertThatThrownBy(() -> new EventManagerServices(FILEPFX + "event-svc-invalid-db"))
.isInstanceOf(IllegalArgumentException.class);
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
index 7b0213107..609de5705 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 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.
@@ -21,65 +22,56 @@
package org.onap.policy.controlloop.eventmanager;
import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-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.assertNotSame;
+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.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
-import java.time.Instant;
import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.drools.core.lock.Lock;
-@RunWith(MockitoJUnitRunner.class)
-public class LockDataTest {
+class LockDataTest {
private static final String ENTITY = "my-entity";
private static final UUID REQ_ID = UUID.randomUUID();
- @Mock
- private Lock lock;
- @Mock
- private Consumer<OperationOutcome> callback1;
- @Mock
- private Consumer<OperationOutcome> callback2;
- @Mock
- private Consumer<OperationOutcome> callback3;
+ private final Lock lock = mock(Lock.class);
+ private final Consumer<OperationOutcome> callback1 = mock();
+ private final Consumer<OperationOutcome> callback2 = mock();
+ private final Consumer<OperationOutcome> callback3 = mock();
private LockData data;
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
data = new LockData(ENTITY, REQ_ID);
}
@Test
- public void testGetFuture() {
- CompletableFuture<OperationOutcome> future = data.getFuture();
+ void testGetFuture() {
+ var future = data.getFuture();
assertNotNull(future);
assertFalse(future.isDone());
}
@Test
- public void testAddUnavailableCallback() {
+ void testAddUnavailableCallback() {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
@@ -96,7 +88,7 @@ public class LockDataTest {
* Tests addUnavailableCallback() when the lock never becomes available.
*/
@Test
- public void testAddUnavailableCallbackNeverAvailable() {
+ void testAddUnavailableCallbackNeverAvailable() {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
@@ -109,7 +101,7 @@ public class LockDataTest {
}
@Test
- public void testFree() {
+ void testFree() {
// no lock yet
assertThatCode(() -> data.free()).doesNotThrowAnyException();
@@ -120,27 +112,27 @@ public class LockDataTest {
}
@Test
- public void testLockAvailable() throws Exception {
+ void testLockAvailable() throws Exception {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
- CompletableFuture<OperationOutcome> future = data.getFuture();
+ var future = data.getFuture();
data.lockAvailable(lock);
assertSame(future, data.getFuture());
assertTrue(future.isDone());
- OperationOutcome outcome = future.get();
+ var outcome = future.get();
assertEquals(ActorConstants.LOCK_ACTOR, outcome.getActor());
assertEquals(ActorConstants.LOCK_OPERATION, outcome.getOperation());
assertEquals(ENTITY, outcome.getTarget());
assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
- Instant start = outcome.getStart();
+ var start = outcome.getStart();
assertNotNull(start);
- Instant end = outcome.getEnd();
+ var end = outcome.getEnd();
assertNotNull(end);
assertTrue(start.compareTo(end) <= 0);
@@ -149,7 +141,7 @@ public class LockDataTest {
}
@Test
- public void testLockUnavailable() throws Exception {
+ void testLockUnavailable() throws Exception {
data.addUnavailableCallback(callback1);
data.addUnavailableCallback(callback2);
data.addUnavailableCallback(callback3);
@@ -157,17 +149,17 @@ public class LockDataTest {
// arrange for callback2 to throw an exception
doThrow(new IllegalStateException("expected exception")).when(callback2).accept(any());
- CompletableFuture<OperationOutcome> future = data.getFuture();
+ var future = data.getFuture();
assertNotNull(future);
data.lockUnavailable(lock);
- CompletableFuture<OperationOutcome> future2 = data.getFuture();
+ var future2 = data.getFuture();
assertNotNull(future2);
assertNotSame(future, future2);
assertTrue(future.isDone());
- OperationOutcome outcome = future.get();
+ var outcome = future.get();
assertTrue(future2.isDone());
assertSame(outcome, future2.get());
@@ -178,10 +170,10 @@ public class LockDataTest {
assertEquals(OperationResult.FAILURE, outcome.getResult());
assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage());
- Instant start = outcome.getStart();
+ var start = outcome.getStart();
assertNotNull(start);
- Instant end = outcome.getEnd();
+ var end = outcome.getEnd();
assertNotNull(end);
assertTrue(start.compareTo(end) <= 0);
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
index 8037f0037..29c92a0e9 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2020-2021 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,14 +23,15 @@ package org.onap.policy.controlloop.eventmanager;
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.assertNotEquals;
-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.assertNotEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.Mockito.mock;
import static org.mockito.Mockito.when;
import java.time.Instant;
@@ -43,11 +45,8 @@ import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
@@ -61,8 +60,7 @@ import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOp
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.drools.domain.models.operational.OperationalTarget;
-@RunWith(MockitoJUnitRunner.class)
-public class StepTest {
+class StepTest {
private static final UUID REQ_ID = UUID.randomUUID();
private static final String POLICY_ACTOR = "my-actor";
private static final String POLICY_OPERATION = "my-operation";
@@ -72,14 +70,10 @@ public class StepTest {
private static final long REMAINING_MS = 5000;
private static final String EXPECTED_EXCEPTION = "expected exception";
- @Mock
- private Operator policyOperator;
- @Mock
- private Operation policyOperation;
- @Mock
- private Actor policyActor;
- @Mock
- private ActorService actors;
+ private final Operator policyOperator = mock(Operator.class);
+ private final Operation policyOperation = mock(Operation.class);
+ private final Actor policyActor = mock(Actor.class);
+ private final ActorService actors = mock(ActorService.class);
private CompletableFuture<OperationOutcome> future;
private OperationalTarget target;
@@ -95,7 +89,7 @@ public class StepTest {
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() {
future = new CompletableFuture<>();
@@ -133,7 +127,7 @@ public class StepTest {
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertTrue(step.isPolicyStep());
assertSame(params, step.getParams());
assertNull(step.getParentStep());
@@ -150,12 +144,12 @@ public class StepTest {
}
@Test
- public void testConstructorWithOtherStep_testInitStartTime_testGetStartTimeRef() {
- Step step2 = new Step(step, "actorB", "operB");
+ void testConstructorWithOtherStep_testInitStartTime_testGetStartTimeRef() {
+ var step2 = new Step(step, "actorB", "operB");
assertFalse(step2.isPolicyStep());
assertSame(step, step2.getParentStep());
- ControlLoopOperationParams params2 = step2.getParams();
+ var params2 = step2.getParams();
assertEquals("actorB", params2.getActor());
assertEquals("operB", params2.getOperation());
assertNull(params2.getRetry());
@@ -173,7 +167,7 @@ public class StepTest {
step2.init();
step2.start(REMAINING_MS);
- Instant instant = startTime.get();
+ var instant = startTime.get();
assertNotNull(instant);
assertSame(instant, step2.getStartTime());
@@ -187,13 +181,13 @@ public class StepTest {
}
@Test
- public void testGetActorName_testGetOperationName() {
+ void testGetActorName_testGetOperationName() {
assertEquals(POLICY_ACTOR, step.getActorName());
assertEquals(POLICY_OPERATION, step.getOperationName());
}
@Test
- public void testIsInitialized_testInit_testGetOperation() {
+ void testIsInitialized_testInit_testGetOperation() {
assertFalse(step.isInitialized());
// verify it's unchanged
@@ -217,7 +211,7 @@ public class StepTest {
}
@Test
- public void testStart() {
+ void testStart() {
assertThatIllegalStateException().isThrownBy(() -> step.start(REMAINING_MS))
.withMessage("step has not been initialized");
@@ -236,14 +230,14 @@ public class StepTest {
* Tests start() when the operation.start() throws an exception.
*/
@Test
- public void testStartException() {
+ void testStartException() {
when(policyOperation.start()).thenThrow(new RuntimeException());
step.init();
assertTrue(step.start(REMAINING_MS));
// exception should be immediate
- OperationOutcome outcome = completions.poll();
+ var outcome = completions.poll();
assertNotNull(outcome);
assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -255,14 +249,14 @@ public class StepTest {
* Tests start() when the operation throws an asynchronous exception.
*/
@Test
- public void testStartAsyncException() {
+ void testStartAsyncException() {
step.init();
step.start(REMAINING_MS);
future.completeExceptionally(new RuntimeException(EXPECTED_EXCEPTION));
// exception should be immediate
- OperationOutcome outcome = completions.poll();
+ var outcome = completions.poll();
assertNotNull(outcome);
assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -274,7 +268,7 @@ public class StepTest {
* Tests handleException() when the exception is a CancellationException.
*/
@Test
- public void testHandleExceptionCancellationException() {
+ void testHandleExceptionCancellationException() {
step.init();
step.start(REMAINING_MS);
@@ -285,7 +279,7 @@ public class StepTest {
}
@Test
- public void testHandleExceptionCauseCancellationException() {
+ void testHandleExceptionCauseCancellationException() {
step.init();
step.start(REMAINING_MS);
@@ -296,7 +290,7 @@ public class StepTest {
}
@Test
- public void testHandleException() {
+ void testHandleException() {
when(policyOperation.start()).thenThrow(new RuntimeException());
step.init();
@@ -304,7 +298,7 @@ public class StepTest {
assertTrue(step.start(REMAINING_MS));
// exception should be immediate
- OperationOutcome outcome = completions.poll();
+ var outcome = completions.poll();
assertNotNull(outcome);
assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
@@ -317,7 +311,7 @@ public class StepTest {
}
@Test
- public void testHandleTimeout() throws InterruptedException {
+ void testHandleTimeout() throws InterruptedException {
step.init();
long tstart = System.currentTimeMillis();
@@ -325,7 +319,7 @@ public class StepTest {
// give it a short timeout
step.start(100);
- OperationOutcome outcome = completions.poll(5, TimeUnit.SECONDS);
+ var outcome = completions.poll(5, TimeUnit.SECONDS);
assertNotNull(outcome);
// should not have timed out before 100ms
@@ -347,7 +341,7 @@ public class StepTest {
}
@Test
- public void testCancel() {
+ void testCancel() {
// should have no effect
step.cancel();
@@ -360,18 +354,18 @@ public class StepTest {
}
@Test
- public void testBuildOperation() {
+ void testBuildOperation() {
assertSame(policyOperation, step.buildOperation());
}
@Test
- public void testMakeOutcome() {
+ void testMakeOutcome() {
step.init();
assertEquals(MY_TARGET, step.makeOutcome().getTarget());
}
@Test
- public void testToString() {
+ void testToString() {
assertNotNull(step.toString());
}
}