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/dmaap-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/dmaap-client/src')
4 files changed, 43 insertions, 27 deletions
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java index 43a0b4cc..b2a37249 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java @@ -20,15 +20,10 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; -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; -import java.net.URI; -import java.util.UUID; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; -import org.onap.dcaegen2.services.sdk.rest.services.model.ConsumerDmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.slf4j.MDC; @@ -40,6 +35,13 @@ import org.springframework.web.client.RestTemplate; import org.springframework.web.util.DefaultUriBuilderFactory; import reactor.core.publisher.Mono; +import java.net.URI; +import java.util.UUID; + +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; + /** * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18 @@ -53,6 +55,7 @@ public class DMaaPPublisherReactiveHttpClient { private final String dmaapTopicName; private final String dmaapContentType; private final Mono<RestTemplate> restTemplateMono; + private final JsonBodyBuilder jsonBodyBuilder; /** * Constructor DMaaPPublisherReactiveHttpClient. @@ -60,25 +63,26 @@ public class DMaaPPublisherReactiveHttpClient { * @param dmaapPublisherConfiguration - DMaaP producer configuration object */ DMaaPPublisherReactiveHttpClient(DmaapPublisherConfiguration dmaapPublisherConfiguration, - Mono<RestTemplate> restTemplateMono) { + Mono<RestTemplate> restTemplateMono, JsonBodyBuilder jsonBodyBuilder) { this.dmaapHostName = dmaapPublisherConfiguration.dmaapHostName(); this.dmaapProtocol = dmaapPublisherConfiguration.dmaapProtocol(); this.dmaapPortNumber = dmaapPublisherConfiguration.dmaapPortNumber(); this.dmaapTopicName = dmaapPublisherConfiguration.dmaapTopicName(); this.dmaapContentType = dmaapPublisherConfiguration.dmaapContentType(); this.restTemplateMono = restTemplateMono; + this.jsonBodyBuilder = jsonBodyBuilder; } /** * Function for calling DMaaP HTTP producer - post request to DMaaP. * - * @param consumerDmaapModelMono - object which will be sent to DMaaP + * @param dmaapModel - object which will be sent to DMaaP * @return status code of operation */ - public Mono<ResponseEntity<String>> getDMaaPProducerResponse(ConsumerDmaapModel consumerDmaapModelMono) { + public Mono<ResponseEntity<String>> getDMaaPProducerResponse(DmaapModel dmaapModel) { return Mono.defer(() -> { - HttpEntity<String> request = new HttpEntity<>(createJsonBody(consumerDmaapModelMono), getAllHeaders()); + HttpEntity<String> request = new HttpEntity<>(jsonBodyBuilder.createJsonBody(dmaapModel), getAllHeaders()); logger.info("Request: {} {}", getUri(), request); return restTemplateMono.map( restTemplate -> restTemplate.exchange(getUri(), HttpMethod.POST, request, String.class)); diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java index e5f3e19e..ff574f46 100644 --- a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java +++ b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java @@ -21,19 +21,22 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; public class PublisherReactiveHttpClientFactory { private final DmaaPRestTemplateFactory restTemplateFactory; - public PublisherReactiveHttpClientFactory(DmaaPRestTemplateFactory restTemplateFactory) { + private final JsonBodyBuilder jsonBodyBuilder; + + public PublisherReactiveHttpClientFactory(DmaaPRestTemplateFactory restTemplateFactory, JsonBodyBuilder jsonBodyBuilder) { this.restTemplateFactory = restTemplateFactory; + this.jsonBodyBuilder = jsonBodyBuilder; } public DMaaPPublisherReactiveHttpClient create(DmaapPublisherConfiguration publisherConfiguration) { return new DMaaPPublisherReactiveHttpClient(publisherConfiguration, - restTemplateFactory.build(publisherConfiguration)); + restTemplateFactory.build(publisherConfiguration), jsonBodyBuilder); } - } diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java index ac743266..c84ca7d2 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java @@ -30,8 +30,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.dmaap.client.config.DmaapPublisherConfiguration; -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.DmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; @@ -47,15 +48,13 @@ import reactor.test.StepVerifier; class DMaaPPublisherReactiveHttpClientTest { private DMaaPPublisherReactiveHttpClient dmaapPublisherReactiveHttpClient; - private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock( - DmaapPublisherConfiguration.class); - private ConsumerDmaapModel consumerDmaapModel = ImmutableConsumerDmaapModel.builder() - .correlationId("NOKnhfsadhff") - .ipv4("256.22.33.155") - .ipv6("200J:0db8:85a3:0000:0000:8a2e:0370:7334") - .build(); + private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class); + private RestTemplate restTemplate = mock(RestTemplate.class); + private DmaapModel dmaapModel = mock(DmaapModel.class); + private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class); + @BeforeEach void setUp() { @@ -66,9 +65,14 @@ class DMaaPPublisherReactiveHttpClientTest { when(dmaapPublisherConfigurationMock.dmaapUserPassword()).thenReturn("PRH"); when(dmaapPublisherConfigurationMock.dmaapContentType()).thenReturn("application/json"); when(dmaapPublisherConfigurationMock.dmaapTopicName()).thenReturn("unauthenticated.PNF_READY"); - dmaapPublisherReactiveHttpClient = - new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, Mono.just(restTemplate)); + when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn( + "{\"correlationId\":\"NOKnhfsadhff\"," + + "\"ipaddress-v4\":\"256.22.33.155\", " + + "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}"); + + dmaapPublisherReactiveHttpClient = + new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, Mono.just(restTemplate),jsonBodyBuilder); } @Test @@ -82,7 +86,7 @@ class DMaaPPublisherReactiveHttpClientTest { .exchange(any(URI.class), any(HttpMethod.class), any(HttpEntity.class), (Class<Object>) any()); //then - StepVerifier.create(dmaapPublisherReactiveHttpClient.getDMaaPProducerResponse(consumerDmaapModel)) + StepVerifier.create(dmaapPublisherReactiveHttpClient.getDMaaPProducerResponse(dmaapModel)) .expectSubscription().expectNext(mockedResponseEntity).verifyComplete(); } diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java index faed10d9..07b35673 100644 --- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java +++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java @@ -25,14 +25,19 @@ import static org.mockito.Mockito.mock; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration; +import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel; +import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder; class PublisherReactiveHttpClientFactoryTest { private DmaaPRestTemplateFactory restTemplateFactory = mock(DmaaPRestTemplateFactory.class); private DmaapPublisherConfiguration dmaapPublisherConfiguration = mock(DmaapPublisherConfiguration.class); + private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class); + + private PublisherReactiveHttpClientFactory httpClientFactory = - new PublisherReactiveHttpClientFactory(restTemplateFactory); + new PublisherReactiveHttpClientFactory(restTemplateFactory, jsonBodyBuilder); @Test void create_shouldReturnNotNullFactoryInstance() { |