diff options
Diffstat (limited to 'rest-services')
16 files changed, 139 insertions, 97 deletions
diff --git a/rest-services/aai-client/pom.xml b/rest-services/aai-client/pom.xml index b69781e3..5492e0a3 100644 --- a/rest-services/aai-client/pom.xml +++ b/rest-services/aai-client/pom.xml @@ -7,13 +7,13 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>aai-client</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-aai-client</name> <description>Active and Available Inventory Rest Services Module</description> @@ -23,7 +23,7 @@ <dependency> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>common-dependency</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework</groupId> 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 diff --git a/rest-services/cbs-client/pom.xml b/rest-services/cbs-client/pom.xml index 052c614d..c6484ff5 100644 --- a/rest-services/cbs-client/pom.xml +++ b/rest-services/cbs-client/pom.xml @@ -7,13 +7,13 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>cbs-client</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-cbs-client</name> <description>Config Binding Service Rest Services Module</description> diff --git a/rest-services/common-dependency/pom.xml b/rest-services/common-dependency/pom.xml index f2d6b450..39cac5da 100644 --- a/rest-services/common-dependency/pom.xml +++ b/rest-services/common-dependency/pom.xml @@ -8,13 +8,13 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>common-dependency</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-common-dependency</name> <description>Common functionality in the project</description> diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ConsumerDmaapModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiModel.java index 1bf9ff62..781aabee 100644 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ConsumerDmaapModel.java +++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/AaiModel.java @@ -20,24 +20,8 @@ package org.onap.dcaegen2.services.sdk.rest.services.model; -import com.google.gson.annotations.SerializedName; -import org.immutables.gson.Gson; -import org.immutables.value.Value; +@FunctionalInterface +public interface AaiModel extends ClientModel { -/** - * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 5/8/18 - */ - -@Value.Immutable -@Gson.TypeAdapters(fieldNamingStrategy = true) -public interface ConsumerDmaapModel { - - @SerializedName(value = "correlationId", alternate = "correlationId") String getCorrelationId(); - - @SerializedName(value = "ipaddress-v4-oam", alternate = "ipaddress-v4-oam") - String getIpv4(); - - @SerializedName(value = "ipaddress-v6-oam", alternate = "ipaddress-v6-oam") - String getIpv6(); } diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ClientModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ClientModel.java new file mode 100644 index 00000000..f94985be --- /dev/null +++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/ClientModel.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.model; + +public interface ClientModel { +} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/DmaapModel.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/DmaapModel.java new file mode 100644 index 00000000..6c5731d8 --- /dev/null +++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/DmaapModel.java @@ -0,0 +1,24 @@ +/* + * ============LICENSE_START======================================================= + * DCAEGEN2-SERVICES-SDK + * ================================================================================ + * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.dcaegen2.services.sdk.rest.services.model; + +public interface DmaapModel extends ClientModel { +} diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/CommonFunctions.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/JsonBodyBuilder.java index 55b12e0a..e33f914f 100644 --- a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/CommonFunctions.java +++ b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/model/JsonBodyBuilder.java @@ -20,27 +20,15 @@ package org.onap.dcaegen2.services.sdk.rest.services.model; -import com.google.gson.GsonBuilder; -import com.google.gson.TypeAdapterFactory; - -import java.util.ServiceLoader; - - -public class CommonFunctions { - - private CommonFunctions() { - } +@FunctionalInterface +public interface JsonBodyBuilder<T extends ClientModel> { /** * Method for serialization object by GSON. * - * @param consumerDmaapModel - object which will be serialized + * @param t - object which will be serialized * @return string from serialization */ - public static String createJsonBody(ConsumerDmaapModel consumerDmaapModel) { - GsonBuilder gsonBuilder = new GsonBuilder(); - ServiceLoader.load(TypeAdapterFactory.class).forEach(gsonBuilder::registerTypeAdapterFactory); - return gsonBuilder.create().toJson(ImmutableConsumerDmaapModel.builder().ipv4(consumerDmaapModel.getIpv4()) - .ipv6(consumerDmaapModel.getIpv6()).correlationId(consumerDmaapModel.getCorrelationId()).build()); - } + + String createJsonBody(T t); }
\ No newline at end of file diff --git a/rest-services/dmaap-client/pom.xml b/rest-services/dmaap-client/pom.xml index 295d1d31..e34dfa17 100644 --- a/rest-services/dmaap-client/pom.xml +++ b/rest-services/dmaap-client/pom.xml @@ -7,13 +7,13 @@ <parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>dmaap-client</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services-dmaap-client</name> <description>DMaaP Rest Services Module</description> @@ -23,7 +23,7 @@ <dependency> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>common-dependency</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> </dependency> <dependency> <groupId>org.springframework</groupId> @@ -68,7 +68,7 @@ <dependency> <groupId>org.onap.dcaegen2.services.sdk.rest.services</groupId> <artifactId>aai-client</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <scope>test</scope> </dependency> </dependencies> 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() { diff --git a/rest-services/pom.xml b/rest-services/pom.xml index a363dc82..101e4f92 100644 --- a/rest-services/pom.xml +++ b/rest-services/pom.xml @@ -7,13 +7,13 @@ <parent> <groupId>org.onap.dcaegen2.services</groupId> <artifactId>sdk</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <relativePath>../pom.xml</relativePath> </parent> <groupId>org.onap.dcaegen2.services.sdk</groupId> <artifactId>dcaegen2-services-sdk-rest-services</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.1.0-SNAPSHOT</version> <name>dcaegen2-services-sdk-rest-services</name> <description>Common SDK repo for all DCAE Services (R4)</description> |