aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.test
diff options
context:
space:
mode:
Diffstat (limited to 'models-interactions/model-actors/actor.test')
-rw-r--r--models-interactions/model-actors/actor.test/pom.xml5
-rw-r--r--models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java25
-rw-r--r--models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java27
3 files changed, 54 insertions, 3 deletions
diff --git a/models-interactions/model-actors/actor.test/pom.xml b/models-interactions/model-actors/actor.test/pom.xml
index 6b0580748..3a10fa3d1 100644
--- a/models-interactions/model-actors/actor.test/pom.xml
+++ b/models-interactions/model-actors/actor.test/pom.xml
@@ -56,6 +56,11 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.onap.policy.common</groupId>
+ <artifactId>utils-test</artifactId>
+ <version>${policy.common.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito2</artifactId>
<scope>compile</scope>
diff --git a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java
index 15e4848c6..e160479b3 100644
--- a/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java
+++ b/models-interactions/model-actors/actor.test/src/main/java/org/onap/policy/controlloop/actor/test/BasicHttpOperation.java
@@ -33,8 +33,10 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import org.mockito.stubbing.Answer;
import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
+import org.onap.policy.common.utils.time.PseudoExecutor;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
@@ -89,6 +91,7 @@ public class BasicHttpOperation<Q> {
protected VirtualControlLoopEvent event;
protected ControlLoopEventContext context;
protected OperationOutcome outcome;
+ protected PseudoExecutor executor;
/**
* Constructs the object using a default actor and operation name.
@@ -122,6 +125,8 @@ public class BasicHttpOperation<Q> {
future = new CompletableFuture<>();
when(client.getBaseUrl()).thenReturn(BASE_URI);
+ executor = new PseudoExecutor();
+
makeContext();
outcome = params.makeOutcome();
@@ -132,6 +137,8 @@ public class BasicHttpOperation<Q> {
/**
* Reinitializes {@link #enrichment}, {@link #event}, {@link #context}, and
* {@link #params}.
+ * <p/>
+ * Note: {@link #params} is configured to use {@link #executor}.
*/
protected void makeContext() {
enrichment = new TreeMap<>(makeEnrichment());
@@ -142,8 +149,8 @@ public class BasicHttpOperation<Q> {
context = new ControlLoopEventContext(event);
- params = ControlLoopOperationParams.builder().context(context).actorService(service).actor(actorName)
- .operation(operationName).targetEntity(TARGET_ENTITY).build();
+ params = ControlLoopOperationParams.builder().executor(executor).context(context).actorService(service)
+ .actor(actorName).operation(operationName).targetEntity(TARGET_ENTITY).build();
}
/**
@@ -166,4 +173,18 @@ public class BasicHttpOperation<Q> {
protected Map<String, String> makeEnrichment() {
return new TreeMap<>();
}
+
+ /**
+ * Provides a response to an asynchronous HttpClient call.
+ *
+ * @param response response to be provided to the call
+ * @return a function that provides the response to the call
+ */
+ protected Answer<CompletableFuture<Response>> provideResponse(Response response) {
+ return args -> {
+ InvocationCallback<Response> cb = args.getArgument(0);
+ cb.completed(response);
+ return CompletableFuture.completedFuture(response);
+ };
+ }
}
diff --git a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java
index c33483d26..096b8b80d 100644
--- a/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java
+++ b/models-interactions/model-actors/actor.test/src/test/java/org/onap/policy/controlloop/actor/test/BasicHttpOperationTest.java
@@ -24,7 +24,11 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+import javax.ws.rs.client.InvocationCallback;
+import javax.ws.rs.core.Response;
import org.junit.Before;
import org.junit.Test;
@@ -55,7 +59,7 @@ public class BasicHttpOperationTest {
}
@Test
- public void testSetUp() {
+ public void testSetUp() throws Exception {
assertNotNull(oper.client);
assertSame(oper.client, oper.factory.get(BasicHttpOperation.MY_CLIENT));
assertEquals(200, oper.rawResponse.getStatus());
@@ -63,6 +67,7 @@ public class BasicHttpOperationTest {
assertEquals(BasicHttpOperation.BASE_URI, oper.client.getBaseUrl());
assertNotNull(oper.context);
assertNotNull(oper.outcome);
+ assertNotNull(oper.executor);
assertTrue(oper.operator.isAlive());
}
@@ -79,6 +84,7 @@ public class BasicHttpOperationTest {
assertSame(oper.context, oper.params.getContext());
assertSame(oper.service, oper.params.getActorService());
+ assertSame(oper.executor, oper.params.getExecutor());
assertEquals(ACTOR, oper.params.getActor());
assertEquals(OPERATION, oper.params.getOperation());
assertEquals(BasicHttpOperation.TARGET_ENTITY, oper.params.getTargetEntity());
@@ -101,4 +107,23 @@ public class BasicHttpOperationTest {
assertTrue(oper.makeEnrichment().isEmpty());
}
+ @Test
+ public void testProvideResponse() throws Exception {
+ InvocationCallback<Response> cb = new InvocationCallback<>() {
+ @Override
+ public void completed(Response response) {
+ // do nothing
+ }
+
+ @Override
+ public void failed(Throwable throwable) {
+ // do nothing
+ }
+ };
+
+
+ when(oper.client.get(any(), any(), any())).thenAnswer(oper.provideResponse(oper.rawResponse));
+
+ assertSame(oper.rawResponse, oper.client.get(cb, null, null).get());
+ }
}