aboutsummaryrefslogtreecommitdiffstats
path: root/prh-dmaap-client/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'prh-dmaap-client/src/test')
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/DMaaPReactiveWebClientTest.java16
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java32
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPProducerReactiveHttpClientTest.java35
3 files changed, 14 insertions, 69 deletions
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
index fad18699..2e323c5e 100644
--- 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
@@ -19,8 +19,12 @@
*/
package org.onap.dcaegen2.services.prh.service;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.prh.config.DmaapConsumerConfiguration;
import org.springframework.web.reactive.function.client.WebClient;
/**
@@ -28,19 +32,23 @@ import org.springframework.web.reactive.function.client.WebClient;
*/
public class DMaaPReactiveWebClientTest {
+
@Test
public void builder_shouldBuildDMaaPReactiveWebClient() {
//given
+ DmaapConsumerConfiguration dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class);
WebClient dMaaPReactiveWebClient;
String dMaaPContentType = "*/*";
String dMaaPUserName = "DMaaP";
String dMaaPUserPassword = "DMaaP";
//when
- dMaaPReactiveWebClient = new DMaaPReactiveWebClient.WebClientBuilder()
- .dmaapContentType(dMaaPContentType)
- .dmaapUserName(dMaaPUserName)
- .dmaapUserPassword(dMaaPUserPassword).build();
+ when(dmaapConsumerConfiguration.dmaapContentType()).thenReturn(dMaaPContentType);
+ when(dmaapConsumerConfiguration.dmaapUserName()).thenReturn(dMaaPUserName);
+ when(dmaapConsumerConfiguration.dmaapUserPassword()).thenReturn(dMaaPUserPassword);
+ dMaaPReactiveWebClient = new DMaaPReactiveWebClient()
+ .fromConfiguration(dmaapConsumerConfiguration)
+ .build();
//then
Assertions.assertNotNull(dMaaPReactiveWebClient);
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
index cbc7bd62..1f04da15 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
@@ -98,36 +98,6 @@ public class DMaaPConsumerReactiveHttpClientTest {
}).verifyComplete();
}
-
- @Test
- public void getHttpResponse_HttpResponse4xxClientError() {
-
- //when
- mockDependantObjects();
- doAnswer(invocationOnMock -> Mono.error(new Exception("400")))
- .when(responseSpec).onStatus(HttpStatus::is4xxClientError, e -> Mono.error(new Exception("400")));
- DMaaPConsumerReactiveHttpClient.createDMaaPWebClient(webClient);
-
- //then
- StepVerifier.create(DMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription()
- .expectError(Exception.class);
-
- }
-
- @Test
- public void getHttpResponse_HttpResponse5xxClientError() {
-
- //when
- mockDependantObjects();
- doAnswer(invocationOnMock -> Mono.error(new Exception("500")))
- .when(responseSpec).onStatus(HttpStatus::is4xxClientError, e -> Mono.error(new Exception("500")));
- DMaaPConsumerReactiveHttpClient.createDMaaPWebClient(webClient);
-
- //then
- StepVerifier.create(DMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription()
- .expectError(Exception.class);
- }
-
@Test
public void getHttpResponse_whenURISyntaxExceptionHasBeenThrown() throws URISyntaxException {
//given
@@ -139,7 +109,7 @@ public class DMaaPConsumerReactiveHttpClientTest {
//then
StepVerifier.create(DMaaPConsumerReactiveHttpClient.getDMaaPConsumerResponse()).expectSubscription()
- .expectError(Exception.class);
+ .expectError(Exception.class).verify();
}
private void mockDependantObjects() {
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 f1fb70b0..20ab64e5 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
@@ -20,7 +20,6 @@
package org.onap.dcaegen2.services.prh.service.producer;
import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -36,7 +35,6 @@ import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModel;
import org.onap.dcaegen2.services.prh.model.ConsumerDmaapModelForUnitTest;
import org.springframework.http.HttpHeaders;
-import org.springframework.http.HttpStatus;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClient.RequestBodyUriSpec;
import org.springframework.web.reactive.function.client.WebClient.RequestHeadersSpec;
@@ -97,37 +95,6 @@ public class DMaaPProducerReactiveHttpClientTest {
}
@Test
- public void getHttpResponse_HttpResponse4xxClientError() {
- //when
- mockWebClientDependantObject();
-
- doAnswer(invocationOnMock -> Mono.error(new Exception("400")))
- .when(responseSpec).onStatus(HttpStatus::is4xxClientError, e -> Mono.error(new Exception("400")));
- dMaaPProducerReactiveHttpClient.createDMaaPWebClient(webClient);
-
- //then
- StepVerifier.create(dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(Mono.just(consumerDmaapModel)))
- .expectSubscription()
- .expectError(Exception.class);
-
- }
-
- @Test
- public void getHttpResponse_HttpResponse5xxClientError() {
-
- //when
- mockWebClientDependantObject();
- doAnswer(invocationOnMock -> Mono.error(new Exception("500")))
- .when(responseSpec).onStatus(HttpStatus::is4xxClientError, e -> Mono.error(new Exception("500")));
- dMaaPProducerReactiveHttpClient.createDMaaPWebClient(webClient);
-
- //then
- StepVerifier.create(dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(Mono.just(consumerDmaapModel)))
- .expectSubscription()
- .expectError(Exception.class);
- }
-
- @Test
public void getHttpResponse_whenURISyntaxExceptionHasBeenThrown() throws URISyntaxException {
//given
dMaaPProducerReactiveHttpClient = spy(dMaaPProducerReactiveHttpClient);
@@ -138,7 +105,7 @@ public class DMaaPProducerReactiveHttpClientTest {
//then
StepVerifier.create(dMaaPProducerReactiveHttpClient.getDMaaPProducerResponse(any())).expectSubscription()
- .expectError(Exception.class);
+ .expectError(Exception.class).verify();
}
private void mockWebClientDependantObject() {