From 9bd821d6a2b49dacb7286d58f11d5cd1cc7e0aa2 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Mon, 2 Mar 2020 16:17:36 -0500 Subject: Fix path issues A&AI tenant query is prepending the target entity with "/", but it should not. Fixed it. Modified A&AI and SO actors to get path prefixes from parameters. Fixed a bug in an A&AI simulator response (extra "}" at the end. Issue-ID: POLICY-2349 Signed-off-by: Jim Hahn Change-Id: I71f8b1e5fb8a4bd29b4f616a7757d366c7d58127 --- .../controlloop/actor/test/BasicHttpOperation.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'models-interactions/model-actors/actor.test') 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 e803df8c9..6228756bd 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 @@ -20,12 +20,16 @@ package org.onap.policy.controlloop.actor.test; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.util.Map; import java.util.concurrent.CompletableFuture; +import javax.ws.rs.client.AsyncInvoker; import javax.ws.rs.client.Entity; +import javax.ws.rs.client.Invocation.Builder; import javax.ws.rs.client.InvocationCallback; +import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -55,6 +59,12 @@ public class BasicHttpOperation extends BasicOperation { @Mock protected HttpConfig config; @Mock + protected WebTarget webTarget; + @Mock + protected Builder webBuilder; + @Mock + protected AsyncInvoker webAsync; + @Mock protected HttpClient client; @Mock protected HttpClientFactory factory; @@ -90,6 +100,14 @@ public class BasicHttpOperation extends BasicOperation { when(rawResponse.getStatus()).thenReturn(200); + when(webBuilder.async()).thenReturn(webAsync); + + when(webTarget.request()).thenReturn(webBuilder); + when(webTarget.path(any())).thenReturn(webTarget); + when(webTarget.queryParam(any(), any())).thenReturn(webTarget); + + when(client.getWebTarget()).thenReturn(webTarget); + when(client.getBaseUrl()).thenReturn(BASE_URI); initConfig(); @@ -110,8 +128,19 @@ public class BasicHttpOperation extends BasicOperation { * @return a function that provides the response to the call */ protected Answer> provideResponse(Response response) { + return provideResponse(response, 0); + } + + /** + * Provides a response to an asynchronous HttpClient call. + * + * @param response response to be provided to the call + * @param index index of the callback within the arguments + * @return a function that provides the response to the call + */ + protected Answer> provideResponse(Response response, int index) { return args -> { - InvocationCallback cb = args.getArgument(0); + InvocationCallback cb = args.getArgument(index); cb.completed(response); return CompletableFuture.completedFuture(response); }; -- cgit 1.2.3-korg