aboutsummaryrefslogtreecommitdiffstats
path: root/prh-app-server/src/test/java
diff options
context:
space:
mode:
authorpkaras <piotr.karas@nokia.com>2018-10-26 11:14:13 +0200
committerpkaras <piotr.karas@nokia.com>2018-10-26 11:14:13 +0200
commit600c05b1530c120b34370e86e92dfd79421474fe (patch)
treebf181b2dae941c768d41df18f5e72eb51d3be6cd /prh-app-server/src/test/java
parent361f6112f3316f66f1a20a994db0996975080a25 (diff)
Simplify DmaaP Publisher and consumer interfaces
Change-Id: Iaa7d870e8bd33687047832960c86adb7e97d969c Issue-ID: DCAEGEN2-922 Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'prh-app-server/src/test/java')
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java39
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java1
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java7
-rw-r--r--prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java20
4 files changed, 25 insertions, 42 deletions
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
index 8d6218ee..fe9f6f78 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskImplTest.java
@@ -29,16 +29,14 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.onap.dcaegen2.services.prh.TestAppConfiguration.createDefaultDmaapConsumerConfiguration;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonParser;
import java.util.Optional;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
-import org.mockito.Mockito;
import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
+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 reactor.core.publisher.Flux;
@@ -56,7 +54,6 @@ class DmaapConsumerTaskImplTest {
private static AppConfig appConfig;
private static DmaapConsumerConfiguration dmaapConsumerConfiguration;
private static String message;
- private static String parsed;
@BeforeAll
static void setUp() {
@@ -82,22 +79,6 @@ class DmaapConsumerTaskImplTest {
+ " \"softwareVersion\": \"v4.5.0.1\","
+ " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
+ "}}}]";
-
- parsed = "{\"event\": {"
- + "\"commonEventHeader\": { \"sourceName\":\"NOKQTFCOC540002E\"},"
- + "\"pnfRegistrationFields\": {"
- + " \"unitType\": \"AirScale\","
- + " \"serialNumber\": \"QTFCOC540002E\","
- + " \"pnfRegistrationFieldsVersion\": \"2.0\","
- + " \"manufactureDate\": \"1535014037024\","
- + " \"modelNumber\": \"7BEA\",\n"
- + " \"lastServiceDate\": \"1535014037024\","
- + " \"unitFamily\": \"BBU\","
- + " \"vendorName\": \"Nokia\","
- + " \"oamV4IpAddress\": \"10.16.123.234\","
- + " \"softwareVersion\": \"v4.5.0.1\","
- + " \"oamV6IpAddress\": \"0:0:0:0:0:FFFF:0A10:7BEA\""
- + "}}}";
}
@Test
@@ -126,16 +107,22 @@ class DmaapConsumerTaskImplTest {
assertEquals(consumerDmaapModel, response.blockFirst());
}
+ @Test
+ void whenInitConfigs_initStreamReader() {
+ //when
+ dmaapConsumerTask.initConfigs();
+
+ //then
+ verify(appConfig).initFileStreamReader();
+ }
+
private void prepareMocksForDmaapConsumer(Optional<String> message) {
- DmaapConsumerJsonParser dmaapConsumerJsonParser = spy(new DmaapConsumerJsonParser());
- JsonElement jsonElement = new JsonParser().parse(parsed);
- Mockito.doReturn(Optional.of(jsonElement.getAsJsonObject()))
- .when(dmaapConsumerJsonParser).getJsonObjectFromAnArray(jsonElement);
dMaaPConsumerReactiveHttpClient = mock(DMaaPConsumerReactiveHttpClient.class);
when(dMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).thenReturn(Mono.just(message.orElse("")));
when(appConfig.getDmaapConsumerConfiguration()).thenReturn(dmaapConsumerConfiguration);
- dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig, dmaapConsumerJsonParser));
- when(dmaapConsumerTask.resolveConfiguration()).thenReturn(dmaapConsumerConfiguration);
+ DMaaPReactiveWebClient dmaapReactiveWebClient = mock(DMaaPReactiveWebClient.class);
+ dmaapConsumerTask =
+ spy(new DmaapConsumerTaskImpl(appConfig, new DmaapConsumerJsonParser(), dmaapReactiveWebClient));
doReturn(dMaaPConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient();
}
} \ No newline at end of file
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java
index 5f73dbe1..f42c3962 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapConsumerTaskSpy.java
@@ -50,7 +50,6 @@ public class DmaapConsumerTaskSpy {
DmaapConsumerTaskImpl dmaapConsumerTask = spy(new DmaapConsumerTaskImpl(appConfig));
DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient = mock(
DMaaPConsumerReactiveHttpClient.class);
- doReturn(mock(DmaapConsumerConfiguration.class)).when(dmaapConsumerTask).resolveConfiguration();
doReturn(dmaapConsumerReactiveHttpClient).when(dmaapConsumerTask).resolveClient();
return dmaapConsumerTask;
}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java
index 01851dc1..7ed6c5ad 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapProducerTaskSpy.java
@@ -26,7 +26,7 @@ import static org.mockito.Mockito.spy;
import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.configuration.AppConfig;
-import org.onap.dcaegen2.services.prh.service.producer.DMaaPProducerReactiveHttpClient;
+import org.onap.dcaegen2.services.prh.service.producer.DMaaPPublisherReactiveHttpClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
@@ -48,9 +48,8 @@ public class DmaapProducerTaskSpy {
AppConfig appConfig = spy(AppConfig.class);
doReturn(mock(DmaapPublisherConfiguration.class)).when(appConfig).getDmaapPublisherConfiguration();
DmaapPublisherTaskImpl dmaapPublisherTask = spy(new DmaapPublisherTaskImpl(appConfig));
- DMaaPProducerReactiveHttpClient extendedDmaapProducerHttpClient = mock(
- DMaaPProducerReactiveHttpClient.class);
- doReturn(mock(DmaapPublisherConfiguration.class)).when(dmaapPublisherTask).resolveConfiguration();
+ DMaaPPublisherReactiveHttpClient extendedDmaapProducerHttpClient = mock(
+ DMaaPPublisherReactiveHttpClient.class);
doReturn(extendedDmaapProducerHttpClient).when(dmaapPublisherTask).resolveClient();
return dmaapPublisherTask;
}
diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
index 00d6fc46..e9eed698 100644
--- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
+++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/prh/tasks/DmaapPublisherTaskImplTest.java
@@ -40,7 +40,7 @@ import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException;
import org.onap.dcaegen2.services.prh.exceptions.PrhTaskException;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ImmutableConsumerDmaapModel;
-import org.onap.dcaegen2.services.prh.service.producer.DMaaPProducerReactiveHttpClient;
+import org.onap.dcaegen2.services.prh.service.producer.DMaaPPublisherReactiveHttpClient;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import reactor.core.publisher.Mono;
@@ -53,7 +53,7 @@ class DmaapPublisherTaskImplTest {
private static ConsumerDmaapModel consumerDmaapModel;
private static DmaapPublisherTaskImpl dmaapPublisherTask;
- private static DMaaPProducerReactiveHttpClient dMaaPProducerReactiveHttpClient;
+ private static DMaaPPublisherReactiveHttpClient dMaaPPublisherReactiveHttpClient;
private static AppConfig appConfig;
private static DmaapPublisherConfiguration dmaapPublisherConfiguration;
@@ -90,9 +90,9 @@ class DmaapPublisherTaskImplTest {
.expectNext(responseEntity).verifyComplete();
//then
- verify(dMaaPProducerReactiveHttpClient, times(1))
+ verify(dMaaPPublisherReactiveHttpClient, times(1))
.getDMaaPProducerResponse(consumerDmaapModel);
- verifyNoMoreInteractions(dMaaPProducerReactiveHttpClient);
+ verifyNoMoreInteractions(dMaaPPublisherReactiveHttpClient);
}
@@ -107,22 +107,20 @@ class DmaapPublisherTaskImplTest {
.expectNext(responseEntity).verifyComplete();
//then
- verify(dMaaPProducerReactiveHttpClient, times(1))
+ verify(dMaaPPublisherReactiveHttpClient, times(1))
.getDMaaPProducerResponse(consumerDmaapModel);
- verifyNoMoreInteractions(dMaaPProducerReactiveHttpClient);
+ verifyNoMoreInteractions(dMaaPPublisherReactiveHttpClient);
}
private ResponseEntity<String> prepareMocksForTests(Integer httpResponseCode) {
ResponseEntity<String> responseEntity = mock(ResponseEntity.class);
- //when
when(responseEntity.getStatusCode()).thenReturn(HttpStatus.valueOf(httpResponseCode));
- dMaaPProducerReactiveHttpClient = mock(DMaaPProducerReactiveHttpClient.class);
- when(dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(any()))
+ dMaaPPublisherReactiveHttpClient = mock(DMaaPPublisherReactiveHttpClient.class);
+ when(dMaaPPublisherReactiveHttpClient.getDMaaPProducerResponse(any()))
.thenReturn(Mono.just(responseEntity));
dmaapPublisherTask = spy(new DmaapPublisherTaskImpl(appConfig));
- when(dmaapPublisherTask.resolveConfiguration()).thenReturn(dmaapPublisherConfiguration);
- doReturn(dMaaPProducerReactiveHttpClient).when(dmaapPublisherTask).resolveClient();
+ doReturn(dMaaPPublisherReactiveHttpClient).when(dmaapPublisherTask).resolveClient();
return responseEntity;
}
} \ No newline at end of file