Make Actors event-agnostic
[policy/models.git] / models-interactions / model-actors / actor.appclcm / src / test / java / org / onap / policy / controlloop / actor / appclcm / AppcLcmOperationTest.java
index b2a44af..650c5da 100644 (file)
 
 package org.onap.policy.controlloop.actor.appclcm;
 
+import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
 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.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
 
 import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 import org.junit.After;
 import org.junit.AfterClass;
@@ -52,17 +52,16 @@ import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.controlloop.ControlLoopOperation;
 import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
-import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
-import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
 import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
 import org.onap.policy.simulators.AppcLcmTopicServer;
 import org.onap.policy.simulators.TopicServer;
 
-public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
+public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation<AppcLcmDmaapWrapper> {
 
     private static final String EXPECTED_EXCEPTION = "expected exception";
     private static final String PAYLOAD_KEY1 = "key-A";
@@ -102,8 +101,8 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
         super.tearDownBasic();
     }
 
-    @SuppressWarnings("rawtypes")
-    protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+    @Override
+    protected TopicServer<AppcLcmDmaapWrapper> makeServer(TopicSink sink, TopicSource source) {
         return new AppcLcmTopicServer(sink, source);
     }
 
@@ -118,52 +117,22 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
 
         params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
 
-        oper = new AppcLcmOperation(params, config) {
-            @Override
-            protected CompletableFuture<OperationOutcome> startGuardAsync() {
-                return null;
-            }
-        };
+        oper = new AppcLcmOperation(params, config);
 
         outcome = oper.start().get();
-        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+        assertEquals(OperationResult.SUCCESS, outcome.getResult());
+        assertTrue(outcome.getResponse() instanceof AppcLcmDmaapWrapper);
     }
 
     @Test
     public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
         assertEquals(DEFAULT_OPERATION, oper.getName());
-
-        // missing target entity
-        params = params.toBuilder().targetEntity("").build();
-        assertThatIllegalArgumentException().isThrownBy(() -> new AppcLcmOperation(params, config))
-                        .withMessage("missing targetEntity");
     }
 
     @Test
-    public void testStartPreprocessorAsync() throws Exception {
-        context = mock(ControlLoopEventContext.class);
-        when(context.getEvent()).thenReturn(event);
-        params = params.toBuilder().context(context).build();
-
-        AtomicBoolean guardStarted = new AtomicBoolean();
-
-        oper = new AppcLcmOperation(params, config) {
-            @Override
-            protected CompletableFuture<OperationOutcome> startGuardAsync() {
-                guardStarted.set(true);
-                return super.startGuardAsync();
-            }
-        };
-
-        CompletableFuture<OperationOutcome> future2 = oper.startPreprocessorAsync();
-        assertNotNull(future2);
-        assertFalse(future.isDone());
-        assertTrue(guardStarted.get());
-
-        assertTrue(executor.runAll(100));
-        assertTrue(future2.isDone());
-        assertEquals(PolicyResult.SUCCESS, future2.get().getResult());
+    public void testGetPropertyNames() {
+        assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY));
     }
 
     @Test
@@ -200,7 +169,7 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
         // coder exception
         oper = new AppcLcmOperation(params, config) {
             @Override
-            protected Coder makeCoder() {
+            protected Coder getCoder() {
                 return new StandardCoder() {
                     @Override
                     public String encode(Object object) throws CoderException {
@@ -255,24 +224,28 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
 
     @Test
     public void testSetOutcome() {
-        oper.setOutcome(outcome, PolicyResult.SUCCESS, response);
-        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+        oper.setOutcome(outcome, OperationResult.SUCCESS, response);
+        assertEquals(OperationResult.SUCCESS, outcome.getResult());
         assertEquals(MY_MESSAGE, outcome.getMessage());
+        assertSame(response, outcome.getResponse());
 
         // failure
-        oper.setOutcome(outcome, PolicyResult.FAILURE, response);
-        assertEquals(PolicyResult.FAILURE, outcome.getResult());
+        oper.setOutcome(outcome, OperationResult.FAILURE, response);
+        assertEquals(OperationResult.FAILURE, outcome.getResult());
         assertEquals(MY_MESSAGE, outcome.getMessage());
+        assertSame(response, outcome.getResponse());
 
         // null message
         response.getBody().getOutput().getStatus().setMessage(null);
-        oper.setOutcome(outcome, PolicyResult.SUCCESS, response);
+        oper.setOutcome(outcome, OperationResult.SUCCESS, response);
         assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
+        assertSame(response, outcome.getResponse());
 
         // null status
         response.getBody().getOutput().setStatus(null);
-        oper.setOutcome(outcome, PolicyResult.SUCCESS, response);
+        oper.setOutcome(outcome, OperationResult.SUCCESS, response);
         assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
+        assertSame(response, outcome.getResponse());
     }
 
     @Test
@@ -339,10 +312,10 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
     protected void makeContext() {
         super.makeContext();
 
-        Target target = new Target();
-        target.setResourceID(RESOURCE_ID);
+        Map<String, String> targetEntities = new HashMap<>();
+        targetEntities.put(ControlLoopOperationParams.PARAMS_ENTITY_RESOURCEID, RESOURCE_ID);
 
-        params = params.toBuilder().target(target).build();
+        params = params.toBuilder().targetEntityIds(targetEntities).build();
     }
 
     @Override