summaryrefslogtreecommitdiffstats
path: root/prh-dmaap-client
diff options
context:
space:
mode:
Diffstat (limited to 'prh-dmaap-client')
-rw-r--r--prh-dmaap-client/pom.xml5
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java36
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java29
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java12
4 files changed, 21 insertions, 61 deletions
diff --git a/prh-dmaap-client/pom.xml b/prh-dmaap-client/pom.xml
index ff6a0b30..40d4df91 100644
--- a/prh-dmaap-client/pom.xml
+++ b/prh-dmaap-client/pom.xml
@@ -99,5 +99,10 @@
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.dcaegen2.services.commons</groupId>
+ <artifactId>commons</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
</project> \ No newline at end of file
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java
deleted file mode 100644
index a0877feb..00000000
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * PNF-REGISTRATION-HANDLER
- * ================================================================================
- * 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.service.producer;
-
-import org.immutables.value.Value;
-
-import java.util.Optional;
-
-@Value.Immutable(prehash = true)
-@Value.Style(builder = "new")
-public abstract class DmaapPublisherRequestDetails {
-
- @Value.Parameter
- public abstract String dmaapAPIPath();
-
- @Value.Parameter
- public abstract String jsonBody();
-}
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java
index 98c9a83e..def9dd85 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java
@@ -29,6 +29,8 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.model.CommonFunctions;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.service.DmaapHttpClientImpl;
import org.onap.dcaegen2.services.service.HttpUtils;
import org.slf4j.Logger;
@@ -61,17 +63,14 @@ public class ExtendedDmaapProducerHttpClientImpl {
this.dmaapContentType = configuration.dmaapContentType();
}
- public Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) {
-
+ public Optional<String> getHttpProducerResponse(ConsumerDmaapModel consumerDmaapModel) {
Optional<String> extendedDetails = Optional.empty();
- Optional<HttpRequestBase> request = createRequest(requestDetails);
-
+ Optional<HttpRequestBase> request = createRequest(consumerDmaapModel);
try {
extendedDetails = closeableHttpClient.execute(request.get(), dmaapProducerResponseHandler());
} catch (IOException | NullPointerException e) {
logger.warn("Exception while executing HTTP request: ", e);
}
-
return extendedDetails;
}
@@ -81,51 +80,45 @@ public class ExtendedDmaapProducerHttpClientImpl {
private Optional<StringEntity> parseJson(Optional<String> jsonBody) {
Optional<StringEntity> stringEntity = Optional.empty();
-
try {
stringEntity = Optional.of(new StringEntity(jsonBody.get()));
} catch (UnsupportedEncodingException e) {
logger.warn("Exception while parsing JSON: ", e);
}
-
return stringEntity;
}
- private Optional<HttpRequestBase> createRequest(DmaapPublisherRequestDetails requestDetails) {
-
+ private Optional<HttpRequestBase> createRequest(ConsumerDmaapModel consumerDmaapModel) {
Optional<HttpRequestBase> request = Optional.empty();
- final URI extendedURI = createDmaapPublisherExtendedURI(requestDetails);
+ final URI extendedURI = createDmaapPublisherExtendedURI();
if ("application/json".equals(dmaapContentType)) {
- request = Optional.ofNullable(createRequest(extendedURI, requestDetails));
+ request = Optional.ofNullable(createRequest(extendedURI, consumerDmaapModel));
request.get().addHeader("Content-type", dmaapContentType);
}
return request;
}
- private URI createDmaapPublisherExtendedURI(DmaapPublisherRequestDetails requestDetails) {
+ private URI createDmaapPublisherExtendedURI() {
URI extendedURI = null;
-
final URIBuilder uriBuilder = new URIBuilder()
.setScheme(dmaapProtocol)
.setHost(dmaapHostName)
.setPort(dmaapPortNumber)
- .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName);
-
+ .setPath(dmaapTopicName);
try {
extendedURI = uriBuilder.build();
logger.trace("Building extended URI: {}", extendedURI);
} catch (URISyntaxException e) {
logger.warn("Exception while building extended URI: ", e);
}
-
return extendedURI;
}
- private HttpRequestBase createRequest(URI extendedURI, DmaapPublisherRequestDetails requestDetails) {
+ private HttpRequestBase createRequest(URI extendedURI, ConsumerDmaapModel consumerDmaapModel) {
if (extendedURI != null) {
- return createHttpPost(extendedURI, Optional.ofNullable(requestDetails.jsonBody()));
+ return createHttpPost(extendedURI, Optional.ofNullable(CommonFunctions.createJsonBody(consumerDmaapModel)));
} else {
return null;
}
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java
index 3f64fd5f..6ca815ae 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java
@@ -27,6 +27,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.config.DmaapPublisherConfiguration;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.model.ConsumerDmaapModelForUnitTest;
import java.io.IOException;
import java.lang.reflect.Field;
@@ -43,10 +45,9 @@ public class ExtendedDmaapProducerHttpClientImplTest {
private static DmaapPublisherConfiguration configurationMock = mock(DmaapPublisherConfiguration.class);
private static CloseableHttpClient closeableHttpClientMock = mock(CloseableHttpClient.class);
- private static DmaapPublisherRequestDetails requestDetailsMock = mock(DmaapPublisherRequestDetails.class);
+ private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
private static Optional<String> expectedResult = Optional.empty();
- private static final String JSON_MESSAGE = "{ \"ipaddress-v4-oam\": \"11.22.33.44\" }";
private static final String RESPONSE_SUCCESS = "200";
private static final String RESPONSE_FAILURE = "404";
@@ -61,9 +62,6 @@ public class ExtendedDmaapProducerHttpClientImplTest {
when(configurationMock.dmaapContentType()).thenReturn("application/json");
when(configurationMock.dmaapTopicName()).thenReturn("pnfReady");
- when(requestDetailsMock.dmaapAPIPath()).thenReturn("events");
- when(requestDetailsMock.jsonBody()).thenReturn(JSON_MESSAGE);
-
objectUnderTest = new ExtendedDmaapProducerHttpClientImpl(configurationMock);
setField();
@@ -77,7 +75,7 @@ public class ExtendedDmaapProducerHttpClientImplTest {
when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class)))
.thenReturn(expectedResult);
- Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(requestDetailsMock);
+ Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel);
Assertions.assertEquals(expectedResult.get(), actualResult.get());
}
@@ -87,7 +85,7 @@ public class ExtendedDmaapProducerHttpClientImplTest {
expectedResult = Optional.of(RESPONSE_FAILURE);
when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class)))
.thenReturn(Optional.empty());
- Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(requestDetailsMock);
+ Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(consumerDmaapModel);
Assertions.assertEquals(Optional.empty(), actualResult);
}