Test new actors against simulators 17/104617/4
authorJim Hahn <jrh3@att.com>
Fri, 27 Mar 2020 16:35:23 +0000 (12:35 -0400)
committerJim Hahn <jrh3@att.com>
Mon, 30 Mar 2020 13:01:15 +0000 (09:01 -0400)
Also modified HttpParams to allow "path" to be blank to support any
cases that really have no "path" to append to the context URI base
path.

Issue-ID: POLICY-2405
Change-Id: I49eebde6759659d2804b5a11c1504c37674bd0c4
Signed-off-by: Jim Hahn <jrh3@att.com>
34 files changed:
models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java
models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java
models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java
models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java
models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/BasicAppcOperation.java
models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java
models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java
models-interactions/model-actors/actor.guard/pom.xml
models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java
models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java
models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java
models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java
models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java
models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BasicSdncOperation.java
models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java
models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/BasicSdnrOperation.java
models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperationTest.java
models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/BasicSoOperation.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleCreateTest.java
models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/VfModuleDeleteTest.java
models-interactions/model-actors/actor.test/pom.xml
models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperation.java
models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicOperation.java
models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicBidirectionalTopicOperationTest.java
models-interactions/model-actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/Restart.java
models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/BasicVfcOperation.java
models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/RestartTest.java
models-interactions/model-actors/actor.vfc/src/test/java/org/onap/policy/controlloop/actor/vfc/VfcOperationTest.java
models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParams.java
models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/parameters/HttpParamsTest.java
models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AppcLcmTopicServer.java
models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/AppcLegacyTopicServer.java
models-interactions/model-simulators/src/main/java/org/onap/policy/simulators/SdnrTopicServer.java

index dae4435..cf19ef6 100644 (file)
@@ -39,7 +39,9 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeoutException;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.InvocationCallback;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Captor;
@@ -47,6 +49,7 @@ import org.mockito.Mock;
 import org.onap.policy.aai.AaiConstants;
 import org.onap.policy.aai.AaiCqResponse;
 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.coder.StandardCoderObject;
 import org.onap.policy.controlloop.actorserviceprovider.Operation;
@@ -54,6 +57,7 @@ import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.Util;
 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
 import org.onap.policy.controlloop.policy.PolicyResult;
@@ -62,7 +66,8 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
     private static final StandardCoder coder = new StandardCoder();
 
     private static final String MY_LINK = "my-link";
-    private static final String MY_VSERVER = "my-verserver-name";
+    private static final String MY_VSERVER = "my-vserver-name";
+    private static final String SIM_VSERVER = "OzVServer";
 
     @Captor
     private ArgumentCaptor<Entity<Map<String, String>>> entityCaptor;
@@ -76,6 +81,16 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
         super(AaiConstants.ACTOR_NAME, AaiCustomQueryOperation.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * Sets up.
      */
@@ -93,8 +108,25 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
         oper = new AaiCustomQueryOperation(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/query").build();
+        config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        preloadTenantData();
+
+        params = params.toBuilder().targetEntity(SIM_VSERVER).retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        oper = new AaiCustomQueryOperation(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
-    public void testAaiCustomQueryOperation() {
+    public void testConstructor() {
         assertEquals(AaiConstants.ACTOR_NAME, oper.getActorName());
         assertEquals(AaiCustomQueryOperation.NAME, oper.getName());
         assertEquals(MY_VSERVER, oper.getVserver());
@@ -215,6 +247,7 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation<Map<String, S
 
     private void preloadTenantData(StandardCoderObject data) {
         context.setProperty(AaiGetOperation.getTenantKey(MY_VSERVER), data);
+        context.setProperty(AaiGetOperation.getTenantKey(SIM_VSERVER), data);
     }
 
     private PolicyResult getResult(CompletableFuture<OperationOutcome> future2)
index b042045..9a28819 100644 (file)
@@ -31,16 +31,20 @@ import static org.mockito.Mockito.when;
 import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import javax.ws.rs.client.InvocationCallback;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.onap.policy.aai.AaiConstants;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.coder.StandardCoderObject;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
 import org.onap.policy.controlloop.policy.PolicyResult;
 
 public class AaiGetOperationTest extends BasicAaiOperation<Void> {
-
     private static final String INPUT_FIELD = "input";
     private static final String TEXT = "my-text";
 
@@ -50,6 +54,16 @@ public class AaiGetOperationTest extends BasicAaiOperation<Void> {
         super(AaiConstants.ACTOR_NAME, AaiGetOperation.TENANT);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * Sets up.
      */
@@ -59,6 +73,37 @@ public class AaiGetOperationTest extends BasicAaiOperation<Void> {
         oper = new AaiGetOperation(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build();
+        config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().targetEntity("OzVServer").retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        oper = new AaiGetOperation(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
+    /**
+     * Tests "failure" case with simulator.
+     */
+    @Test
+    public void testFailure() throws Exception {
+        HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT).path("v16/search/nodes-query").build();
+        config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().targetEntity("failedVserver").retry(0).timeoutSec(5).executor(blockingExecutor)
+                        .build();
+        oper = new AaiGetOperation(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.FAILURE, outcome.getResult());
+    }
+
     @Test
     public void testGetRetry() {
         // use default if null retry
index 00485c9..2715bfe 100644 (file)
@@ -23,7 +23,11 @@ package org.onap.policy.controlloop.actor.aai;
 import static org.junit.Assert.assertEquals;
 
 import java.util.Map;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
+import org.onap.policy.simulators.Util;
 
 /**
  * Superclass for various operator tests.
@@ -47,6 +51,22 @@ public abstract class BasicAaiOperation<Q> extends BasicHttpOperation<Q> {
         super(actor, operation);
     }
 
+    /**
+     * Starts the simulator.
+     */
+    protected static void initBeforeClass() throws Exception {
+        Util.buildAaiSim();
+
+        BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("aai/")
+                        .hostname("localhost").managed(true).port(Util.AAISIM_SERVER_PORT).build();
+        HttpClientFactoryInstance.getClientFactory().build(clientParams);
+    }
+
+    protected static void destroyAfterClass() {
+        HttpClientFactoryInstance.getClientFactory().destroy();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+    }
+
     protected void verifyHeaders(Map<String, Object> headers) {
         assertEquals("POLICY", headers.get("X-FromAppId").toString());
         assertEquals(params.getRequestId().toString(), headers.get("X-TransactionId"));
index 30450d0..7f7ac7a 100644 (file)
@@ -30,7 +30,10 @@ import java.util.Arrays;
 import java.util.Map;
 import java.util.TreeMap;
 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.appc.CommonHeader;
 import org.onap.policy.appc.Request;
@@ -42,10 +45,22 @@ import org.onap.policy.controlloop.policy.PolicyResult;
 public class AppcOperationTest extends BasicAppcOperation {
     private AppcOperation oper;
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        // use same topic name for both sides
+        initBeforeClass(MY_SINK, MY_SINK);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * Sets up.
      */
     @Before
+    @Override
     public void setUp() throws Exception {
         super.setUp();
 
@@ -57,8 +72,14 @@ public class AppcOperationTest extends BasicAppcOperation {
         };
     }
 
+    @After
+    @Override
+    public void tearDown() {
+        super.tearDown();
+    }
+
     @Test
-    public void testAppcOperation() {
+    public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
         assertEquals(DEFAULT_OPERATION, oper.getName());
     }
index 06ad166..546a38d 100644 (file)
@@ -35,6 +35,8 @@ import java.util.function.BiConsumer;
 import org.onap.policy.appc.Response;
 import org.onap.policy.appc.ResponseCode;
 import org.onap.policy.appc.ResponseStatus;
+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.StandardCoderInstantAsMillis;
 import org.onap.policy.common.utils.coder.StandardCoderObject;
 import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
@@ -44,6 +46,8 @@ import org.onap.policy.controlloop.actorserviceprovider.impl.OperationMaker;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.simulators.AppcLegacyTopicServer;
+import org.onap.policy.simulators.TopicServer;
 import org.powermock.reflect.Whitebox;
 
 /**
@@ -94,6 +98,15 @@ public abstract class BasicAppcOperation extends BasicBidirectionalTopicOperatio
         status.setDescription(MY_DESCRIPTION);
     }
 
+    public void tearDown() {
+        super.tearDownBasic();
+    }
+
+    @SuppressWarnings("rawtypes")
+    protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+        return new AppcLegacyTopicServer(sink, source);
+    }
+
     /**
      * Runs the operation and verifies that the response is successful.
      *
index 95629bc..743896c 100644 (file)
@@ -35,7 +35,10 @@ import java.util.Arrays;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.atomic.AtomicBoolean;
 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.aai.domain.yang.GenericVnf;
 import org.onap.policy.aai.AaiCqResponse;
@@ -43,6 +46,8 @@ import org.onap.policy.appc.Request;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
 import org.onap.policy.controlloop.policy.PolicyResult;
 
 public class ModifyConfigOperationTest extends BasicAppcOperation {
@@ -53,14 +58,61 @@ public class ModifyConfigOperationTest extends BasicAppcOperation {
         super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        // use same topic name for both sides
+        initBeforeClass(MY_SINK, MY_SINK);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     @Before
+    @Override
     public void setUp() throws Exception {
         super.setUp();
         oper = new ModifyConfigOperation(params, config);
     }
 
+    @After
+    @Override
+    public void tearDown() {
+        super.tearDown();
+    }
+
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        BidirectionalTopicParams opParams =
+                        BidirectionalTopicParams.builder().sinkTopic(MY_SINK).sourceTopic(MY_SINK).build();
+        config = new BidirectionalTopicConfig(blockingExecutor, opParams, topicMgr, AppcOperation.SELECTOR_KEYS);
+
+        AaiCqResponse cq = mock(AaiCqResponse.class);
+        GenericVnf genvnf = mock(GenericVnf.class);
+        when(genvnf.getVnfId()).thenReturn(MY_VNF);
+        when(cq.getGenericVnfByModelInvariantId(any())).thenReturn(genvnf);
+
+        params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, cq);
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+        oper = new ModifyConfigOperation(params, config) {
+            @Override
+            protected CompletableFuture<OperationOutcome> startGuardAsync() {
+                return null;
+            }
+        };
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
-    public void testModifyConfigOperation() {
+    public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
         assertEquals(ModifyConfigOperation.NAME, oper.getName());
     }
index 8e6a603..9744d82 100644 (file)
@@ -37,13 +37,18 @@ 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;
@@ -52,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 {
 
@@ -68,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.
      */
@@ -80,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());
index 99e6164..dc40561 100644 (file)
             <version>${project.version}</version>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.models.policy-models-interactions</groupId>
+            <artifactId>simulators</artifactId>
+            <version>${project.version}</version>
+            <scope>test</scope>
+        </dependency>
         <dependency>
             <groupId>org.powermock</groupId>
             <artifactId>powermock-api-mockito2</artifactId>
index 13a2411..3d15383 100644 (file)
@@ -35,9 +35,14 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.concurrent.CompletableFuture;
 import java.util.function.Consumer;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -45,6 +50,7 @@ import org.onap.policy.controlloop.actorserviceprovider.Util;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.models.decisions.concepts.DecisionRequest;
 import org.onap.policy.models.decisions.concepts.DecisionResponse;
+import org.onap.policy.simulators.GuardSimulatorJaxRs;
 
 public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> {
 
@@ -56,6 +62,25 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> {
     private GuardConfig guardConfig;
     private GuardOperation oper;
 
+    /**
+     * Starts the simulator.
+     */
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        org.onap.policy.simulators.Util.buildGuardSim();
+
+        BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("policy/pdpx/v1/")
+                        .hostname("localhost").managed(true).port(org.onap.policy.simulators.Util.GUARDSIM_SERVER_PORT)
+                        .build();
+        HttpClientFactoryInstance.getClientFactory().build(clientParams);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        HttpClientFactoryInstance.getClientFactory().destroy();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+    }
+
     /**
      * Sets up.
      */
@@ -81,6 +106,37 @@ public class GuardOperationTest extends BasicHttpOperation<DecisionRequest> {
         oper = new GuardOperation(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        GuardParams opParams = GuardParams.builder().clientName(MY_CLIENT).path("decision").build();
+        config = new GuardConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        oper = new GuardOperation(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
+    /**
+     * Tests "failure" case with simulator.
+     */
+    @Test
+    public void testFailure() throws Exception {
+        GuardParams opParams = GuardParams.builder().clientName(MY_CLIENT).path("decision").build();
+        config = new GuardConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor)
+                        .payload(Map.of("clname", GuardSimulatorJaxRs.DENY_CLNAME)).build();
+        oper = new GuardOperation(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.FAILURE, outcome.getResult());
+    }
+
     @Test
     public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
index ff18813..daced6e 100644 (file)
@@ -39,8 +39,6 @@ import org.onap.policy.sdnc.SdncRequest;
 public class BandwidthOnDemandOperation extends SdncOperation {
     public static final String NAME = "BandwidthOnDemand";
 
-    public static final String URI = "/GENERIC-RESOURCE-API:vf-module-topology-operation";
-
     // fields in the enrichment data
     public static final String SERVICE_ID_KEY = "service-instance.service-instance-id";
     public static final String VNF_ID = "vnfId";
@@ -92,7 +90,7 @@ public class BandwidthOnDemandOperation extends SdncOperation {
         SdncRequest request = new SdncRequest();
         request.setNsInstanceId(serviceInstance);
         request.setRequestId(context.getRequestId());
-        request.setUrl(URI);
+        request.setUrl("/" + getPath());
 
         SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo();
         vnfInfo.setVnfId(context.getEnrichment().get(VNF_ID));
index 753da1b..2e0d7b8 100644 (file)
@@ -35,8 +35,6 @@ import org.onap.policy.sdnc.SdncRequest;
 public class RerouteOperation extends SdncOperation {
     public static final String NAME = "Reroute";
 
-    public static final String URI = "/GENERIC-RESOURCE-API:network-topology-operation";
-
     // fields in the enrichment data
     public static final String SERVICE_ID_KEY = "service-instance.service-instance-id";
     public static final String NETWORK_ID_KEY = "network-information.network-id";
@@ -79,7 +77,7 @@ public class RerouteOperation extends SdncOperation {
         SdncRequest request = new SdncRequest();
         request.setNsInstanceId(serviceInstance);
         request.setRequestId(context.getRequestId());
-        request.setUrl(URI);
+        request.setUrl("/" + getPath());
 
         SdncHealRequest healRequest = new SdncHealRequest();
         healRequest.setRequestHeaderInfo(headerInfo);
index 1aed75c..0c05582 100644 (file)
@@ -68,7 +68,7 @@ public abstract class SdncOperation extends HttpOperation<SdncResponse> {
         Map<String, Object> headers = makeHeaders();
 
         headers.put("Accept", MediaType.APPLICATION_JSON);
-        String path = getPath() + request.getUrl();
+        String path = getPath();
         String url = getClient().getBaseUrl() + path;
 
         logMessage(EventType.OUT, CommInfrastructure.REST, url, request);
index ade2513..8e26c68 100644 (file)
@@ -24,8 +24,14 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.util.Map;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
+import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.sdnc.SdncRequest;
 
 public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
@@ -36,6 +42,16 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
         super(DEFAULT_ACTOR, BandwidthOnDemandOperation.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * Set up.
      */
@@ -46,17 +62,33 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation {
     }
 
     @Test
-    public void testBandwidthOnDemandOperator() {
+    public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
         assertEquals(BandwidthOnDemandOperation.NAME, oper.getName());
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
+                        .path("GENERIC-RESOURCE-API:vf-module-topology-operation").build();
+        config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        oper = new BandwidthOnDemandOperation(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
     public void testMakeRequest() throws Exception {
         SdncRequest request = oper.makeRequest(1);
         assertEquals("my-service", request.getNsInstanceId());
         assertEquals(REQ_ID, request.getRequestId());
-        assertEquals(BandwidthOnDemandOperation.URI, request.getUrl());
+        assertEquals("/my-path/", request.getUrl());
         assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
 
         verifyRequest("bod.json", request, IGNORE_FIELDS);
index 73b8143..bb1285e 100644 (file)
@@ -33,6 +33,9 @@ import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeoutException;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -42,6 +45,7 @@ import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.sdnc.SdncRequest;
 import org.onap.policy.sdnc.SdncResponse;
 import org.onap.policy.sdnc.SdncResponseOutput;
+import org.onap.policy.simulators.Util;
 import org.powermock.reflect.Whitebox;
 
 /**
@@ -72,6 +76,22 @@ public abstract class BasicSdncOperation extends BasicHttpOperation<SdncRequest>
         super(actor, operation);
     }
 
+    /**
+     * Starts the simulator.
+     */
+    protected static void initBeforeClass() throws Exception {
+        Util.buildSdncSim();
+
+        BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("restconf/operations/")
+                        .hostname("localhost").managed(true).port(Util.SDNCSIM_SERVER_PORT).build();
+        HttpClientFactoryInstance.getClientFactory().build(clientParams);
+    }
+
+    protected static void destroyAfterClass() {
+        HttpClientFactoryInstance.getClientFactory().destroy();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+    }
+
     /**
      * Initializes mocks and sets up.
      */
index 30ddd87..97cdcb0 100644 (file)
@@ -24,8 +24,14 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.util.Map;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
+import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.sdnc.SdncRequest;
 
 public class RerouteOperationTest extends BasicSdncOperation {
@@ -36,6 +42,16 @@ public class RerouteOperationTest extends BasicSdncOperation {
         super(DEFAULT_ACTOR, RerouteOperation.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * Set up.
      */
@@ -45,8 +61,24 @@ public class RerouteOperationTest extends BasicSdncOperation {
         oper = new RerouteOperation(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        HttpParams opParams = HttpParams.builder().clientName(MY_CLIENT)
+                        .path("GENERIC-RESOURCE-API:network-topology-operation").build();
+        config = new HttpConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        oper = new RerouteOperation(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
-    public void testRerouteOperator() {
+    public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
         assertEquals(RerouteOperation.NAME, oper.getName());
     }
@@ -56,7 +88,7 @@ public class RerouteOperationTest extends BasicSdncOperation {
         SdncRequest request = oper.makeRequest(1);
         assertEquals("my-service", request.getNsInstanceId());
         assertEquals(REQ_ID, request.getRequestId());
-        assertEquals(RerouteOperation.URI, request.getUrl());
+        assertEquals("/my-path/", request.getUrl());
         assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId());
 
         verifyRequest("reroute.json", request, IGNORE_FIELDS);
index 27d7d43..15f919b 100644 (file)
@@ -31,6 +31,8 @@ import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeoutException;
 import java.util.function.BiConsumer;
+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.StandardCoderObject;
 import org.onap.policy.controlloop.actor.test.BasicBidirectionalTopicOperation;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -43,6 +45,8 @@ import org.onap.policy.sdnr.PciMessage;
 import org.onap.policy.sdnr.PciResponse;
 import org.onap.policy.sdnr.Status;
 import org.onap.policy.sdnr.util.StatusCodeEnum;
+import org.onap.policy.simulators.SdnrTopicServer;
+import org.onap.policy.simulators.TopicServer;
 import org.powermock.reflect.Whitebox;
 
 public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperation {
@@ -86,6 +90,15 @@ public abstract class BasicSdnrOperation extends BasicBidirectionalTopicOperatio
         status.setValue(StatusCodeEnum.SUCCESS.toString());
     }
 
+    public void tearDown() {
+        super.tearDownBasic();
+    }
+
+    @SuppressWarnings("rawtypes")
+    protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+        return new SdnrTopicServer(sink, source);
+    }
+
     /**
      * Runs the operation and verifies that the response is successful.
      *
index 3165d58..e3e3c99 100644 (file)
@@ -30,11 +30,17 @@ import static org.mockito.Mockito.when;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.atomic.AtomicBoolean;
 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.common.utils.coder.CoderException;
+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.parameters.BidirectionalTopicConfig;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicParams;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.sdnr.PciMessage;
 
@@ -46,15 +52,53 @@ public class ModifyConfigOperationTest extends BasicSdnrOperation {
         super(DEFAULT_ACTOR, ModifyConfigOperation.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     @Before
     public void setUp() throws Exception {
         super.setUp();
         oper = new ModifyConfigOperation(params, config);
     }
 
+    @After
+    @Override
+    public void tearDown() {
+        super.tearDown();
+    }
+
+
+    /**
+     * 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, SdnrOperation.SELECTOR_KEYS);
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+
+        oper = new ModifyConfigOperation(params, config) {
+            @Override
+            protected CompletableFuture<OperationOutcome> startGuardAsync() {
+                return null;
+            }
+        };
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
 
     @Test
-    public void testModifyConfigOperation() {
+    public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
         assertEquals(ModifyConfigOperation.NAME, oper.getName());
     }
index 5f6a5df..8f58f7d 100644 (file)
@@ -27,8 +27,12 @@ import static org.junit.Assert.assertSame;
 
 import java.util.Arrays;
 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.controlloop.actor.test.BasicBidirectionalTopicOperation;
 import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status;
 import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.sdnr.PciCommonHeader;
@@ -39,16 +43,33 @@ public class SdnrOperationTest extends BasicSdnrOperation {
 
     private SdnrOperation operation;
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        BasicBidirectionalTopicOperation.initBeforeClass(MY_SINK, MY_SOURCE);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * Setup.
      */
     @Before
+    @Override
     public void setUp() throws Exception {
         super.setUp();
 
         operation = new SdnrOperation(params, config) {};
     }
 
+    @After
+    @Override
+    public void tearDown() {
+        super.tearDown();
+    }
+
     @Test
     public void testSdnrOperation() {
         assertEquals(DEFAULT_ACTOR, operation.getActorName());
index f33d501..e6a3615 100644 (file)
@@ -30,6 +30,9 @@ import java.util.List;
 import java.util.Map;
 import org.mockito.Mock;
 import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
 import org.onap.policy.controlloop.actorserviceprovider.Util;
 import org.onap.policy.controlloop.policy.Target;
@@ -80,6 +83,23 @@ public abstract class BasicSoOperation extends BasicHttpOperation<SoRequest> {
         super(actor, operation);
     }
 
+    /**
+     * Starts the simulator.
+     */
+    protected static void initBeforeClass() throws Exception {
+        org.onap.policy.simulators.Util.buildSoSim();
+
+        BusTopicParams clientParams =
+                        BusTopicParams.builder().clientName(MY_CLIENT).basePath("").hostname("localhost")
+                                        .managed(true).port(org.onap.policy.simulators.Util.SOSIM_SERVER_PORT).build();
+        HttpClientFactoryInstance.getClientFactory().build(clientParams);
+    }
+
+    protected static void destroyAfterClass() {
+        HttpClientFactoryInstance.getClientFactory().destroy();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+    }
+
     /**
      * Initializes mocks and sets up.
      */
index 1d5d44c..918559a 100644 (file)
@@ -36,7 +36,9 @@ import java.util.concurrent.ForkJoinPool;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.commons.lang3.tuple.Pair;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.onap.aai.domain.yang.CloudRegion;
@@ -45,6 +47,7 @@ import org.onap.aai.domain.yang.ModelVer;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.aai.domain.yang.Tenant;
 import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
@@ -63,6 +66,15 @@ public class VfModuleCreateTest extends BasicSoOperation {
         super(DEFAULT_ACTOR, VfModuleCreate.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
 
     @Before
     public void setUp() throws Exception {
@@ -70,6 +82,22 @@ public class VfModuleCreateTest extends BasicSoOperation {
         oper = new VfModuleCreate(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstantiation/v7/serviceInstances")
+                        .pathGet("orchestrationRequests/v5/").build();
+        config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        oper = new VfModuleCreate(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
     public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
index cb2bcef..16775fe 100644 (file)
@@ -48,7 +48,9 @@ import javax.ws.rs.client.InvocationCallback;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 import org.apache.commons.lang3.tuple.Pair;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
@@ -58,6 +60,7 @@ import org.onap.aai.domain.yang.ModelVer;
 import org.onap.aai.domain.yang.ServiceInstance;
 import org.onap.aai.domain.yang.Tenant;
 import org.onap.policy.aai.AaiCqResponse;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.common.utils.coder.Coder;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
@@ -89,6 +92,15 @@ public class VfModuleDeleteTest extends BasicSoOperation {
         super(DEFAULT_ACTOR, VfModuleDelete.NAME);
     }
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
 
     /**
      * Sets up.
@@ -104,6 +116,22 @@ public class VfModuleDeleteTest extends BasicSoOperation {
         oper = new MyOperation(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        SoParams opParams = SoParams.builder().clientName(MY_CLIENT).path("serviceInstances/v7")
+                        .pathGet("orchestrationRequests/v5/").build();
+        config = new SoConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        oper = new VfModuleDelete(params, config);
+
+        outcome = oper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
     public void testConstructor() {
         assertEquals(DEFAULT_ACTOR, oper.getActorName());
index c67e648..16af025 100644 (file)
             <artifactId>junit</artifactId>
             <scope>provided</scope>
         </dependency>
+        <dependency>
+            <groupId>org.onap.policy.models.policy-models-interactions</groupId>
+            <artifactId>simulators</artifactId>
+            <version>${project.version}</version>
+        </dependency>
         <dependency>
             <groupId>org.onap.policy.common</groupId>
             <artifactId>utils-test</artifactId>
index bba2bc1..c8b6967 100644 (file)
 
 package org.onap.policy.controlloop.actor.test;
 
+import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.when;
 
+import java.util.List;
 import java.util.function.BiConsumer;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Captor;
 import org.mockito.Mock;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
+import org.onap.policy.common.endpoints.event.comm.TopicSink;
+import org.onap.policy.common.endpoints.event.comm.TopicSource;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
+import org.onap.policy.common.endpoints.parameters.TopicParameters;
 import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoderObject;
 import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig;
 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicHandler;
+import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager;
 import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
+import org.onap.policy.simulators.TopicServer;
+import org.onap.policy.simulators.Util;
 
 /**
  * Superclass for various BidirectionalTopicOperation tests.
  */
-public class BasicBidirectionalTopicOperation extends BasicOperation {
+public abstract class BasicBidirectionalTopicOperation extends BasicOperation {
     protected static final String MY_SINK = "my-sink";
     protected static final String MY_SOURCE = "my-source";
     protected static final int TIMEOUT_SEC = 10;
     protected static final long TIMEOUT_MS = 1000L * TIMEOUT_SEC;
 
+    // sink and source used by the TopicServer
+    private static TopicSink serverSink;
+    private static TopicSource serverSource;
+    private static BidirectionalTopicHandler realTopicHandler;
+
+    protected static BidirectionalTopicManager topicMgr = (sink, source) -> {
+        // note: the sink and source names are swapped for the simulator
+        assertEquals(serverSource.getTopic(), sink);
+        assertEquals(serverSink.getTopic(), source);
+        return realTopicHandler;
+    };
+
     @Captor
     protected ArgumentCaptor<BiConsumer<String, StandardCoderObject>> listenerCaptor;
 
@@ -51,6 +74,9 @@ public class BasicBidirectionalTopicOperation extends BasicOperation {
     @Mock
     protected BidirectionalTopicConfig config;
 
+    @SuppressWarnings("rawtypes")
+    private TopicServer topicServer;
+
     /**
      * Constructs the object using a default actor and operation name.
      */
@@ -68,15 +94,76 @@ public class BasicBidirectionalTopicOperation extends BasicOperation {
         super(actor, operation);
     }
 
+    /**
+     * Starts the topic.
+     */
+    protected static void initBeforeClass(String sinkTopic, String sourceTopic) throws Exception {
+
+        Util.buildDmaapSim();
+
+        // note: the sink and source names are swapped for the simulator
+        TopicParameters ptopic = new TopicParameters();
+        ptopic.setTopic(sourceTopic);
+        ptopic.setManaged(true);
+        ptopic.setServers(List.of("localhost"));
+        ptopic.setTopicCommInfrastructure("dmaap");
+        ptopic.setFetchTimeout(500);
+        serverSink = TopicEndpointManager.getManager().addTopicSinks(List.of(ptopic)).get(0);
+
+        ptopic.setTopic(sinkTopic);
+        serverSource = TopicEndpointManager.getManager().addTopicSources(List.of(ptopic)).get(0);
+
+        serverSink.start();
+        serverSource.start();
+
+        if (!sinkTopic.equals(sourceTopic)) {
+            // sink and source are different - create other ends for the actor
+            initActorTopics(sinkTopic, sourceTopic, ptopic);
+        }
+
+        realTopicHandler = new BidirectionalTopicHandler(sinkTopic, sourceTopic);
+        realTopicHandler.start();
+    }
+
+    private static void initActorTopics(String sinkTopic, String sourceTopic, TopicParameters ptopic) {
+        // create sink and source for the actor, too
+        ptopic.setTopic(sinkTopic);
+        TopicEndpointManager.getManager().addTopicSinks(List.of(ptopic)).get(0).start();
+
+        ptopic.setTopic(sourceTopic);
+        TopicEndpointManager.getManager().addTopicSources(List.of(ptopic)).get(0).start();
+    }
+
+    protected static void destroyAfterClass() {
+        TopicEndpointManager.getManager().shutdown();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+        HttpClientFactoryInstance.getClientFactory().destroy();
+    }
+
     /**
      * Initializes mocks and sets up.
      */
     @Override
     public void setUpBasic() {
         super.setUpBasic();
+        topicServer = makeServer(serverSink, serverSource);
         initConfig();
     }
 
+    public void tearDownBasic() {
+        topicServer.shutdown();
+    }
+
+    /**
+     * Makes a simulator for the given sink and source.
+     *
+     * @param sink topic to which the simulator should publish responses
+     * @param source topic from which the simulator should receive messages
+     * @return a new topic server/simulator
+     */
+    @SuppressWarnings("rawtypes")
+    protected abstract TopicServer makeServer(TopicSink sink, TopicSource source);
+
     /**
      * Initializes a configuration.
      */
index d6940d2..3b1871f 100644 (file)
@@ -28,6 +28,7 @@ import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
 import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.Executor;
 import javax.ws.rs.core.Response;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
@@ -59,6 +60,12 @@ public class BasicOperation {
     protected static final String DEFAULT_OPERATION = "default-operation";
     protected static final String TARGET_ENTITY = "my-target";
 
+    protected static final Executor blockingExecutor = command -> {
+        Thread thread = new Thread(command);
+        thread.setDaemon(true);
+        thread.start();
+    };
+
     protected final String actorName;
     protected final String operationName;
     protected Coder coder = new StandardCoder();
index 101f130..afb8f07 100644 (file)
@@ -28,12 +28,18 @@ import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.verify;
 
 import java.util.function.BiConsumer;
+import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
+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.StandardCoderObject;
+import org.onap.policy.simulators.TopicServer;
 
 public class BasicBidirectionalTopicOperationTest {
     private static final String ACTOR = "my-actor";
@@ -44,6 +50,16 @@ public class BasicBidirectionalTopicOperationTest {
 
     private BasicBidirectionalTopicOperation oper;
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        BasicBidirectionalTopicOperation.initBeforeClass(BasicBidirectionalTopicOperation.MY_SINK,
+                        BasicBidirectionalTopicOperation.MY_SOURCE);
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        BasicBidirectionalTopicOperation.destroyAfterClass();
+    }
 
     /**
      * Sets up.
@@ -52,13 +68,28 @@ public class BasicBidirectionalTopicOperationTest {
     public void setUp() throws Exception {
         MockitoAnnotations.initMocks(this);
 
-        oper = new BasicBidirectionalTopicOperation(ACTOR, OPERATION);
+        oper = new MyOperation(ACTOR, OPERATION);
         oper.setUpBasic();
     }
 
+    @After
+    public void tearDown() {
+        oper.tearDownBasic();
+    }
+
+    @Test
+    public void testTopicMgr() {
+        assertNotNull(BasicBidirectionalTopicOperation.topicMgr.getTopicHandler(
+                        BasicBidirectionalTopicOperation.MY_SINK, BasicBidirectionalTopicOperation.MY_SOURCE));
+    }
+
     @Test
     public void testBasicBidirectionalTopicOperation() {
-        oper = new BasicBidirectionalTopicOperation();
+        oper.tearDownBasic();
+
+        oper = new MyOperation();
+        oper.setUpBasic();
+
         assertEquals(BasicOperation.DEFAULT_ACTOR, oper.actorName);
         assertEquals(BasicOperation.DEFAULT_OPERATION, oper.operationName);
     }
@@ -101,4 +132,31 @@ public class BasicBidirectionalTopicOperationTest {
         assertThatIllegalArgumentException().isThrownBy(() -> oper.provideResponse(listener, "{invalid json"))
                         .withMessage("response is not a Map");
     }
+
+    private static class MyOperation extends BasicBidirectionalTopicOperation {
+        public MyOperation() {
+            super();
+        }
+
+        /**
+         * Constructs the object.
+         *
+         * @param actor actor name
+         * @param operation operation name
+         */
+        public MyOperation(String actor, String operation) {
+            super(actor, operation);
+        }
+
+        @Override
+        @SuppressWarnings("rawtypes")
+        protected TopicServer makeServer(TopicSink sink, TopicSource source) {
+            return new TopicServer<String>(sink, source, null, String.class) {
+                @Override
+                protected String process(String request) {
+                    return null;
+                }
+            };
+        }
+    }
 }
index 2c5cf8e..e3df16d 100644 (file)
@@ -20,6 +20,7 @@
 
 package org.onap.policy.controlloop.actor.vfc;
 
+import java.util.Map;
 import java.util.concurrent.CompletableFuture;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.core.MediaType;
@@ -47,7 +48,10 @@ public class Restart extends VfcOperation {
         String path = getPath() + pair.getLeft();
         String url = getClient().getBaseUrl() + path;
 
-        return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, null));
+        Map<String, Object> headers = makeHeaders();
+        headers.put("Accept", MediaType.APPLICATION_JSON);
+
+        return handleResponse(outcome, url, callback -> getClient().post(callback, path, entity, headers));
     }
 
     /**
@@ -58,7 +62,7 @@ public class Restart extends VfcOperation {
     protected Pair<String, VfcRequest> makeRequest() {
 
         VfcRequest request = super.constructVfcRequest();
-        String requestUrl = "/ns/" + request.getNsInstanceId() + "/heal";
+        String requestUrl = "/" + request.getNsInstanceId() + "/heal";
         return Pair.of(requestUrl, request);
     }
 }
index be62bbb..47371d2 100644 (file)
@@ -23,7 +23,11 @@ package org.onap.policy.controlloop.actor.vfc;
 import static org.mockito.Mockito.when;
 
 import org.mockito.Mock;
+import org.onap.policy.common.endpoints.event.comm.bus.internal.BusTopicParams;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.controlloop.actor.test.BasicHttpOperation;
+import org.onap.policy.simulators.Util;
 import org.onap.policy.vfc.VfcRequest;
 import org.onap.policy.vfc.VfcResponse;
 
@@ -54,6 +58,22 @@ public abstract class BasicVfcOperation extends BasicHttpOperation<VfcRequest> {
         super(actor, operation);
     }
 
+    /**
+     * Starts the simulator.
+     */
+    protected static void initBeforeClass() throws Exception {
+        Util.buildVfcSim();
+
+        BusTopicParams clientParams = BusTopicParams.builder().clientName(MY_CLIENT).basePath("api/nslcm/v1/")
+                        .hostname("localhost").managed(true).port(Util.VFCSIM_SERVER_PORT).build();
+        HttpClientFactoryInstance.getClientFactory().build(clientParams);
+    }
+
+    protected static void destroyAfterClass() {
+        HttpClientFactoryInstance.getClientFactory().destroy();
+        HttpServletServerFactoryInstance.getServerFactory().destroy();
+    }
+
     /**
      * Initializes mocks and sets up.
      */
index dd6c4cf..5fe4973 100644 (file)
@@ -25,14 +25,28 @@ import static org.junit.Assert.assertNotNull;
 
 import java.util.concurrent.CompletableFuture;
 import org.apache.commons.lang3.tuple.Pair;
+import org.junit.AfterClass;
 import org.junit.Before;
+import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.policy.PolicyResult;
 import org.onap.policy.vfc.VfcRequest;
 
 public class RestartTest extends BasicVfcOperation {
     private Restart restartOper;
 
+    @BeforeClass
+    public static void setUpBeforeClass() throws Exception {
+        initBeforeClass();
+    }
+
+    @AfterClass
+    public static void tearDownAfterClass() {
+        destroyAfterClass();
+    }
+
     /**
      * setup restart operation.
      */
@@ -45,8 +59,23 @@ public class RestartTest extends BasicVfcOperation {
         restartOper = new Restart(params, config);
     }
 
+    /**
+     * Tests "success" case with simulator.
+     */
+    @Test
+    public void testSuccess() throws Exception {
+        VfcParams opParams = VfcParams.builder().clientName(MY_CLIENT).path("ns").pathGet("jobs").maxGets(1).build();
+        config = new VfcConfig(blockingExecutor, opParams, HttpClientFactoryInstance.getClientFactory());
+
+        params = params.toBuilder().retry(0).timeoutSec(5).executor(blockingExecutor).build();
+        restartOper = new Restart(params, config);
+
+        outcome = restartOper.start().get();
+        assertEquals(PolicyResult.SUCCESS, outcome.getResult());
+    }
+
     @Test
-    public void testStartOperationAsync() {
+    public void testConstructor() {
         CompletableFuture<OperationOutcome> futureRes = restartOper.startOperationAsync(1, outcome);
         assertNotNull(futureRes);
         assertEquals(0, restartOper.getGetCount());
index 4fe0cd4..4d98b97 100644 (file)
@@ -44,8 +44,8 @@ public class VfcOperationTest extends BasicVfcOperation {
     /**
      * setUp.
      */
-    @Override
     @Before
+    @Override
     public void setUp() throws Exception {
         super.setUp();
 
@@ -84,7 +84,7 @@ public class VfcOperationTest extends BasicVfcOperation {
         response.setJobId("sampleJobId");
         CompletableFuture<OperationOutcome> future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
         assertFalse(future2.isDone());
-        //assertSame(outcome, future2.get()); TODO Hanging
+        // assertSame(outcome, future2.get()); TODO Hanging
         assertEquals(PolicyResult.SUCCESS, outcome.getResult());
 
         response.getResponseDescriptor().setStatus("FinisHeD");
@@ -100,11 +100,12 @@ public class VfcOperationTest extends BasicVfcOperation {
         assertEquals(PolicyResult.FAILURE, outcome.getResult());
 
         // failed
-        /*response.getResponseDescriptor().setStatus("anything but finished");
-        future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response);
-        assertTrue(future2.isDone());
-        assertSame(outcome, future2.get());
-        assertEquals(PolicyResult.FAILURE, outcome.getResult());*/
+        /*
+         * response.getResponseDescriptor().setStatus("anything but finished"); future2 =
+         * oper.postProcessResponse(outcome, PATH, rawResponse, response);
+         * assertTrue(future2.isDone()); assertSame(outcome, future2.get());
+         * assertEquals(PolicyResult.FAILURE, outcome.getResult());
+         */
     }
 
     @Test
@@ -115,7 +116,9 @@ public class VfcOperationTest extends BasicVfcOperation {
 
         VfcResponseDescriptor mockDescriptor = Mockito.mock(VfcResponseDescriptor.class);
         Mockito.when(mockResponse.getResponseDescriptor()).thenReturn(mockDescriptor);
-        Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE"); // TODO use actual request state value
+
+        // TODO use actual request state value
+        Mockito.when(mockDescriptor.getStatus()).thenReturn("COMPLETE");
         assertNotNull(oper.getRequestState(mockResponse));
     }
 
index 57270ac..be1f0f8 100644 (file)
@@ -32,7 +32,6 @@ import org.onap.policy.common.parameters.annotations.NotNull;
  * Parameters used by Operators that connect to a server via HTTP.
  */
 @NotNull
-@NotBlank
 @Data
 @SuperBuilder(toBuilder = true)
 public class HttpParams {
@@ -40,6 +39,7 @@ public class HttpParams {
     /**
      * Name of the HttpClient, as found in the HttpClientFactory.
      */
+    @NotBlank
     private String clientName;
 
     /**
index 8d4d446..f4c6a20 100644 (file)
@@ -54,6 +54,10 @@ public class HttpParamsTest {
         testValidateField("timeoutSec", "minimum", bldr -> bldr.timeoutSec(-1));
 
         // check edge cases
+        assertFalse(params.toBuilder().clientName("").build().validate(CONTAINER).isValid());
+
+        assertTrue(params.toBuilder().path("").build().validate(CONTAINER).isValid());
+
         assertFalse(params.toBuilder().timeoutSec(0).build().validate(CONTAINER).isValid());
         assertTrue(params.toBuilder().timeoutSec(1).build().validate(CONTAINER).isValid());
     }
index 6b2eabe..3b0d8cd 100644 (file)
@@ -30,6 +30,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
  * APPC-LCM topic server.
  */
 public class AppcLcmTopicServer extends TopicServer<AppcLcmDmaapWrapper> {
+
     public AppcLcmTopicServer(TopicSink sink, TopicSource source) {
         super(sink, source, new StandardCoder(), AppcLcmDmaapWrapper.class);
     }
index 0c25978..c3f0435 100644 (file)
@@ -30,6 +30,7 @@ import org.onap.policy.common.utils.resources.ResourceUtils;
  * Legacy APPC topic server.
  */
 public class AppcLegacyTopicServer extends TopicServer<Request> {
+
     public AppcLegacyTopicServer(TopicSink sink, TopicSource source) {
         super(sink, source, new StandardCoderInstantAsMillis(), Request.class);
     }
index 043a2c5..9aad4d4 100644 (file)
@@ -30,6 +30,7 @@ import org.onap.policy.sdnr.PciMessage;
  * SDNR topic server.
  */
 public class SdnrTopicServer extends TopicServer<PciMessage> {
+
     public SdnrTopicServer(TopicSink sink, TopicSource source) {
         super(sink, source, new StandardCoder(), PciMessage.class);
     }