diff options
Diffstat (limited to 'prh-app-server/src')
2 files changed, 17 insertions, 20 deletions
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 9cec7779..1a528180 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 @@ -20,10 +20,9 @@ package org.onap.dcaegen2.services.prh.tasks; -import com.google.gson.JsonPrimitive; import org.onap.dcaegen2.services.prh.exceptions.DmaapNotFoundException; import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel; -import org.onap.dcaegen2.services.prh.model.PnfReadyJsonBodyBuilderImpl; +import org.onap.dcaegen2.services.prh.model.PnfReadyJsonBodyBuilder; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRouterPublisher; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishResponse; @@ -42,7 +41,7 @@ public class DmaapPublisherTaskImpl implements DmaapPublisherTask { private final Supplier<MessageRouterPublishRequest> config; private final MessageRouterPublisherResolver messageRouterPublisherClientResolver; - private final PnfReadyJsonBodyBuilderImpl pnfReadyJsonBodyBuilder = new PnfReadyJsonBodyBuilderImpl(); + private final PnfReadyJsonBodyBuilder pnfReadyJsonBodyBuilder = new PnfReadyJsonBodyBuilder(); public DmaapPublisherTaskImpl(Supplier<MessageRouterPublishRequest> config, MessageRouterPublisherResolver messageRouterPublisherClientResolver) { @@ -57,9 +56,8 @@ public class DmaapPublisherTaskImpl implements DmaapPublisherTask { } MessageRouterPublisher messageRouterPublisher = messageRouterPublisherClientResolver.resolveClient(); LOGGER.info("Method called with arg {}", consumerDmaapModel); - String json = pnfReadyJsonBodyBuilder.createJsonBody(consumerDmaapModel); return messageRouterPublisher.put( config.get(), - Flux.just(json).map(JsonPrimitive::new)); + Flux.just(pnfReadyJsonBodyBuilder.createJsonBody(consumerDmaapModel))); } }
\ No newline at end of file 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 6347ad3d..6f38d87d 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 @@ -20,7 +20,8 @@ package org.onap.dcaegen2.services.prh.tasks; -import com.google.gson.JsonPrimitive; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -38,10 +39,8 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.api.MessageRout import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.ImmutableMessageRouterPublishRequest; import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.model.MessageRouterPublishRequest; import reactor.core.publisher.Flux; +import reactor.test.StepVerifier; -import java.util.function.Supplier; - -import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.verify; @@ -53,30 +52,27 @@ import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class DmaapPublisherTaskImplTest { - private static DmaapPublisherTaskImpl dmaapPublisherTask; + private DmaapPublisherTaskImpl dmaapPublisherTask; + + private MessageRouterPublishRequest mrRequest = createMRRequest(); @Mock private static MessageRouterPublisherResolver messageRouterPublisherClientResolver; @Mock private static MessageRouterPublisher messageRouterPublisher; - private Supplier<MessageRouterPublishRequest> configSupplier; - - @Captor - private ArgumentCaptor<Flux<JsonPrimitive>> fluxCaptor; + private ArgumentCaptor<Flux<JsonElement>> fluxCaptor; @BeforeEach void beforeEach() { when(messageRouterPublisherClientResolver.resolveClient()).thenReturn(messageRouterPublisher); - MessageRouterPublishRequest mrRequest = createMRRequest(); - configSupplier = () -> mrRequest; } @Test void execute_whenPassedObjectDoesntFit_ThrowsPrhTaskException() { //given - dmaapPublisherTask = new DmaapPublisherTaskImpl(configSupplier, messageRouterPublisherClientResolver); + dmaapPublisherTask = new DmaapPublisherTaskImpl(() -> mrRequest, messageRouterPublisherClientResolver); //when Executable executableFunction = () -> dmaapPublisherTask.execute(null); //then @@ -86,12 +82,15 @@ class DmaapPublisherTaskImplTest { @Test void execute_whenPassedObjectFits_ReturnsCorrectStatus() throws DmaapNotFoundException { //given - dmaapPublisherTask = new DmaapPublisherTaskImpl(configSupplier, messageRouterPublisherClientResolver); + dmaapPublisherTask = new DmaapPublisherTaskImpl(() -> mrRequest, messageRouterPublisherClientResolver); //when dmaapPublisherTask.execute(createConsumerDmaapModel()); //then - verify(messageRouterPublisher).put(eq(configSupplier.get()), fluxCaptor.capture()); - assertEquals(new JsonPrimitive("{\"correlationId\":\"NOKQTFCOC540002E\"}"), fluxCaptor.getValue().blockFirst()); + verify(messageRouterPublisher).put(eq(mrRequest), fluxCaptor.capture()); + + StepVerifier.create(fluxCaptor.getValue()) + .expectNext(new JsonParser().parse("{\"correlationId\":\"NOKQTFCOC540002E\"}")) + .verifyComplete(); } |