summaryrefslogtreecommitdiffstats
path: root/prh-dmaap-client/src
diff options
context:
space:
mode:
authorwasala <przemyslaw.wasala@nokia.com>2018-05-08 13:48:44 +0200
committerwasala <przemyslaw.wasala@nokia.com>2018-05-09 14:20:35 +0200
commit44ce56cf2e6bfae17c443901ac6ded8ba8cdd414 (patch)
treed2700e58cff23035f8f489ef7579ecee04ef3cc6 /prh-dmaap-client/src
parent7e7aa0c165665f74b628ba5c95fb3cdae72f4449 (diff)
Added dmaap consumer task execution to workflow
Change-Id: I67904a8ffb7d401fa2188fb046e28474eded4377 Issue-ID: DCAEGEN2-474 Signed-off-by: wasala <przemyslaw.wasala@nokia.com>
Diffstat (limited to 'prh-dmaap-client/src')
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java1
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java23
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/DmaapPublisherRequestDetails.java4
-rw-r--r--prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImpl.java30
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java6
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/producer/ExtendedDmaapProducerHttpClientImplTest.java12
6 files changed, 31 insertions, 45 deletions
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java
index 525e1326..ac26ea97 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/config/DmaapPublisherConfiguration.java
@@ -26,7 +26,6 @@ import org.springframework.stereotype.Component;
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 3/23/18
*/
-@Component
@Value.Immutable(prehash = true)
@Value.Style(builder = "new")
@Gson.TypeAdapters
diff --git a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java
index 0b76ccaa..1772104a 100644
--- a/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java
+++ b/prh-dmaap-client/src/main/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImpl.java
@@ -53,7 +53,7 @@ public class ExtendedDmaapConsumerHttpClientImpl {
private final String dmaapContentType;
- ExtendedDmaapConsumerHttpClientImpl(DmaapConsumerConfiguration configuration) {
+ public ExtendedDmaapConsumerHttpClientImpl(DmaapConsumerConfiguration configuration) {
this.closeableHttpClient = new DmaapHttpClientImpl(configuration).getHttpClient();
this.dmaapHostName = configuration.dmaapHostName();
this.dmaapProtocol = configuration.dmaapProtocol();
@@ -108,38 +108,31 @@ public class ExtendedDmaapConsumerHttpClientImpl {
}
private URI createDmaapConsumerExtendedURI() {
- URI extendedURI = null;
-
- final URIBuilder uriBuilder = new URIBuilder()
+ try {
+ return new URIBuilder()
.setScheme(dmaapProtocol)
.setHost(dmaapHostName)
.setPort(dmaapPortNumber)
- .setPath(createRequestPath());
-
- try {
- extendedURI = uriBuilder.build();
- logger.info("Building extended URI: {}", extendedURI);
+ .setPath(createRequestPath()).build();
} catch (URISyntaxException e) {
- logger.error("Exception while building extended URI: {}", e);
+ throw new RuntimeException("Exception while building extended URI: {}", e);
}
-
- return extendedURI;
}
private ResponseHandler<Optional<String>> dmaapConsumerResponseHandler() {
- return httpResponse -> {
+ return httpResponse -> {
final int responseCode = httpResponse.getStatusLine().getStatusCode();
logger.info("Status code of operation: {}", responseCode);
final HttpEntity responseEntity = httpResponse.getEntity();
- if (HttpUtils.isSuccessfulResponseCode(responseCode) ) {
+ if (HttpUtils.isSuccessfulResponseCode(responseCode)) {
logger.info("HTTP response successful.");
final String dmaapResponse = EntityUtils.toString(responseEntity);
return Optional.of(dmaapResponse);
} else {
String dmaapResponse = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
logger.error("HTTP response not successful : {}", dmaapResponse);
- return Optional.of("" + responseCode);
+ return Optional.of(String.valueOf(responseCode));
}
};
}
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
index 6541fe96..a0877feb 100644
--- 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
@@ -28,11 +28,9 @@ import java.util.Optional;
@Value.Style(builder = "new")
public abstract class DmaapPublisherRequestDetails {
- private static final long serialVersionUID = 1L;
-
@Value.Parameter
public abstract String dmaapAPIPath();
@Value.Parameter
- public abstract Optional<String> jsonBody();
+ 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 17e34ed0..af7534c6 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
@@ -52,7 +52,7 @@ public class ExtendedDmaapProducerHttpClientImpl {
private final String dmaapContentType;
- ExtendedDmaapProducerHttpClientImpl(DmaapPublisherConfiguration configuration) {
+ public ExtendedDmaapProducerHttpClientImpl(DmaapPublisherConfiguration configuration) {
this.closeableHttpClient = new DmaapHttpClientImpl(configuration).getHttpClient();
this.dmaapHostName = configuration.dmaapHostName();
this.dmaapProtocol = configuration.dmaapProtocol();
@@ -61,7 +61,7 @@ public class ExtendedDmaapProducerHttpClientImpl {
this.dmaapContentType = configuration.dmaapContentType();
}
- Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) {
+ public Optional<String> getHttpProducerResponse(DmaapPublisherRequestDetails requestDetails) {
Optional<String> extendedDetails = Optional.empty();
Optional<HttpRequestBase> request = createRequest(requestDetails);
@@ -74,11 +74,7 @@ public class ExtendedDmaapProducerHttpClientImpl {
return extendedDetails;
}
-
- private Boolean isExtendedURINotNull(URI extendedURI) {
- return extendedURI != null;
- }
-
+
private Optional<StringEntity> createStringEntity(Optional<String> jsonBody) {
return Optional.of(parseJson(jsonBody).get());
}
@@ -95,7 +91,7 @@ public class ExtendedDmaapProducerHttpClientImpl {
return stringEntity;
}
- private Optional<HttpRequestBase> createRequest (DmaapPublisherRequestDetails requestDetails) {
+ private Optional<HttpRequestBase> createRequest(DmaapPublisherRequestDetails requestDetails) {
Optional<HttpRequestBase> request = Optional.empty();
final URI extendedURI = createDmaapPublisherExtendedURI(requestDetails);
@@ -112,24 +108,24 @@ public class ExtendedDmaapProducerHttpClientImpl {
URI extendedURI = null;
final URIBuilder uriBuilder = new URIBuilder()
- .setScheme(dmaapProtocol)
- .setHost(dmaapHostName)
- .setPort(dmaapPortNumber)
- .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName);
+ .setScheme(dmaapProtocol)
+ .setHost(dmaapHostName)
+ .setPort(dmaapPortNumber)
+ .setPath(requestDetails.dmaapAPIPath() + "/" + dmaapTopicName);
try {
extendedURI = uriBuilder.build();
- logger.info("Building extended URI: {}",extendedURI);
+ logger.info("Building extended URI: {}", extendedURI);
} catch (URISyntaxException e) {
- logger.error("Exception while building extended URI: {}", e);
+ logger.error("Exception while building extended URI: ", e);
}
return extendedURI;
}
private HttpRequestBase createRequest(URI extendedURI, DmaapPublisherRequestDetails requestDetails) {
- if (isExtendedURINotNull(extendedURI) && requestDetails.jsonBody().isPresent()) {
- return createHttpPost(extendedURI, requestDetails.jsonBody());
+ if (extendedURI != null) {
+ return createHttpPost(extendedURI, Optional.ofNullable(requestDetails.jsonBody()));
} else {
return null;
}
@@ -143,7 +139,7 @@ public class ExtendedDmaapProducerHttpClientImpl {
}
private ResponseHandler<Optional<String>> dmaapProducerResponseHandler() {
- return httpResponse -> {
+ return httpResponse -> {
final int responseCode = httpResponse.getStatusLine().getStatusCode();
final HttpEntity responseEntity = httpResponse.getEntity();
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java
index 21d3e4c2..1df025ca 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/service/consumer/ExtendedDmaapConsumerHttpClientImplTest.java
@@ -57,9 +57,9 @@ public class ExtendedDmaapConsumerHttpClientImplTest {
when(configurationMock.dmaapUserName()).thenReturn("PRH");
when(configurationMock.dmaapUserPassword()).thenReturn("PRH");
when(configurationMock.dmaapContentType()).thenReturn("application/json");
- when(configurationMock.dmaapTopicName()).thenReturn("pnfReady");
- when(configurationMock.consumerGroup()).thenReturn("consumerGroup");
- when(configurationMock.consumerId()).thenReturn("consumerId");
+ when(configurationMock.dmaapTopicName()).thenReturn("unauthenticated.SEC_OTHER_OUTPUT");
+ when(configurationMock.consumerGroup()).thenReturn("OpenDCAE-c12");
+ when(configurationMock.consumerId()).thenReturn("c12");
objectUnderTest = new ExtendedDmaapConsumerHttpClientImpl(configurationMock);
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 0560432b..3f64fd5f 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
@@ -62,7 +62,7 @@ public class ExtendedDmaapProducerHttpClientImplTest {
when(configurationMock.dmaapTopicName()).thenReturn("pnfReady");
when(requestDetailsMock.dmaapAPIPath()).thenReturn("events");
- when(requestDetailsMock.jsonBody()).thenReturn(Optional.of(JSON_MESSAGE));
+ when(requestDetailsMock.jsonBody()).thenReturn(JSON_MESSAGE);
objectUnderTest = new ExtendedDmaapProducerHttpClientImpl(configurationMock);
@@ -75,7 +75,7 @@ public class ExtendedDmaapProducerHttpClientImplTest {
expectedResult = Optional.of(RESPONSE_SUCCESS);
when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class)))
- .thenReturn(expectedResult);
+ .thenReturn(expectedResult);
Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(requestDetailsMock);
@@ -85,10 +85,10 @@ public class ExtendedDmaapProducerHttpClientImplTest {
@Test
public void getExtendedDetails_returnsFailure() throws IOException {
expectedResult = Optional.of(RESPONSE_FAILURE);
- when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class))).
- thenReturn(Optional.empty());
- Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(requestDetailsMock);
- Assertions.assertEquals(Optional.empty(),actualResult);
+ when(closeableHttpClientMock.execute(any(HttpPost.class), any(ResponseHandler.class)))
+ .thenReturn(Optional.empty());
+ Optional<String> actualResult = objectUnderTest.getHttpProducerResponse(requestDetailsMock);
+ Assertions.assertEquals(Optional.empty(), actualResult);
}