aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java14
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java13
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java13
-rw-r--r--prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java12
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java49
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java2
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java3
7 files changed, 83 insertions, 23 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java
index 6db36a8a..8df564d2 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTask.java
@@ -19,10 +19,12 @@
*/
package org.onap.dcaegen2.services.prh.tasks;
-import java.util.Optional;
+import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient;
+import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
/**
@@ -36,5 +38,15 @@ abstract class DmaapConsumerTask {
abstract void initConfigs();
+ protected abstract DmaapConsumerConfiguration resolveConfiguration();
+
protected abstract Mono<ConsumerDmaapModel> execute(String object) throws PrhTaskException;
+
+ WebClient buildWebClient() {
+ DmaapConsumerConfiguration dmaapConsumerConfiguration = resolveConfiguration();
+ return new DMaaPReactiveWebClient.WebClientBuilder()
+ .dmaapContentType(dmaapConsumerConfiguration.dmaapContentType())
+ .dmaapUserName(dmaapConsumerConfiguration.dmaapUserName())
+ .dmaapUserPassword(dmaapConsumerConfiguration.dmaapUserPassword()).build();
+ }
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
index 90382e51..8c74bac3 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImpl.java
@@ -24,7 +24,6 @@ import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.DmaapConsumerJsonParser;
import org.onap.dcaegen2.services.prh.service.consumer.DMaaPConsumerReactiveHttpClient;
import org.slf4j.Logger;
@@ -73,21 +72,15 @@ public class DmaapConsumerTaskImpl extends DmaapConsumerTask {
prhAppConfig.initFileStreamReader();
}
+ @Override
protected DmaapConsumerConfiguration resolveConfiguration() {
return prhAppConfig.getDmaapConsumerConfiguration();
}
@Override
DMaaPConsumerReactiveHttpClient resolveClient() {
-
return Optional.ofNullable(dMaaPConsumerReactiveHttpClient)
- .orElseGet(() -> {
- DmaapConsumerConfiguration dmaapConsumerConfiguration = resolveConfiguration();
- return new DMaaPConsumerReactiveHttpClient(dmaapConsumerConfiguration).createDMaaPWebClient(
- new DMaaPReactiveWebClient.WebClientBuilder()
- .dmaapContentType(dmaapConsumerConfiguration.dmaapContentType())
- .dmaapUserName(dmaapConsumerConfiguration.dmaapUserName())
- .dmaapUserPassword(dmaapConsumerConfiguration.dmaapUserPassword()).build());
- });
+ .orElseGet(() -> new DMaaPConsumerReactiveHttpClient(resolveConfiguration()).createDMaaPWebClient(
+ buildWebClient()));
}
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java
index 27670e29..af8d14a3 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTask.java
@@ -19,9 +19,12 @@
*/
package org.onap.dcaegen2.services.prh.tasks;
+import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
+import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.producer.DMaaPProducerReactiveHttpClient;
+import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
/**
@@ -33,5 +36,15 @@ abstract class DmaapPublisherTask {
abstract DMaaPProducerReactiveHttpClient resolveClient();
+ protected abstract DmaapPublisherConfiguration resolveConfiguration();
+
protected abstract Mono<Integer> execute(Mono<ConsumerDmaapModel> consumerDmaapModel) throws PrhTaskException;
+
+ WebClient buildWebClient() {
+ DmaapPublisherConfiguration dmaapPublisherConfiguration = resolveConfiguration();
+ return new DMaaPReactiveWebClient.WebClientBuilder()
+ .dmaapContentType(dmaapPublisherConfiguration.dmaapContentType())
+ .dmaapUserName(dmaapPublisherConfiguration.dmaapUserName())
+ .dmaapUserPassword(dmaapPublisherConfiguration.dmaapUserPassword()).build();
+ }
}
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java
index faf43bc7..11281d81 100644
--- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java
+++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImpl.java
@@ -25,7 +25,6 @@ import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.configuration.Config;
import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.DMaaPReactiveWebClient;
import org.onap.dcaegen2.services.prh.service.producer.DMaaPProducerReactiveHttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -64,6 +63,7 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask {
return publish(consumerDmaapModel);
}
+ @Override
protected DmaapPublisherConfiguration resolveConfiguration() {
return prhAppConfig.getDmaapPublisherConfiguration();
}
@@ -71,13 +71,7 @@ public class DmaapPublisherTaskImpl extends DmaapPublisherTask {
@Override
DMaaPProducerReactiveHttpClient resolveClient() {
return Optional.ofNullable(dMaaPProducerReactiveHttpClient)
- .orElseGet(() -> {
- DmaapPublisherConfiguration dmaapPublisherConfiguration = resolveConfiguration();
- return new DMaaPProducerReactiveHttpClient(dmaapPublisherConfiguration).createDMaaPWebClient(
- new DMaaPReactiveWebClient.WebClientBuilder()
- .dmaapContentType(dmaapPublisherConfiguration.dmaapContentType())
- .dmaapUserName(dmaapPublisherConfiguration.dmaapUserName())
- .dmaapUserPassword(dmaapPublisherConfiguration.dmaapUserPassword()).build());
- });
+ .orElseGet(() -> new DMaaPProducerReactiveHttpClient(resolveConfiguration())
+ .createDMaaPWebClient(buildWebClient()));
}
} \ No newline at end of file
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java
new file mode 100644
index 00000000..fad18699
--- /dev/null
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java
@@ -0,0 +1,49 @@
+/*
+ * ============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.prh.service;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.springframework.web.reactive.function.client.WebClient;
+
+/**
+ * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/5/18
+ */
+public class DMaaPReactiveWebClientTest {
+
+ @Test
+ public void builder_shouldBuildDMaaPReactiveWebClient() {
+ //given
+ WebClient dMaaPReactiveWebClient;
+ String dMaaPContentType = "*/*";
+ String dMaaPUserName = "DMaaP";
+ String dMaaPUserPassword = "DMaaP";
+
+ //when
+ dMaaPReactiveWebClient = new DMaaPReactiveWebClient.WebClientBuilder()
+ .dmaapContentType(dMaaPContentType)
+ .dmaapUserName(dMaaPUserName)
+ .dmaapUserPassword(dMaaPUserPassword).build();
+
+ //then
+ Assertions.assertNotNull(dMaaPReactiveWebClient);
+
+ }
+} \ No newline at end of file
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java
index dc8f7b6e..96939771 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/config/DmaapConsumerConfigurationTest.java
@@ -1,4 +1,4 @@
-/*-
+/*
* ============LICENSE_START=======================================================
* PNF-REGISTRATION-HANDLER
* ================================================================================
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java
index c0b0c40b..f1fb70b0 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java
@@ -55,7 +55,6 @@ public class DMaaPProducerReactiveHttpClientTest {
DmaapPublisherConfiguration.class);
private static final Integer RESPONSE_SUCCESS = 200;
private static ConsumerDmaapModel consumerDmaapModel = new ConsumerDmaapModelForUnitTest();
- private static Mono<Integer> expectedResult = Mono.empty();
private static WebClient webClient = mock(WebClient.class);
private static RequestBodyUriSpec requestBodyUriSpec;
private static ResponseSpec responseSpec;
@@ -85,7 +84,7 @@ public class DMaaPProducerReactiveHttpClientTest {
@Test
public void getHttpResponse_Success() {
//given
- expectedResult = Mono.just(RESPONSE_SUCCESS);
+ Mono<Integer> expectedResult = Mono.just(RESPONSE_SUCCESS);
//when
mockWebClientDependantObject();