aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/dmaap-client/src/test/java
diff options
context:
space:
mode:
authorMarcin Migdal <marcin.migdal@nokia.com>2019-02-27 17:10:03 +0100
committerMarcin Migdal <marcin.migdal@nokia.com>2019-02-28 15:02:35 +0100
commit6493e10bc206313bd92a6b4f760b0a7e3d6ee641 (patch)
tree87bc12e63eeb9301850d8e443be05ed02f2d6679 /rest-services/dmaap-client/src/test/java
parent5e6c996472969e50b3da60a06559c3231218637e (diff)
Remove Spring stuff from DMaaP
Change-Id: Id441d0dce89fcb24b5558af7bdf996a74eba78e6 Issue-ID: DCAEGEN2-1245 Signed-off-by: Marcin Migdal <marcin.migdal@nokia.com>
Diffstat (limited to 'rest-services/dmaap-client/src/test/java')
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java59
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactoryTest.java7
2 files changed, 26 insertions, 40 deletions
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
index 9a4a130c..4c789019 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java
@@ -20,22 +20,20 @@
package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
-import static org.springframework.web.reactive.function.client.ExchangeFilterFunctions.basicAuthentication;
import java.net.URI;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import org.apache.http.entity.ContentType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
-import org.springframework.http.HttpHeaders;
-import org.springframework.web.reactive.function.client.WebClient;
-import org.springframework.web.reactive.function.client.WebClient.RequestHeadersUriSpec;
-import org.springframework.web.reactive.function.client.WebClient.ResponseSpec;
+import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -47,11 +45,11 @@ class DMaaPConsumerReactiveHttpClientTest {
private static final String JSON_MESSAGE = "{ \"responseFromDmaap\": \"Success\"}";
private DMaaPConsumerReactiveHttpClient dmaapConsumerReactiveHttpClient;
private DmaapConsumerConfiguration consumerConfigurationMock = mock(DmaapConsumerConfiguration.class);
- private Mono<String> expectedResult = Mono.empty();
- private WebClient webClient;
- private RequestHeadersUriSpec requestHeadersSpec;
- private ResponseSpec responseSpec;
-
+ private Mono<String> expectedResult;
+ private CloudHttpClient httpClient = mock(CloudHttpClient.class);
+ private URI exampleTestUri = URI
+ .create("https://54.45.33.2:1234/unauthenticated.SEC_OTHER_OUTPUT/OpenDCAE-c12/c12");
+ private RequestDiagnosticContext requestDiagnosticContext = mock(RequestDiagnosticContext.class);
@BeforeEach
void setUp() {
@@ -60,32 +58,22 @@ class DMaaPConsumerReactiveHttpClientTest {
when(consumerConfigurationMock.dmaapPortNumber()).thenReturn(1234);
when(consumerConfigurationMock.dmaapUserName()).thenReturn("PRH");
when(consumerConfigurationMock.dmaapUserPassword()).thenReturn("PRH");
- when(consumerConfigurationMock.dmaapContentType()).thenReturn("application/json");
+ when(consumerConfigurationMock.dmaapContentType()).thenReturn(ContentType.APPLICATION_JSON.getMimeType());
when(consumerConfigurationMock.dmaapTopicName()).thenReturn("unauthenticated.SEC_OTHER_OUTPUT");
when(consumerConfigurationMock.consumerGroup()).thenReturn("OpenDCAE-c12");
when(consumerConfigurationMock.consumerId()).thenReturn("c12");
-
- webClient = spy(WebClient.builder()
- .defaultHeader(HttpHeaders.CONTENT_TYPE, consumerConfigurationMock.dmaapContentType())
- .filter(basicAuthentication(consumerConfigurationMock.dmaapUserName(),
- consumerConfigurationMock.dmaapUserPassword()))
- .build());
- dmaapConsumerReactiveHttpClient = new DMaaPConsumerReactiveHttpClient(consumerConfigurationMock, webClient);
- requestHeadersSpec = mock(RequestHeadersUriSpec.class);
- responseSpec = mock(ResponseSpec.class);
+ dmaapConsumerReactiveHttpClient = new DMaaPConsumerReactiveHttpClient(consumerConfigurationMock, httpClient);
}
-
@Test
void getHttpResponse_Success() {
//given
expectedResult = Mono.just(JSON_MESSAGE);
-
+ when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext, getCustomHeaders(), String.class))
+ .thenReturn(expectedResult);
//when
- mockDependantObjects();
- doReturn(expectedResult).when(responseSpec).bodyToMono(String.class);
- Mono<String> response = dmaapConsumerReactiveHttpClient.getDMaaPConsumerResponse();
-
+ Mono<String> response = dmaapConsumerReactiveHttpClient
+ .getDMaaPConsumerResponse(Optional.of(requestDiagnosticContext));
//then
StepVerifier.create(response).expectSubscription()
.expectNextMatches(results -> {
@@ -96,16 +84,13 @@ class DMaaPConsumerReactiveHttpClientTest {
@Test
void getAppropriateUri_whenPassingCorrectedPathForPnf() {
- Assertions.assertEquals(dmaapConsumerReactiveHttpClient.getUri(),
- URI.create("https://54.45.33.2:1234/unauthenticated.SEC_OTHER_OUTPUT/OpenDCAE-c12/c12"));
+ Assertions.assertEquals(dmaapConsumerReactiveHttpClient.getUri(), exampleTestUri);
}
- private void mockDependantObjects() {
- when(webClient.get()).thenReturn(requestHeadersSpec);
- when(requestHeadersSpec.uri((URI) any())).thenReturn(requestHeadersSpec);
- when(requestHeadersSpec.headers(any())).thenReturn(requestHeadersSpec);
- when(requestHeadersSpec.retrieve()).thenReturn(responseSpec);
- doReturn(responseSpec).when(responseSpec).onStatus(any(), any());
+ private Map<String, String> getCustomHeaders() {
+ Map<String, String> customHeaders = new HashMap<>();
+ customHeaders.put("Content-Type", ContentType.APPLICATION_JSON.getMimeType());
+ return customHeaders;
}
} \ No newline at end of file
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactoryTest.java
index d9989d1d..6fd22007 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactoryTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactoryTest.java
@@ -30,7 +30,8 @@ import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory;
-import org.springframework.web.reactive.function.client.WebClient;
+import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+
/**
* @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/5/18
@@ -51,7 +52,7 @@ class DMaaPReactiveWebClientFactoryTest {
DmaapConsumerConfiguration dmaapConsumerConfiguration = givenDmaapConfigurationWithSslDisabled();
//when
- WebClient dmaapReactiveWebClient = webClientFactory.build(dmaapConsumerConfiguration);
+ CloudHttpClient dmaapReactiveWebClient = webClientFactory.build(dmaapConsumerConfiguration);
//then
Assertions.assertNotNull(dmaapReactiveWebClient);
@@ -64,7 +65,7 @@ class DMaaPReactiveWebClientFactoryTest {
DmaapConsumerConfiguration dmaapConsumerConfiguration = givenDmaapConfigurationWithSslEnabled();
//when
- WebClient dmaapReactiveWebClient = webClientFactory.build(dmaapConsumerConfiguration);
+ CloudHttpClient dmaapReactiveWebClient = webClientFactory.build(dmaapConsumerConfiguration);
//then
Assertions.assertNotNull(dmaapReactiveWebClient);