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>
diff --git a/models-interactions/model-actors/actor.guard/pom.xml b/models-interactions/model-actors/actor.guard/pom.xml
index 99e6164..dc40561 100644
--- a/models-interactions/model-actors/actor.guard/pom.xml
+++ b/models-interactions/model-actors/actor.guard/pom.xml
@@ -69,6 +69,12 @@
<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>
<scope>test</scope>
diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java
index 13a2411..3d15383 100644
--- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java
+++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java
@@ -35,9 +35,14 @@
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.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> {
@@ -57,6 +63,25 @@
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.
*/
@Before
@@ -81,6 +106,37 @@
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());