aboutsummaryrefslogtreecommitdiffstats
path: root/prh-aai-client/src/test/java
diff options
context:
space:
mode:
authorpwielebs <piotr.wielebski@nokia.com>2018-09-04 09:29:49 +0200
committerpwielebs <piotr.wielebski@nokia.com>2018-09-04 09:29:49 +0200
commit83df6e1df5ec20627c85af9ba2f49036dd58f328 (patch)
treede9282995bc4c7b0d0f277760b1d6f3574970794 /prh-aai-client/src/test/java
parent3c2766d8a64d21f402b5234e33419a8aed14d7ea (diff)
Refatoring due to prh workflow
1. Added specified HttpClient for DmaaPPublisher: *DmaaP Handle transfer-encoding: chunk header and reject the request if it will be set by the client. In conclusion no other reactive http client can be used for pushing something to dmaap. 2. Added sll support to A&AI rective webclient. *Behaviour of reactive A&AI HttpClient is different as in native spring have without it. 3. Added 10s fixed time in PRH for requesting DmaaP. 4. Added debug log in reactive/native http clients. 5. Fixed reactive workflow of prh. 6. Updated the version of: * spring-boot-dependencies:2.0.1.RELEASE->2.0.4.RELEASE * spring-boot-starter-reactor-netty:2.0.2.RELEASE->2.0.4.RELEASE * spring-webflux:5.0.5.RELEASE->5.0.8.RELEASE * reactor-bom:Bismuth-RELEASE->Bismuth-SR10 Change-Id: I815ffb5bdcf48d94f3b7c64040a73e98e404a5e8 Issue-ID: DCAEGEN2-743 Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'prh-aai-client/src/test/java')
-rw-r--r--prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java66
1 files changed, 38 insertions, 28 deletions
diff --git a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java
index 9b0f4fe8..4160f356 100644
--- a/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java
+++ b/prh-aai-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/AaiProducerReactiveHttpClientTest.java
@@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.prh.service.producer;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
@@ -31,18 +32,19 @@ import java.net.URI;
import java.net.URISyntaxException;
import java.util.HashMap;
import java.util.Map;
+
import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.prh.config.AaiClientConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest;
+import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
-
class AaiProducerReactiveHttpClientTest {
private static final Integer SUCCESS_RESPONSE = 200;
@@ -50,16 +52,21 @@ class AaiProducerReactiveHttpClientTest {
private static AaiClientConfiguration aaiConfigurationMock = mock(AaiClientConfiguration.class);
private static WebClient webClient = mock(WebClient.class);
- private static ConsumerDmaapModel dmaapModel = new ConsumerDmaapModelForUnitTest();
- private static WebClient.RequestBodyUriSpec requestBodyUriSpec;
- private static ResponseSpec responseSpec;
- private static Map<String, String> aaiHeaders;
+ private ConsumerDmaapModel dmaapModel = spy(new ConsumerDmaapModelForUnitTest());
+ private WebClient.RequestBodyUriSpec requestBodyUriSpec;
+ private ResponseSpec responseSpec;
- @BeforeAll
- static void setUp() {
- setupHeaders();
+ private Map<String, String> aaiHeaders;
+ private ClientResponse clientResponse;
+ private Mono<ClientResponse> clientResponseMono;
+ @BeforeEach
+ void setUp() {
+ setupHeaders();
+ clientResponse = mock(ClientResponse.class);
+ clientResponseMono = Mono.just(clientResponse);
+ when(dmaapModel.getSourceName()).thenReturn("NOKnhfsadhff");
when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2");
when(aaiConfigurationMock.aaiProtocol()).thenReturn("https");
when(aaiConfigurationMock.aaiPort()).thenReturn(1234);
@@ -80,15 +87,6 @@ class AaiProducerReactiveHttpClientTest {
responseSpec = mock(ResponseSpec.class);
}
- private static void setupHeaders() {
- aaiHeaders = new HashMap<>();
- aaiHeaders.put("X-FromAppId", "PRH");
- aaiHeaders.put("X-TransactionId", "vv-temp");
- aaiHeaders.put("Accept", "application/json");
- aaiHeaders.put("Real-Time", "true");
- aaiHeaders.put("Content-Type", "application/merge-patch+json");
- }
-
@Test
void getAaiProducerResponse_shouldReturn200() {
//given
@@ -98,12 +96,11 @@ class AaiProducerReactiveHttpClientTest {
mockWebClientDependantObject();
doReturn(expectedResult).when(responseSpec).bodyToMono(Integer.class);
aaiProducerReactiveHttpClient.createAaiWebClient(webClient);
- Mono<Integer> response = aaiProducerReactiveHttpClient.getAaiProducerResponse(Mono.just(dmaapModel));
//then
- StepVerifier.create(response).expectSubscription()
+ StepVerifier.create(aaiProducerReactiveHttpClient.getAaiProducerResponse(dmaapModel)).expectSubscription()
.expectNextMatches(results -> {
- Assertions.assertEquals(results, expectedResult.block());
+ Assertions.assertEquals(results, clientResponse);
return true;
}).verifyComplete();
}
@@ -115,24 +112,37 @@ class AaiProducerReactiveHttpClientTest {
//when
when(webClient.patch()).thenReturn(requestBodyUriSpec);
aaiProducerReactiveHttpClient.createAaiWebClient(webClient);
- when(aaiProducerReactiveHttpClient.getUri("pnfName")).thenThrow(URISyntaxException.class);
-
+ doThrow(URISyntaxException.class).when(aaiProducerReactiveHttpClient).getUri(any());
//then
StepVerifier.create(
aaiProducerReactiveHttpClient.getAaiProducerResponse(
- Mono.just(dmaapModel)
+ dmaapModel
)).expectSubscription().expectError(Exception.class).verify();
}
+ @Test
+ void getAppropriateUri_whenPassingCorrectedPathForPnf() throws URISyntaxException {
+ Assertions.assertEquals(aaiProducerReactiveHttpClient.getUri("NOKnhfsadhff"),
+ URI.create("https://54.45.33.2:1234/aai/v11/network/pnfs/pnf/NOKnhfsadhff"));
+ }
+
+
+ private void setupHeaders() {
+ aaiHeaders = new HashMap<>();
+ aaiHeaders.put("X-FromAppId", "PRH");
+ aaiHeaders.put("X-TransactionId", "vv-temp");
+ aaiHeaders.put("Accept", "application/json");
+ aaiHeaders.put("Real-Time", "true");
+ aaiHeaders.put("Content-Type", "application/merge-patch+json");
+ }
+
private void mockWebClientDependantObject() {
WebClient.RequestHeadersSpec requestHeadersSpec = mock(WebClient.RequestHeadersSpec.class);
when(webClient.patch()).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.uri((URI) any())).thenReturn(requestBodyUriSpec);
when(requestBodyUriSpec.header(any(), any())).thenReturn(requestBodyUriSpec);
- when(requestBodyUriSpec.body(any())).thenReturn(requestHeadersSpec);
- doReturn(responseSpec).when(requestHeadersSpec).retrieve();
- doReturn(responseSpec).when(responseSpec).onStatus(any(), any());
+ when(requestBodyUriSpec.body(any(), (Class<Object>) any())).thenReturn(requestHeadersSpec);
+ when(requestHeadersSpec.exchange()).thenReturn(clientResponseMono);
}
-
}