From 61a84fecc1eae8640fec2860f4b50102ed0baa64 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Fri, 27 Mar 2020 12:35:23 -0400 Subject: Test new actors against simulators 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 --- .../actor/aai/AaiCustomQueryOperationTest.java | 37 ++++++++++++++++- .../controlloop/actor/aai/AaiGetOperationTest.java | 47 +++++++++++++++++++++- .../controlloop/actor/aai/BasicAaiOperation.java | 20 +++++++++ 3 files changed, 101 insertions(+), 3 deletions(-) (limited to 'models-interactions/model-actors/actor.aai/src') diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java index dae443593..cf19ef65d 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java @@ -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>> entityCaptor; @@ -76,6 +81,16 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation future2) diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java index b0420456e..9a288192f 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiGetOperationTest.java @@ -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 { - private static final String INPUT_FIELD = "input"; private static final String TEXT = "my-text"; @@ -50,6 +54,16 @@ public class AaiGetOperationTest extends BasicAaiOperation { 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 { 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 diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java index 00485c935..2715bfe29 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/BasicAaiOperation.java @@ -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 extends BasicHttpOperation { 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 headers) { assertEquals("POLICY", headers.get("X-FromAppId").toString()); assertEquals(params.getRequestId().toString(), headers.get("X-TransactionId")); -- cgit 1.2.3-korg