diff options
author | Jim Hahn <jrh3@att.com> | 2020-03-27 12:35:23 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-03-30 09:01:15 -0400 |
commit | 61a84fecc1eae8640fec2860f4b50102ed0baa64 (patch) | |
tree | 32ba4cf68bd9f6c4f97e92f665ab2de7ad788dc6 /models-interactions/model-actors/actor.aai/src | |
parent | 3a374cbc9f4bef8856c3e78be1a6b4c5274cd744 (diff) |
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 <jrh3@att.com>
Diffstat (limited to 'models-interactions/model-actors/actor.aai/src')
3 files changed, 101 insertions, 3 deletions
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<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) 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<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 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<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")); |