summaryrefslogtreecommitdiffstats
path: root/rest-services/dmaap-client/src
diff options
context:
space:
mode:
Diffstat (limited to 'rest-services/dmaap-client/src')
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClient.java26
-rw-r--r--rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java9
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java28
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java7
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() {