Test new actors against simulators
[policy/models.git] / models-interactions / model-actors / actor.appclcm / src / test / java / org / onap / policy / controlloop / actor / appclcm / AppcLcmOperationTest.java
index e94eaec..9744d82 100644 (file)
@@ -36,13 +36,19 @@ import java.util.Set;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
+import org.apache.commons.lang3.tuple.Pair;
+import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.onap.policy.appclcm.AppcLcmBody;
 import org.onap.policy.appclcm.AppcLcmCommonHeader;
 import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
 import org.onap.policy.appclcm.AppcLcmOutput;
 import org.onap.policy.appclcm.AppcLcmResponseStatus;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -51,8 +57,12 @@ 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.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.simulators.AppcLcmTopicServer;
+import org.onap.policy.simulators.TopicServer;
 
 public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
 
@@ -67,6 +77,16 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
     private AppcLcmDmaapWrapper response;
     private AppcLcmOperation oper;
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass(MY_SINK, MY_SOURCE);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * Sets up.
      */
@@ -79,6 +99,38 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
         oper = new AppcLcmOperation(params, config);
     }
 
+    @After
+    public void tearDown() {
+        super.tearDownBasic();
+    }
+
+    @SuppressWarnings("rawtypes")
+    protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+        return new AppcLcmTopicServer(sink, source);
+    }
+
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        BidirectionalTopicParams opParams =
+                        BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SOURCE).build();
+        config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, AppcLcmOperation.SELECTOR_KEYS);
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+        oper = new AppcLcmOperation(params, config) {
+            @Override
+            protected CompletableFuture<OperationOutcome> startGuardAsync() {
+                return null;
+            }
+        };
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
     public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
@@ -118,20 +170,26 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
 
     @Test
     public void testMakeRequest() {
-        AppcLcmDmaapWrapper request = oper.makeRequest(2);
+        Pair<String, AppcLcmDmaapWrapper> result = oper.makeRequest(2);
+        String subreq = result.getLeft();
+        assertNotNull(subreq);
+
+        AppcLcmDmaapWrapper request = result.getRight();
         assertEquals("DefaultOperation", request.getBody().getInput().getAction());
 
         AppcLcmCommonHeader header = request.getBody().getInput().getCommonHeader();
         assertNotNull(header);
         assertEquals(params.getRequestId(), header.getRequestId());
 
-        String subreq = header.getSubRequestId();
-        assertNotNull(subreq);
+        assertEquals(subreq, header.getSubRequestId());
 
         assertEquals("{vnf-id=my-target}", request.getBody().getInput().getActionIdentifiers().toString());
 
         // a subsequent request should have a different sub-request id
-        assertNotEquals(subreq, oper.makeRequest(2).getBody().getInput().getCommonHeader().getSubRequestId());
+        result = oper.makeRequest(2);
+        assertNotEquals(subreq, result.getLeft());
+        assertNotNull(result.getLeft());
+        assertEquals(result.getLeft(), result.getRight().getBody().getInput().getCommonHeader().getSubRequestId());
     }
 
     @Test
@@ -140,7 +198,7 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
         params = params.toBuilder().operation(AppcLcmConstants.OPERATION_CONFIG_MODIFY).build();
         oper = new AppcLcmOperation(params, config);
 
-        AppcLcmDmaapWrapper req = oper.makeRequest(2);
+        AppcLcmDmaapWrapper req = oper.makeRequest(2).getRight();
         assertEquals("{\"key-A\":\"value-A\"}", req.getBody().getInput().getPayload());
 
         // coder exception
@@ -162,7 +220,7 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation {
 
     @Test
     public void testGetExpectedKeyValues() {
-        AppcLcmDmaapWrapper request = oper.makeRequest(2);
+        AppcLcmDmaapWrapper request = oper.makeRequest(2).getRight();
         assertEquals(Arrays.asList(request.getBody().getInput().getCommonHeader().getSubRequestId()),
                         oper.getExpectedKeyValues(50, request));
     }