Make Actors event-agnostic
[policy/models.git] / models-interactions / model-actors / actorServiceProvider / src / test / java / org / onap / policy / controlloop / actorserviceprovider / parameters / ControlLoopOperationParamsTest.java
index 9dd19d5..b6bd50c 100644 (file)
@@ -49,20 +49,18 @@ import org.junit.Test;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
 import org.onap.policy.common.parameters.BeanValidationResult;
-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.Operator;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams.ControlLoopOperationParamsBuilder;
 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
-import org.onap.policy.controlloop.policy.Target;
 
 public class ControlLoopOperationParamsTest {
+    private static final String NULL_MSG = "null";
     private static final String EXPECTED_EXCEPTION = "expected exception";
     private static final String ACTOR = "my-actor";
     private static final String OPERATION = "my-operation";
-    private static final Target TARGET = new Target();
     private static final String TARGET_ENTITY = "my-target";
     private static final Integer RETRY = 3;
     private static final Integer TIMEOUT = 100;
@@ -77,25 +75,22 @@ public class ControlLoopOperationParamsTest {
     @Mock
     private Consumer<OperationOutcome> completer;
 
-    @Mock
-    private ControlLoopEventContext context;
-
-    @Mock
-    private VirtualControlLoopEvent event;
-
     @Mock
     private Executor executor;
 
     @Mock
-    private CompletableFuture<OperationOutcome> operation;
+    private CompletableFuture<OperationOutcome> operFuture;
 
     @Mock
     private Operator operator;
 
+    @Mock
+    private Operation operation;
+
     @Mock
     private Consumer<OperationOutcome> starter;
 
-    private Map<String, String> payload;
+    private Map<String, Object> payload;
 
     private ControlLoopOperationParams params;
     private OperationOutcome outcome;
@@ -110,39 +105,36 @@ public class ControlLoopOperationParamsTest {
 
         when(actorService.getActor(ACTOR)).thenReturn(actor);
         when(actor.getOperator(OPERATION)).thenReturn(operator);
-        when(operator.startOperation(any())).thenReturn(operation);
-
-        when(event.getRequestId()).thenReturn(REQ_ID);
-
-        when(context.getEvent()).thenReturn(event);
+        when(operator.buildOperation(any())).thenReturn(operation);
+        when(operation.start()).thenReturn(operFuture);
 
         payload = new TreeMap<>();
 
         params = ControlLoopOperationParams.builder().actorService(actorService).completeCallback(completer)
-                        .context(context).executor(executor).actor(ACTOR).operation(OPERATION).payload(payload)
-                        .retry(RETRY).target(TARGET).targetEntity(TARGET_ENTITY).timeoutSec(TIMEOUT)
-                        .startCallback(starter).build();
+                        .requestId(REQ_ID).executor(executor).actor(ACTOR).operation(OPERATION).payload(payload)
+                        .retry(RETRY).targetEntity(TARGET_ENTITY).timeoutSec(TIMEOUT)
+                        .startCallback(starter).preprocessed(true).build();
 
-        outcome = params.makeOutcome();
+        outcome = params.makeOutcome(TARGET_ENTITY);
     }
 
     @Test
     public void testStart() {
-        assertSame(operation, params.start());
+        assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().requestId(null).build().start());
 
-        assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().context(null).build().start());
+        assertSame(operFuture, params.start());
     }
 
     @Test
-    public void testGetRequestId() {
-        assertSame(REQ_ID, params.getRequestId());
+    public void testBuild() {
+        assertThatIllegalArgumentException().isThrownBy(() -> params.toBuilder().requestId(null).build().build());
 
-        // try with null context
-        assertNull(params.toBuilder().context(null).build().getRequestId());
+        assertSame(operation, params.build());
+    }
 
-        // try with null event
-        when(context.getEvent()).thenReturn(null);
-        assertNull(params.getRequestId());
+    @Test
+    public void testGetRequestId() {
+        assertSame(REQ_ID, params.getRequestId());
     }
 
     @Test
@@ -213,22 +205,25 @@ public class ControlLoopOperationParamsTest {
 
     @Test
     public void testValidateFields() {
-        testValidate("actor", "null", bldr -> bldr.actor(null));
-        testValidate("actorService", "null", bldr -> bldr.actorService(null));
-        testValidate("context", "null", bldr -> bldr.context(null));
-        testValidate("executor", "null", bldr -> bldr.executor(null));
-        testValidate("operation", "null", bldr -> bldr.operation(null));
-        testValidate("target", "null", bldr -> bldr.targetEntity(null));
+        testValidate("actor", NULL_MSG, bldr -> bldr.actor(null));
+        testValidate("actorService", NULL_MSG, bldr -> bldr.actorService(null));
+        testValidate("executor", NULL_MSG, bldr -> bldr.executor(null));
+        testValidate("operation", NULL_MSG, bldr -> bldr.operation(null));
+        testValidate("requestId", NULL_MSG, bldr -> bldr.requestId(null));
+
+        // has no target entity
+        BeanValidationResult result = params.toBuilder().targetEntity(null).build().validate();
+        assertTrue(result.isValid());
 
         // check edge cases
         assertTrue(params.toBuilder().build().validate().isValid());
 
         // these can be null
-        assertTrue(params.toBuilder().payload(null).retry(null).target(null).timeoutSec(null).startCallback(null)
+        assertTrue(params.toBuilder().payload(null).retry(null).timeoutSec(null).startCallback(null)
                         .completeCallback(null).build().validate().isValid());
 
         // test with minimal fields
-        assertTrue(ControlLoopOperationParams.builder().actorService(actorService).context(context).actor(ACTOR)
+        assertTrue(ControlLoopOperationParams.builder().actorService(actorService).requestId(REQ_ID).actor(ACTOR)
                         .operation(OPERATION).targetEntity(TARGET_ENTITY).build().validate().isValid());
     }
 
@@ -260,11 +255,6 @@ public class ControlLoopOperationParamsTest {
         assertSame(actorService, params.getActorService());
     }
 
-    @Test
-    public void testGetContext() {
-        assertSame(context, params.getContext());
-    }
-
     @Test
     public void testGetExecutor() {
         assertSame(executor, params.getExecutor());
@@ -287,19 +277,19 @@ public class ControlLoopOperationParamsTest {
     }
 
     @Test
-    public void testGetRetry() {
-        assertSame(RETRY, params.getRetry());
+    public void test() {
+        assertTrue(params.isPreprocessed());
 
-        // should be null when unspecified
-        assertNull(ControlLoopOperationParams.builder().build().getRetry());
+        // should be false when unspecified
+        assertFalse(ControlLoopOperationParams.builder().build().isPreprocessed());
     }
 
     @Test
-    public void testTarget() {
-        assertSame(TARGET, params.getTarget());
+    public void testGetRetry() {
+        assertSame(RETRY, params.getRetry());
 
         // should be null when unspecified
-        assertNull(ControlLoopOperationParams.builder().build().getTarget());
+        assertNull(ControlLoopOperationParams.builder().build().getRetry());
     }
 
     @Test