aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/eventmanager/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common/eventmanager/src/test/java')
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java10
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java45
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java12
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java105
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/EventManagerServicesTest.java1
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/LockDataTest.java6
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/StepTest.java46
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java42
-rw-r--r--controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java2
9 files changed, 130 insertions, 139 deletions
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
index 9534f938a..05eba6450 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/SupportUtil.java
@@ -26,7 +26,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.apache.commons.io.IOUtils;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
+import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.Constructor;
@@ -53,15 +53,15 @@ public final class SupportUtil {
* @return a Pair
* @throws IOException if the file cannot be read
*/
- public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) throws IOException {
+ public static Pair<ToscaPolicy, String> loadYaml(String testFile) throws IOException {
try (InputStream is = new FileInputStream(new File(testFile))) {
String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
//
// Read the yaml into our Java Object
//
- Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- Object obj = yaml.load(contents);
- return new Pair<>((ControlLoopPolicy) obj, contents);
+ Yaml yaml = new Yaml(new Constructor(ToscaPolicy.class));
+ ToscaPolicy obj = yaml.load(contents);
+ return new Pair<>(obj, contents);
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
index 86381ebec..1c4030c08 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager2Test.java
@@ -47,7 +47,6 @@ import java.util.function.Consumer;
import org.drools.core.WorkingMemory;
import org.junit.Before;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.kie.api.runtime.rule.FactHandle;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
@@ -66,18 +65,16 @@ 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.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ControlLoopEventManager2.NewEventStatus;
import org.onap.policy.controlloop.eventmanager.ControlLoopOperationManager2.State;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
+import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -117,7 +114,6 @@ public class ControlLoopEventManager2Test {
private long preCreateTimeMs;
private List<LockImpl> locks;
- private Target target;
private ToscaPolicy tosca;
private ControlLoopParams params;
private VirtualControlLoopEvent event;
@@ -158,10 +154,7 @@ public class ControlLoopEventManager2Test {
event.setAai(new TreeMap<>(Map.of(ControlLoopOperationManager2.VSERVER_VSERVER_NAME, MY_TARGET)));
event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
event.setClosedLoopControlName(CL_NAME);
- event.setTargetType(TargetType.VNF.toString());
-
- target = new Target();
- target.setType(TargetType.VNF);
+ event.setTargetType(ControlLoopTargetType.VNF);
params = new ControlLoopParams();
params.setClosedLoopControlName(CL_NAME);
@@ -217,11 +210,11 @@ public class ControlLoopEventManager2Test {
for (ControlLoopOperationManager2 oper : Arrays.asList(oper1, oper2, oper3)) {
assertTrue(mgr.isActive());
- nextStep(oper, true, PolicyResult.SUCCESS);
+ nextStep(oper, true, OperationResult.SUCCESS);
runRule();
assertTrue(mgr.isActive());
- nextStep(oper, false, PolicyResult.SUCCESS);
+ nextStep(oper, false, OperationResult.SUCCESS);
runRule();
}
@@ -257,7 +250,7 @@ public class ControlLoopEventManager2Test {
@Test
public void testNextStep_testStartOperationSuccess() throws ControlLoopException {
- runOperation(PolicyResult.SUCCESS);
+ runOperation(OperationResult.SUCCESS);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_SUCCESS, notif.getNotification());
@@ -291,7 +284,7 @@ public class ControlLoopEventManager2Test {
*/
@Test
public void testStartOperationException() throws ControlLoopException {
- runOperation(PolicyResult.FAILURE_EXCEPTION);
+ runOperation(OperationResult.FAILURE_EXCEPTION);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notif.getNotification());
@@ -303,7 +296,7 @@ public class ControlLoopEventManager2Test {
*/
@Test
public void testStartOperationFailure() throws ControlLoopException {
- runOperation(PolicyResult.FAILURE);
+ runOperation(OperationResult.FAILURE);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_FAILURE, notif.getNotification());
@@ -315,7 +308,7 @@ public class ControlLoopEventManager2Test {
*/
@Test
public void testStartOperationOpenLoop() throws ControlLoopException {
- runOperation(PolicyResult.FAILURE_GUARD);
+ runOperation(OperationResult.FAILURE_GUARD);
VirtualControlLoopNotification notif = mgr.getNotification();
assertEquals(ControlLoopNotificationType.FINAL_OPENLOOP, notif.getNotification());
@@ -441,7 +434,7 @@ public class ControlLoopEventManager2Test {
mgr.start();
- nextStep(oper1, true, PolicyResult.SUCCESS);
+ nextStep(oper1, true, OperationResult.SUCCESS);
runRule();
// check notification while running
@@ -451,7 +444,7 @@ public class ControlLoopEventManager2Test {
List<ControlLoopOperation> history = notif.getHistory();
assertNotNull(history);
- nextStep(oper1, false, PolicyResult.SUCCESS);
+ nextStep(oper1, false, OperationResult.SUCCESS);
runRule();
assertFalse(mgr.isActive());
@@ -635,7 +628,7 @@ public class ControlLoopEventManager2Test {
event.setAai(addAai(orig, ControlLoopEventManager2.GENERIC_VNF_PROV_STATUS, "ACTIVE"));
assertThatCode(() -> new ControlLoopEventManager2(params, event, workMem)).doesNotThrowAnyException();
-
+
event.setAai(addAai(orig, ControlLoopEventManager2.GENERIC_VNF_PROV_STATUS, "inactive"));
assertThatThrownBy(() -> new ControlLoopEventManager2(params, event, workMem))
.isInstanceOf(IllegalStateException.class);
@@ -701,11 +694,11 @@ public class ControlLoopEventManager2Test {
}
- private void nextStep(ControlLoopOperationManager2 oper, boolean moreSteps, PolicyResult result) {
+ private void nextStep(ControlLoopOperationManager2 oper, boolean moreSteps, OperationResult result) {
when(oper.nextStep()).thenReturn(moreSteps);
when(oper.getOperationResult()).thenReturn(result);
- if (result == PolicyResult.SUCCESS) {
+ if (result == OperationResult.SUCCESS) {
when(oper.getState()).thenReturn(State.OPERATION_SUCCESS);
} else {
when(oper.getState()).thenReturn(State.OPERATION_FAILURE);
@@ -723,13 +716,13 @@ public class ControlLoopEventManager2Test {
mgr.nextStep();
}
- private void runOperation(PolicyResult finalResult) throws ControlLoopException {
+ private void runOperation(OperationResult finalResult) throws ControlLoopException {
mgr.start();
verify(oper1).start(anyLong());
assertTrue(mgr.isActive());
- nextStep(oper1, true, PolicyResult.SUCCESS);
+ nextStep(oper1, true, OperationResult.SUCCESS);
runRule();
nextStep(oper1, false, finalResult);
@@ -814,8 +807,8 @@ public class ControlLoopEventManager2Test {
}
@Override
- protected ControlLoopOperationManager2 makeOperationManager(ControlLoopEventContext ctx, Policy policy) {
- switch (policy.getActor()) {
+ protected ControlLoopOperationManager2 makeOperationManager(ControlLoopEventContext ctx, Operation policy) {
+ switch (policy.getActorOperation().getActor()) {
case "First":
return oper1;
case "Second":
@@ -823,7 +816,7 @@ public class ControlLoopEventManager2Test {
case "Third":
return oper3;
default:
- throw new IllegalArgumentException("unknown policy actor " + policy.getActor());
+ throw new IllegalArgumentException("unknown policy actor " + policy.getActorOperation().getActor());
}
}
}
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 0b37abb14..e4c233281 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
@@ -47,10 +47,8 @@ import org.onap.policy.common.utils.io.Serializer;
import org.onap.policy.common.utils.resources.ResourceUtils;
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.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
@@ -73,7 +71,6 @@ public class ControlLoopEventManagerTest {
private long preCreateTimeMs;
private List<LockImpl> locks;
- private Target target;
private ToscaPolicy tosca;
private ControlLoopParams params;
private ControlLoopEventManager mgr;
@@ -85,9 +82,6 @@ public class ControlLoopEventManagerTest {
public void setUp() throws ControlLoopException, CoderException {
MockitoAnnotations.initMocks(this);
- target = new Target();
- target.setType(TargetType.VNF);
-
params = new ControlLoopParams();
params.setClosedLoopControlName(CL_NAME);
params.setPolicyName(POLICY_NAME);
@@ -189,11 +183,11 @@ public class ControlLoopEventManagerTest {
// indicate that the first lock failed
locks.get(0).notifyUnavailable();
- verifyLock(PolicyResult.FAILURE);
+ verifyLock(OperationResult.FAILURE);
assertTrue(mgr.getOutcomes().isEmpty());
}
- private void verifyLock(PolicyResult result) {
+ private void verifyLock(OperationResult result) {
OperationOutcome outcome = mgr.getOutcomes().poll();
assertNotNull(outcome);
assertEquals(ActorConstants.LOCK_ACTOR, outcome.getActor());
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
index add4c41aa..0b066651b 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopOperationManager2Test.java
@@ -61,15 +61,15 @@ import org.onap.policy.controlloop.actor.guard.GuardActor;
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;
import org.onap.policy.controlloop.actorserviceprovider.Operator;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
+import org.onap.policy.drools.domain.models.operational.ActorOperation;
+import org.onap.policy.drools.domain.models.operational.OperationalTarget;
import org.onap.policy.sdnr.PciBody;
import org.onap.policy.sdnr.PciMessage;
import org.onap.policy.sdnr.PciResponse;
@@ -114,9 +114,11 @@ public class ControlLoopOperationManager2Test {
private CompletableFuture<OperationOutcome> lockFuture;
private CompletableFuture<OperationOutcome> policyFuture;
- private Target target;
+ private ActorOperation operation;
+ private OperationalTarget target;
+ private Map<String, String> entityIds;
private Map<String, String> payload;
- private Policy policy;
+ private org.onap.policy.drools.domain.models.operational.Operation policy;
private VirtualControlLoopEvent event;
private ControlLoopEventContext context;
private PseudoExecutor executor;
@@ -145,19 +147,28 @@ public class ControlLoopOperationManager2Test {
when(vnf.getVnfId()).thenReturn(MY_VNF_ID);
when(cqdata.getDefaultGenericVnf()).thenReturn(vnf);
- target = new Target();
- target.setType(TargetType.VM);
+ entityIds = Map.of("entity-name-A", "entity-value-A");
+
+ target = OperationalTarget.builder()
+ .targetType(TargetType.VM.toString())
+ .entityIds(entityIds)
+ .build();
payload = Map.of(PAYLOAD_KEY, PAYLOAD_VALUE);
- policy = new Policy();
- policy.setId(POLICY_ID);
- policy.setActor(POLICY_ACTOR);
- policy.setRecipe(POLICY_OPERATION);
- policy.setTarget(target);
- policy.setPayload(payload);
- policy.setRetry(POLICY_RETRY);
- policy.setTimeout(POLICY_TIMEOUT);
+ operation = ActorOperation.builder()
+ .actor(POLICY_ACTOR)
+ .operation(POLICY_OPERATION)
+ .payload(payload)
+ .target(target)
+ .build();
+
+ policy = org.onap.policy.drools.domain.models.operational.Operation.builder()
+ .id(POLICY_ID)
+ .actorOperation(operation)
+ .retries(POLICY_RETRY)
+ .timeout(POLICY_TIMEOUT)
+ .build();
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
@@ -200,7 +211,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
OperationOutcome outcome = mgr.getOutcomes().peek();
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertTrue(outcome.isFinalOutcome());
verify(mgrctx, times(4)).updated(mgr);
@@ -211,7 +222,8 @@ public class ControlLoopOperationManager2Test {
*/
@Test
public void testStartDetmTargetException() {
- policy.setTarget(new Target());
+ operation.setTarget(OperationalTarget.builder().build());
+ mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor);
mgr.start(REMAINING_MS);
runToCompletion();
@@ -309,14 +321,15 @@ public class ControlLoopOperationManager2Test {
assertSame(REQ_ID, params.getRequestId());
assertSame(POLICY_RETRY, params.getRetry());
assertNotNull(params.getStartCallback());
- assertSame(target, params.getTarget());
+ assertEquals(target.getTargetType().toString(), params.getTargetType().toString());
+ assertSame(entityIds, params.getTargetEntityIds());
assertEquals(MY_TARGET, params.getTargetEntity());
assertSame(POLICY_TIMEOUT, params.getTimeoutSec());
}
@Test
public void testStartOperationNullPayload() {
- policy.setPayload(null);
+ operation.setPayload(null);
mgr.start(REMAINING_MS);
lockFuture.complete(new OperationOutcome());
@@ -341,7 +354,8 @@ public class ControlLoopOperationManager2Test {
assertSame(REQ_ID, params.getRequestId());
assertSame(POLICY_RETRY, params.getRetry());
assertNotNull(params.getStartCallback());
- assertSame(target, params.getTarget());
+ assertEquals(target.getTargetType().toString(), params.getTargetType().toString());
+ assertSame(entityIds, params.getTargetEntityIds());
assertEquals(MY_TARGET, params.getTargetEntity());
assertSame(POLICY_TIMEOUT, params.getTimeoutSec());
}
@@ -367,7 +381,7 @@ public class ControlLoopOperationManager2Test {
/*
* now work with SDNR actor
*/
- policy.setActor("SDNR");
+ operation.setActor("SDNR");
mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor);
// should return null for a null input
@@ -407,7 +421,7 @@ public class ControlLoopOperationManager2Test {
assertNotNull(mgr.getOperationResult());
runCyle();
- assertEquals(PolicyResult.SUCCESS, mgr.getOperationResult());
+ assertEquals(OperationResult.SUCCESS, mgr.getOperationResult());
}
/**
@@ -420,7 +434,7 @@ public class ControlLoopOperationManager2Test {
genLockFailure();
runToCompletion();
- assertEquals(PolicyResult.FAILURE_GUARD, mgr.getOperationResult());
+ assertEquals(OperationResult.FAILURE_GUARD, mgr.getOperationResult());
}
/**
@@ -490,7 +504,7 @@ public class ControlLoopOperationManager2Test {
// generate failure outcome for ANOTHER actor - should be ignored
OperationOutcome outcome = mgr.getParams().makeOutcome();
outcome.setActor(OTHER_ACTOR);
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
outcome.setStart(Instant.now());
mgr.getParams().callbackStarted(new OperationOutcome(outcome));
@@ -514,7 +528,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
- assertEquals(PolicyResult.SUCCESS, mgr.getOutcomes().peek().getResult());
+ assertEquals(OperationResult.SUCCESS, mgr.getOutcomes().peek().getResult());
verify(mgrctx, times(4)).updated(mgr);
}
@@ -556,7 +570,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx).updated(mgr);
- verifyDb(1, PolicyResult.FAILURE_GUARD, "Operation denied by Lock");
+ verifyDb(1, OperationResult.FAILURE_GUARD, "Operation denied by Lock");
}
/**
@@ -588,7 +602,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx, times(3)).updated(mgr);
- verifyDb(1, PolicyResult.FAILURE, "Operation aborted by Lock");
+ verifyDb(1, OperationResult.FAILURE, "Operation aborted by Lock");
}
/**
@@ -634,7 +648,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx, times(2)).updated(mgr);
- verifyDb(1, PolicyResult.FAILURE_GUARD, "Operation denied by Guard");
+ verifyDb(1, OperationResult.FAILURE_GUARD, "Operation denied by Guard");
}
/**
@@ -664,7 +678,7 @@ public class ControlLoopOperationManager2Test {
assertFalse(mgr.nextStep());
verify(mgrctx, times(4)).updated(mgr);
- verifyDb(2, PolicyResult.SUCCESS, null);
+ verifyDb(2, OperationResult.SUCCESS, null);
}
/**
@@ -690,7 +704,7 @@ public class ControlLoopOperationManager2Test {
assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState());
- verifyDb(2, PolicyResult.FAILURE, null);
+ verifyDb(2, OperationResult.FAILURE, null);
assertThat(mgr.toString()).contains("attempts=1");
@@ -703,7 +717,7 @@ public class ControlLoopOperationManager2Test {
assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_FAILURE, mgr.getState());
- verifyDb(4, PolicyResult.FAILURE, null);
+ verifyDb(4, OperationResult.FAILURE, null);
assertThat(mgr.toString()).contains("attempts=2");
@@ -715,7 +729,7 @@ public class ControlLoopOperationManager2Test {
assertTrue(mgr.nextStep());
assertEquals(ControlLoopOperationManager2.State.OPERATION_SUCCESS, mgr.getState());
- verifyDb(6, PolicyResult.SUCCESS, null);
+ verifyDb(6, OperationResult.SUCCESS, null);
assertThat(mgr.toString()).contains("attempts=3");
@@ -744,29 +758,30 @@ public class ControlLoopOperationManager2Test {
@Test
public void testDetmTargetVm() {
- target.setType(TargetType.VM);
+ target.setTargetType(TargetType.VM.toString());
assertNull(mgr.detmTarget());
assertEquals(MY_TARGET, mgr.getTargetEntity());
- target.setType(TargetType.VNF);
+ target.setTargetType(TargetType.VNF.toString());
assertNull(mgr.detmTarget());
assertEquals(MY_TARGET, mgr.getTargetEntity());
- target.setType(TargetType.VFMODULE);
+ target.setTargetType(TargetType.VFMODULE.toString());
assertNull(mgr.detmTarget());
assertEquals(MY_TARGET, mgr.getTargetEntity());
// unsupported type
- target.setType(TargetType.VFC);
+ target.setTargetType(TargetType.VFC.toString());
assertThatIllegalArgumentException().isThrownBy(() -> mgr.detmTarget())
.withMessage("The target type is not supported");
// null type
- target.setType(null);
+ target.setTargetType(null);
assertThatIllegalArgumentException().isThrownBy(() -> mgr.detmTarget()).withMessage("The target type is null");
// null target
- policy.setTarget(null);
+ operation.setTarget(null);
+ mgr = new ControlLoopOperationManager2(mgrctx, context, policy, executor);
assertThatIllegalArgumentException().isThrownBy(() -> mgr.detmTarget()).withMessage("The target is null");
}
@@ -899,7 +914,7 @@ public class ControlLoopOperationManager2Test {
OperationOutcome outcome = new OperationOutcome();
outcome.setActor(ControlLoopOperationManager2.LOCK_ACTOR);
outcome.setOperation(ControlLoopOperationManager2.LOCK_OPERATION);
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
outcome.setStart(Instant.now());
outcome.setEnd(Instant.now());
outcome.setFinalOutcome(true);
@@ -936,7 +951,7 @@ public class ControlLoopOperationManager2Test {
mgr.getParams().callbackStarted(new OperationOutcome(outcome));
if (!permit) {
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
}
outcome.setEnd(Instant.now());
@@ -969,7 +984,7 @@ public class ControlLoopOperationManager2Test {
if (success) {
outcome.setFinalOutcome(true);
} else {
- outcome.setResult(PolicyResult.FAILURE);
+ outcome.setResult(OperationResult.FAILURE);
}
outcome.setEnd(Instant.now());
@@ -986,7 +1001,7 @@ public class ControlLoopOperationManager2Test {
event.getAai().clear();
event.getAai().putAll(Map.of(ControlLoopOperationManager2.PNF_NAME, MY_TARGET));
- target.setType(TargetType.PNF);
+ target.setTargetType(TargetType.PNF.toString());
}
/**
@@ -997,7 +1012,7 @@ public class ControlLoopOperationManager2Test {
event.getAai().clear();
event.getAai().putAll(Map.of(ControlLoopOperationManager2.GENERIC_VNF_VNF_ID, MY_TARGET));
- target.setType(TargetType.VNF);
+ target.setTargetType(TargetType.VNF.toString());
}
private void checkResp(OperationOutcome outcome, String expectedPayload) {
@@ -1007,7 +1022,7 @@ public class ControlLoopOperationManager2Test {
assertEquals(expectedPayload, resp.getPayload());
}
- private void verifyDb(int nrecords, PolicyResult expectedResult, String expectedMsg) {
+ private void verifyDb(int nrecords, OperationResult expectedResult, String expectedMsg) {
ArgumentCaptor<String> entityCaptor = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ControlLoopOperation> opCaptor = ArgumentCaptor.forClass(ControlLoopOperation.class);
verify(dataMgr, times(nrecords)).store(any(), any(), entityCaptor.capture(), opCaptor.capture());
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 13ad56259..a2f01344f 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
@@ -33,7 +33,6 @@ import org.junit.After;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.rules.ExpectedException;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerImpl;
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 dc470e7c8..98ff04da5 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
@@ -43,7 +43,7 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.drools.core.lock.Lock;
public class LockDataTest {
@@ -135,7 +135,7 @@ public class LockDataTest {
assertEquals(ControlLoopOperationManager2.LOCK_ACTOR, outcome.getActor());
assertEquals(ControlLoopOperationManager2.LOCK_OPERATION, outcome.getOperation());
assertEquals(ENTITY, outcome.getTarget());
- assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
Instant start = outcome.getStart();
@@ -176,7 +176,7 @@ public class LockDataTest {
assertEquals(ControlLoopOperationManager2.LOCK_ACTOR, outcome.getActor());
assertEquals(ControlLoopOperationManager2.LOCK_OPERATION, outcome.getOperation());
assertEquals(ENTITY, outcome.getTarget());
- assertEquals(PolicyResult.FAILURE, outcome.getResult());
+ assertEquals(OperationResult.FAILURE, outcome.getResult());
assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage());
Instant start = outcome.getStart();
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 c4121bb38..efcc6101a 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
@@ -47,30 +47,27 @@ import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
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;
import org.onap.policy.controlloop.actorserviceprovider.Operator;
+import org.onap.policy.controlloop.actorserviceprovider.TargetType;
import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
+import org.onap.policy.drools.domain.models.operational.OperationalTarget;
public class StepTest {
private static final UUID REQ_ID = UUID.randomUUID();
- private static final String POLICY_ID = "my-policy";
private static final String POLICY_ACTOR = "my-actor";
private static final String POLICY_OPERATION = "my-operation";
private static final String MY_TARGET = "my-target";
private static final String PAYLOAD_KEY = "payload-key";
private static final String PAYLOAD_VALUE = "payload-value";
private static final long REMAINING_MS = 5000;
- private static final Integer POLICY_RETRY = 3;
- private static final Integer POLICY_TIMEOUT = 20;
private static final String EXPECTED_EXCEPTION = "expected exception";
@Mock
@@ -83,9 +80,9 @@ public class StepTest {
private ActorService actors;
private CompletableFuture<OperationOutcome> future;
- private Target target;
+ private OperationalTarget target;
+ private Map<String, String> entityIds;
private Map<String, String> payload;
- private Policy policy;
private VirtualControlLoopEvent event;
private ControlLoopEventContext context;
private BlockingQueue<OperationOutcome> starts;
@@ -109,19 +106,14 @@ public class StepTest {
when(policyOperator.buildOperation(any())).thenReturn(policyOperation);
when(policyOperation.start()).thenReturn(future);
- target = new Target();
- target.setType(TargetType.VM);
+ entityIds = Map.of("entity-name-A", "entity-value-A");
- payload = Map.of(PAYLOAD_KEY, PAYLOAD_VALUE);
+ target = OperationalTarget.builder()
+ .targetType(ControlLoopTargetType.VM)
+ .entityIds(entityIds)
+ .build();
- policy = new Policy();
- policy.setId(POLICY_ID);
- policy.setActor(POLICY_ACTOR);
- policy.setRecipe(POLICY_OPERATION);
- policy.setTarget(target);
- policy.setPayload(payload);
- policy.setRetry(POLICY_RETRY);
- policy.setTimeout(POLICY_TIMEOUT);
+ payload = Map.of(PAYLOAD_KEY, PAYLOAD_VALUE);
event = new VirtualControlLoopEvent();
event.setRequestId(REQ_ID);
@@ -136,7 +128,8 @@ public class StepTest {
params = ControlLoopOperationParams.builder().actor(POLICY_ACTOR).actorService(actors)
.completeCallback(completions::add).context(context).executor(ForkJoinPool.commonPool())
.operation(POLICY_OPERATION).payload(new TreeMap<>(payload)).startCallback(starts::add)
- .target(target).targetEntity(MY_TARGET).build();
+ .targetType(TargetType.valueOf(target.getTargetType())).targetEntityIds(target.getEntityIds())
+ .targetEntity(MY_TARGET).build();
startTime = new AtomicReference<>();
@@ -171,7 +164,8 @@ public class StepTest {
assertEquals("operB", params2.getOperation());
assertNull(params2.getRetry());
assertNull(params2.getTimeoutSec());
- assertSame(target, params2.getTarget());
+ assertEquals(target.getTargetType().toString(), params2.getTargetType().toString());
+ assertSame(entityIds, params2.getTargetEntityIds());
assertEquals(MY_TARGET, params2.getTargetEntity());
assertTrue(params2.getPayload().isEmpty());
@@ -257,7 +251,7 @@ public class StepTest {
OperationOutcome outcome = completions.poll();
assertNotNull(outcome);
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(POLICY_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
}
@@ -276,7 +270,7 @@ public class StepTest {
OperationOutcome outcome = completions.poll();
assertNotNull(outcome);
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(POLICY_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
}
@@ -318,7 +312,7 @@ public class StepTest {
OperationOutcome outcome = completions.poll();
assertNotNull(outcome);
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(POLICY_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
assertEquals(POLICY_OPERATION, outcome.getOperation());
@@ -348,7 +342,7 @@ public class StepTest {
// verify that the future was cancelled
assertTrue(future.isCancelled());
- assertNotEquals(PolicyResult.SUCCESS, outcome.getResult());
+ assertNotEquals(OperationResult.SUCCESS, outcome.getResult());
assertEquals(ActorConstants.CL_TIMEOUT_ACTOR, outcome.getActor());
assertTrue(outcome.isFinalOutcome());
assertNull(outcome.getOperation());
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
index 1031c86c7..0ca98720c 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/processor/ControlLoopProcessorTest.java
@@ -30,7 +30,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
-import java.nio.file.Paths;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
@@ -38,9 +37,9 @@ import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.policy.FinalResult;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.controlloop.actorserviceprovider.OperationFinalResult;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
+import org.onap.policy.drools.domain.models.operational.Operation;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
import org.slf4j.Logger;
@@ -52,8 +51,7 @@ public class ControlLoopProcessorTest {
@Test
public void testControlLoopProcessor() throws IOException, ControlLoopException {
- InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
- String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+ String yamlString = Files.readString(new File("src/test/resources/test.yaml").toPath(), StandardCharsets.UTF_8);
this.testSuccess(yamlString);
this.testFailure(yamlString);
}
@@ -116,18 +114,18 @@ public class ControlLoopProcessorTest {
String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
assertThatThrownBy(() -> new ControlLoopProcessor(yamlString))
- .hasMessageStartingWith("Cannot create property=string for JavaBean=ControlLoopPolicy");
+ .hasMessageEndingWith("Cannot decode yaml into ToscaServiceTemplate");
}
@Test
public void testControlLoopProcessorBadTriggerYaml() throws IOException, ControlLoopException {
- InputStream is = new FileInputStream(new File("src/test/resources/badtriggerpolicy.yaml"));
- String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+ String yamlString = Files.readString(new File("src/test/resources/badtriggerpolicy.yaml").toPath(),
+ StandardCharsets.UTF_8);
ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
assertNull(clProcessor.getCurrentPolicy());
- assertThatThrownBy(() -> clProcessor.nextPolicyForResult(PolicyResult.SUCCESS))
+ assertThatThrownBy(() -> clProcessor.nextPolicyForResult(OperationResult.SUCCESS))
.hasMessageStartingWith("There is no current policy to determine where to go to.");
}
@@ -146,12 +144,12 @@ public class ControlLoopProcessorTest {
InputStream is = new FileInputStream(new File("src/test/resources/test.yaml"));
String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
- for (PolicyResult result : PolicyResult.values()) {
+ for (OperationResult result : OperationResult.values()) {
checkResult(yamlString, result);
}
}
- private void checkResult(String yamlString, PolicyResult result) throws ControlLoopException {
+ private void checkResult(String yamlString, OperationResult result) throws ControlLoopException {
ControlLoopProcessor clProcessor = new ControlLoopProcessor(yamlString);
clProcessor.getCurrentPolicy();
clProcessor.nextPolicyForResult(result);
@@ -165,17 +163,17 @@ public class ControlLoopProcessorTest {
*/
public void testSuccess(String yaml) throws ControlLoopException {
ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
- logger.debug("testSuccess: {}", processor.getControlLoop());
+ logger.debug("testSuccess: {}", processor.getCurrentPolicy());
while (true) {
- FinalResult result = processor.checkIsCurrentPolicyFinal();
+ OperationFinalResult result = processor.checkIsCurrentPolicyFinal();
if (result != null) {
logger.debug("{}", result);
break;
}
- Policy policy = processor.getCurrentPolicy();
+ Operation policy = processor.getCurrentPolicy();
assertNotNull(policy);
- logger.debug("current policy is: {} {}", policy.getId(), policy.getName());
- processor.nextPolicyForResult(PolicyResult.SUCCESS);
+ logger.debug("current policy is: {}", policy.getId());
+ processor.nextPolicyForResult(OperationResult.SUCCESS);
}
}
@@ -187,17 +185,17 @@ public class ControlLoopProcessorTest {
*/
public void testFailure(String yaml) throws ControlLoopException {
ControlLoopProcessor processor = new ControlLoopProcessor(yaml);
- logger.debug("testFailure: {}", processor.getControlLoop());
+ logger.debug("testFailure: {}", processor.getCurrentPolicy());
while (true) {
- FinalResult result = processor.checkIsCurrentPolicyFinal();
+ OperationFinalResult result = processor.checkIsCurrentPolicyFinal();
if (result != null) {
logger.debug("{}", result);
break;
}
- Policy policy = processor.getCurrentPolicy();
+ Operation policy = processor.getCurrentPolicy();
assertNotNull(policy);
- logger.debug("current policy is: {} {}", policy.getId(), policy.getName());
- processor.nextPolicyForResult(PolicyResult.FAILURE);
+ logger.debug("current policy is: {}", policy.getId());
+ processor.nextPolicyForResult(OperationResult.FAILURE);
}
}
}
diff --git a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
index c590741f2..9e29af511 100644
--- a/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
+++ b/controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/utils/ControlLoopUtilsTest.java
@@ -24,8 +24,6 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import org.junit.Test;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;