X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Fdmaap%2FDmaapMessageHandlerTest.java;h=09dbf92fe6b1b00b373a3ef199d9cdb4d716f2a5;hb=28b508e5df22fd468d18769449710bd0764a778d;hp=5aeb2404dd6964bb9b24de0fb58670682d56f25f;hpb=0da7354bf7548829a7152dfa0276710dbbe00b7b;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/dmaap/DmaapMessageHandlerTest.java b/policy-agent/src/test/java/org/oransc/policyagent/dmaap/DmaapMessageHandlerTest.java index 5aeb2404..09dbf92f 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/dmaap/DmaapMessageHandlerTest.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/dmaap/DmaapMessageHandlerTest.java @@ -27,9 +27,12 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; + import com.google.gson.Gson; import com.google.gson.GsonBuilder; + import java.io.IOException; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.onap.dmaap.mr.client.MRBatchingPublisher; @@ -37,11 +40,15 @@ import org.onap.dmaap.mr.client.response.MRPublisherResponse; import org.oransc.policyagent.clients.AsyncRestClient; import org.oransc.policyagent.configuration.ApplicationConfig; import org.oransc.policyagent.dmaap.DmaapRequestMessage.Operation; + import reactor.core.publisher.Mono; import reactor.test.StepVerifier; public class DmaapMessageHandlerTest { + private static final String URL = "url"; + private static final String PAYLOAD = "payload"; + private ApplicationConfig appConfig = mock(ApplicationConfig.class); private final MRBatchingPublisher dmaapClient = mock(MRBatchingPublisher.class); private final AsyncRestClient agentClient = mock(AsyncRestClient.class); @@ -52,20 +59,20 @@ public class DmaapMessageHandlerTest { @BeforeEach private void setUp() throws Exception { - testedObject = spy(new DmaapMessageHandler(dmaapClient, appConfig, agentClient)); + testedObject = spy(new DmaapMessageHandler(dmaapClient, agentClient)); } - ImmutableDmaapRequestMessage dmaapRequestMessage(Operation operation) { + DmaapRequestMessage dmaapRequestMessage(Operation operation) { return ImmutableDmaapRequestMessage.builder().apiVersion("apiVersion") // .correlationId("correlationId") // .operation(operation) // .originatorId("originatorId") // - .payload("payload") // + .payload(PAYLOAD) // .requestId("requestId") // .target("target") // .timestamp("timestamp") // .type("type") // - .url("url") // + .url(URL) // .build(); } @@ -74,8 +81,8 @@ public class DmaapMessageHandlerTest { } @Test - public void successfulCase() throws IOException { - doReturn(Mono.just("OK")).when(agentClient).delete("url"); + public void successfulDelete() throws IOException { + doReturn(Mono.just("OK")).when(agentClient).delete(anyString()); doReturn(1).when(dmaapClient).send(anyString()); doReturn(new MRPublisherResponse()).when(dmaapClient).sendBatchWithResponse(); @@ -85,7 +92,67 @@ public class DmaapMessageHandlerTest { .expectNext("OK") // .verifyComplete(); // - verify(agentClient, times(1)).delete("url"); + verify(agentClient, times(1)).delete(URL); + verifyNoMoreInteractions(agentClient); + + verify(dmaapClient, times(1)).send(anyString()); + verify(dmaapClient, times(1)).sendBatchWithResponse(); + verifyNoMoreInteractions(dmaapClient); + } + + @Test + public void successfulGet() throws IOException { + doReturn(Mono.just("OK")).when(agentClient).get(anyString()); + doReturn(1).when(dmaapClient).send(anyString()); + doReturn(new MRPublisherResponse()).when(dmaapClient).sendBatchWithResponse(); + + StepVerifier // + .create(testedObject.createTask(dmaapInputMessage(Operation.GET))) // + .expectSubscription() // + .expectNext("OK") // + .verifyComplete(); // + + verify(agentClient, times(1)).get(URL); + verifyNoMoreInteractions(agentClient); + + verify(dmaapClient, times(1)).send(anyString()); + verify(dmaapClient, times(1)).sendBatchWithResponse(); + verifyNoMoreInteractions(dmaapClient); + } + + @Test + public void successfulPut() throws IOException { + doReturn(Mono.just("OK")).when(agentClient).put(anyString(), anyString()); + doReturn(1).when(dmaapClient).send(anyString()); + doReturn(new MRPublisherResponse()).when(dmaapClient).sendBatchWithResponse(); + + StepVerifier // + .create(testedObject.createTask(dmaapInputMessage(Operation.PUT))) // + .expectSubscription() // + .expectNext("OK") // + .verifyComplete(); // + + verify(agentClient, times(1)).put(URL, PAYLOAD); + verifyNoMoreInteractions(agentClient); + + verify(dmaapClient, times(1)).send(anyString()); + verify(dmaapClient, times(1)).sendBatchWithResponse(); + verifyNoMoreInteractions(dmaapClient); + } + + @Test + public void successfulPost() throws IOException { + doReturn(Mono.just("OK")).when(agentClient).post(anyString(), anyString()); + doReturn(1).when(dmaapClient).send(anyString()); + doReturn(new MRPublisherResponse()).when(dmaapClient).sendBatchWithResponse(); + + StepVerifier // + .create(testedObject.createTask(dmaapInputMessage(Operation.POST))) // + .expectSubscription() // + .expectNext("OK") // + .verifyComplete(); // + + verify(agentClient, times(1)).post(URL, PAYLOAD); verifyNoMoreInteractions(agentClient); verify(dmaapClient, times(1)).send(anyString()); @@ -95,7 +162,7 @@ public class DmaapMessageHandlerTest { @Test public void errorCase() throws IOException { - doReturn(Mono.error(new Exception("Refused"))).when(agentClient).put("url", "payload"); + doReturn(Mono.error(new Exception("Refused"))).when(agentClient).put(anyString(), anyString()); doReturn(1).when(dmaapClient).send(anyString()); doReturn(new MRPublisherResponse()).when(dmaapClient).sendBatchWithResponse(); StepVerifier // @@ -103,7 +170,7 @@ public class DmaapMessageHandlerTest { .expectSubscription() // .verifyComplete(); // - verify(agentClient, times(1)).put("url", "payload"); + verify(agentClient, times(1)).put(URL, PAYLOAD); verifyNoMoreInteractions(agentClient); // Error response