* 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.
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;
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;
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";
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;
/**
* Sets up.
*/
- @Before
+ @BeforeEach
public void setUp() throws ControlLoopException, CoderException {
when(workMem.getFactHandle(any())).thenReturn(factHandle);
}
@Test
- public void testConstructor() {
+ void testConstructor() {
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
}
@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);
assertNull(mgr.getFinalResult());
// add an outcome
- OperationOutcome outcome = makeOutcome();
+ var outcome = makeOutcome();
mgr.addToHistory(outcome);
// indicate success and load next policy
}
@Test
- public void testExecuteStep() {
+ void testExecuteStep() {
mgr.bumpAttempts();
// no steps to execute
}
@Test
- public void testBumpAttempts() {
+ void testBumpAttempts() {
assertEquals(0, mgr.getAttempts());
mgr.bumpAttempts();
}
@Test
- public void testIsAbort() {
- OperationOutcome outcome = makeCompletedOutcome();
+ void testIsAbort() {
+ var outcome = makeCompletedOutcome();
outcome.setResult(OperationResult.FAILURE);
assertTrue(mgr.isAbort(outcome));
}
@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);
}
@Test
- public void testMakeNotification() throws Exception {
+ void testMakeNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
mgr = new MyManager(services, params, REQ_ID, workMem);
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);
}
@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)
}
@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);
@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);
}