diff options
author | pwielebs <piotr.wielebski@nokia.com> | 2018-12-12 16:36:04 +0100 |
---|---|---|
committer | pwielebs <piotr.wielebski@nokia.com> | 2018-12-14 10:41:14 +0100 |
commit | 336d71e343dff06a4270bb1b724dc488498d10b2 (patch) | |
tree | 0215532a2048153ee9b02cf272d676250a442a87 /rest-services/aai-client/src | |
parent | 2cf4d3c25895df964e3767ebd78ad75f1bb74619 (diff) |
Add abstraction level for other components
* vesrion in poms updated to 1.1.0-SNAPSHOT
Change-Id: Ieaa0a8ead1a9a74206fe4bdee85944d11b96c843
Issue-ID: DCAEGEN2-986
Signed-off-by: pwielebs <piotr.wielebski@nokia.com>
Diffstat (limited to 'rest-services/aai-client/src')
3 files changed, 28 insertions, 22 deletions
diff --git a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java index 8b231a44..fa1248df 100644 --- a/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java +++ b/rest-services/aai-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClient.java @@ -22,7 +22,8 @@ package org.onap.dcaegen2.services.sdk.rest.services.aai.client.service.http.pat import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; import org.slf4j.MDC; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; @@ -33,7 +34,6 @@ import java.net.URI; import java.util.UUID; -import static org.onap.dcaegen2.services.sdk.rest.services.model.CommonFunctions.createJsonBody; import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.REQUEST_ID; import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_INVOCATION_ID; import static org.onap.dcaegen2.services.sdk.rest.services.model.logging.MdcVariables.X_ONAP_REQUEST_ID; @@ -48,27 +48,30 @@ public class AaiReactiveHttpPatchClient { private final String aaiBasePath; private final String aaiPnfPath; + private final JsonBodyBuilder jsonBodyBuilder; + /** * Constructor of AaiProducerReactiveHttpClient. * * @param configuration - AAI producer configuration object */ - public AaiReactiveHttpPatchClient(AaiClientConfiguration configuration) { + public AaiReactiveHttpPatchClient(AaiClientConfiguration configuration, JsonBodyBuilder jsonBodyBuilder) { this.aaiHost = configuration.aaiHost(); this.aaiProtocol = configuration.aaiProtocol(); this.aaiHostPortNumber = configuration.aaiPort(); this.aaiBasePath = configuration.aaiBasePath(); this.aaiPnfPath = configuration.aaiPnfPath(); + this.jsonBodyBuilder = jsonBodyBuilder; } /** * Function for calling AAI Http producer - patch request to AAI database. * - * @param consumerDmaapModelMono - object which will be sent to AAI database + * @param aaiModel - object which will be sent to AAI database * @return status code of operation */ - public Mono<ClientResponse> getAaiProducerResponse(ConsumerDmaapModel consumerDmaapModelMono) { - return patchAaiRequest(consumerDmaapModelMono); + public Mono<ClientResponse> getAaiProducerResponse(AaiModel aaiModel) { + return patchAaiRequest(aaiModel); } public AaiReactiveHttpPatchClient createAaiWebClient(WebClient webClient) { @@ -76,13 +79,13 @@ public class AaiReactiveHttpPatchClient { return this; } - private Mono<ClientResponse> patchAaiRequest(ConsumerDmaapModel dmaapModel) { + private Mono<ClientResponse> patchAaiRequest(AaiModel aaiModel) { return webClient.patch() - .uri(getUri(dmaapModel.getCorrelationId())) + .uri(getUri(aaiModel.getCorrelationId())) .header(X_ONAP_REQUEST_ID, MDC.get(REQUEST_ID)) .header(X_INVOCATION_ID, UUID.randomUUID().toString()) - .body(Mono.just(createJsonBody(dmaapModel)), String.class) + .body(Mono.just(jsonBodyBuilder.createJsonBody(aaiModel)), String.class) .exchange(); } diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java index c7323160..153189fd 100644 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/AaiReactiveWebClientFactoryTest.java @@ -33,7 +33,6 @@ import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory; import javax.net.ssl.SSLException; - class AaiReactiveWebClientFactoryTest { private static final String TRUST_STORE_PATH = "trust_store_path"; diff --git a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java index f3b4c5ff..7e34256f 100644 --- a/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java +++ b/rest-services/aai-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/aai/client/service/http/patch/AaiReactiveHttpPatchClientTest.java @@ -24,8 +24,9 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.aai.client.config.AaiClientConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.sdk.rest.services.model.ImmutableConsumerDmaapModel; + +import org.onap.dcaegen2.services.sdk.rest.services.model.AaiModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; import org.springframework.web.reactive.function.client.ClientResponse; import org.springframework.web.reactive.function.client.WebClient; import reactor.core.publisher.Mono; @@ -50,7 +51,6 @@ class AaiReactiveHttpPatchClientTest { private AaiReactiveHttpPatchClient httpClient; private WebClient webClient; - private ConsumerDmaapModel dmaapModel; private WebClient.RequestBodyUriSpec requestBodyUriSpec; private WebClient.ResponseSpec responseSpec; @@ -58,18 +58,15 @@ class AaiReactiveHttpPatchClientTest { private ClientResponse clientResponse; private Mono<ClientResponse> clientResponseMono; + private AaiModel aaiModel = mock(AaiModel.class); + private JsonBodyBuilder<AaiModel> jsonBodyBuilder = mock(JsonBodyBuilder.class); + @BeforeEach void setUp() { setupHeaders(); clientResponse = mock(ClientResponse.class); clientResponseMono = Mono.just(clientResponse); - dmaapModel = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .ipv4("256.22.33.155") - .ipv6("200J:0db8:85a3:0000:0000:8a2e:0370:7334") - .build(); - when(aaiConfigurationMock.aaiHost()).thenReturn("54.45.33.2"); when(aaiConfigurationMock.aaiProtocol()).thenReturn("https"); when(aaiConfigurationMock.aaiPort()).thenReturn(1234); @@ -79,7 +76,14 @@ class AaiReactiveHttpPatchClientTest { when(aaiConfigurationMock.aaiPnfPath()).thenReturn("/network/pnfs/pnf"); when(aaiConfigurationMock.aaiHeaders()).thenReturn(aaiHeaders); - httpClient = new AaiReactiveHttpPatchClient(aaiConfigurationMock); + when(aaiModel.getCorrelationId()).thenReturn("NOKnhfsadhff"); + + when(jsonBodyBuilder.createJsonBody(aaiModel)).thenReturn( + "{\"correlationId\":\"NOKnhfsadhff\"," + + "\"ipaddress-v4\":\"256.22.33.155\", " + + "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}"); + + httpClient = new AaiReactiveHttpPatchClient(aaiConfigurationMock, jsonBodyBuilder); webClient = spy(WebClient.builder() .defaultHeaders(httpHeaders -> httpHeaders.setAll(aaiHeaders)) @@ -101,7 +105,7 @@ class AaiReactiveHttpPatchClientTest { httpClient.createAaiWebClient(webClient); //then - StepVerifier.create(httpClient.getAaiProducerResponse(dmaapModel)).expectSubscription() + StepVerifier.create(httpClient.getAaiProducerResponse(aaiModel)).expectSubscription() .expectNextMatches(results -> { Assertions.assertEquals(results, clientResponse); return true; @@ -133,4 +137,4 @@ class AaiReactiveHttpPatchClientTest { when(requestBodyUriSpec.body(any(), (Class<Object>) any())).thenReturn(requestHeadersSpec); when(requestHeadersSpec.exchange()).thenReturn(clientResponseMono); } -} +}
\ No newline at end of file |