aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/dmaap-client/src/test
diff options
context:
space:
mode:
authorMarcin Migdal <marcin.migdal@nokia.com>2019-03-07 15:02:24 +0100
committerMarcin Migdal <marcin.migdal@nokia.com>2019-03-08 12:47:13 +0100
commit522a1c9dde168f0baa32a52a80a1b85b0b4812f9 (patch)
tree55f72ca7984183f2ae9072bd69935805a7eec492 /rest-services/dmaap-client/src/test
parent3666e89b3411e84b138279cccc8130df60c81f4c (diff)
DMaaP client remove Spring
Change-Id: I9e0206d4b3c737df8a80944f0050871c1ad307c6 Issue-ID: DCAEGEN2-1310 Signed-off-by: Marcin Migdal <marcin.migdal@nokia.com>
Diffstat (limited to 'rest-services/dmaap-client/src/test')
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfigurationTest.java (renamed from rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapConsumerConfigurationTest.java)2
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapPublisherConfigurationTest.java (renamed from rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapPublisherConfigurationTest.java)2
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtilsTest.java43
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java2
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPConsumerReactiveHttpClientTest.java10
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java63
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java9
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java6
8 files changed, 91 insertions, 46 deletions
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapConsumerConfigurationTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfigurationTest.java
index cf0be692..f7940c8f 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapConsumerConfigurationTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapConsumerConfigurationTest.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.config;
+package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapPublisherConfigurationTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapPublisherConfigurationTest.java
index 7128777a..d7f06d1b 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/config/DmaapPublisherConfigurationTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/config/DmaapPublisherConfigurationTest.java
@@ -18,7 +18,7 @@
* ============LICENSE_END=========================================================
*/
-package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.config;
+package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config;
import static org.junit.jupiter.api.Assertions.assertEquals;
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtilsTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtilsTest.java
new file mode 100644
index 00000000..58f23b35
--- /dev/null
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/DMaaPClientServiceUtilsTest.java
@@ -0,0 +1,43 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service;
+
+import java.util.Map;
+import static org.junit.jupiter.api.Assertions.*;
+import org.junit.jupiter.api.Test;
+import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils;
+
+public class DMaaPClientServiceUtilsTest {
+
+
+ private final static String contentType = "myType";
+
+ @Test
+ public void getHeaders(){
+
+ Map<String,String> headres = DMaaPClientServiceUtils.getHeaders(contentType);
+ assertEquals(1,headres.size());
+ assertEquals(contentType,headres.get(DMaaPClientServiceUtils.CONTENT_TYPE));
+
+ }
+
+
+}
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java
index 75eafcb6..e356f179 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactoryTest.java
@@ -32,7 +32,7 @@ class ConsumerReactiveHttpClientFactoryTest {
private DmaapConsumerConfiguration dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class);
private DMaaPReactiveWebClientFactory reactiveWebClientFactory = mock(DMaaPReactiveWebClientFactory.class);
private ConsumerReactiveHttpClientFactory httpClientFactory =
- new ConsumerReactiveHttpClientFactory(reactiveWebClientFactory);
+ new ConsumerReactiveHttpClientFactory(reactiveWebClientFactory);
@Test
void create_shouldReturnNotNullFactoryInstance() throws Exception {
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 4c789019..d2ca5d12 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
@@ -24,8 +24,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
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;
@@ -33,6 +31,7 @@ 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.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils;
import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -69,7 +68,7 @@ class DMaaPConsumerReactiveHttpClientTest {
void getHttpResponse_Success() {
//given
expectedResult = Mono.just(JSON_MESSAGE);
- when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext, getCustomHeaders(), String.class))
+ when(httpClient.get(exampleTestUri.toString(), requestDiagnosticContext, DMaaPClientServiceUtils.getHeaders(ContentType.APPLICATION_JSON.getMimeType()), String.class))
.thenReturn(expectedResult);
//when
Mono<String> response = dmaapConsumerReactiveHttpClient
@@ -87,10 +86,5 @@ class DMaaPConsumerReactiveHttpClientTest {
Assertions.assertEquals(dmaapConsumerReactiveHttpClient.getUri(), exampleTestUri);
}
- 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/producer/DMaaPPublisherReactiveHttpClientTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java
index c84ca7d2..0ff1e207 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DMaaPPublisherReactiveHttpClientTest.java
@@ -20,24 +20,22 @@
package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.net.URI;
+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.DmaapPublisherConfiguration;
-
+import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.DMaaPClientServiceUtils;
+import org.onap.dcaegen2.services.sdk.rest.services.model.ClientModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.DmaapModel;
import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
-import org.springframework.http.HttpEntity;
-import org.springframework.http.HttpMethod;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
-import org.springframework.web.client.RestTemplate;
+import org.onap.dcaegen2.services.sdk.rest.services.model.logging.RequestDiagnosticContext;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
@@ -49,12 +47,11 @@ class DMaaPPublisherReactiveHttpClientTest {
private DMaaPPublisherReactiveHttpClient dmaapPublisherReactiveHttpClient;
private DmaapPublisherConfiguration dmaapPublisherConfigurationMock = mock(DmaapPublisherConfiguration.class);
-
- private RestTemplate restTemplate = mock(RestTemplate.class);
-
- private DmaapModel dmaapModel = mock(DmaapModel.class);
- private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class);
-
+ private CloudHttpClient cloudHttpClientMock = mock(CloudHttpClient.class);
+ private DmaapModel dmaapModelMock = mock(DmaapModel.class);
+ private JsonBodyBuilder<DmaapModel> jsonBodyBuilderMock = mock(JsonBodyBuilder.class);
+ private Optional<RequestDiagnosticContext> requestDiagnosticContextOptionalMock = Optional
+ .of(mock(RequestDiagnosticContext.class));
@BeforeEach
void setUp() {
@@ -66,33 +63,43 @@ class DMaaPPublisherReactiveHttpClientTest {
when(dmaapPublisherConfigurationMock.dmaapContentType()).thenReturn("application/json");
when(dmaapPublisherConfigurationMock.dmaapTopicName()).thenReturn("unauthenticated.PNF_READY");
- when(jsonBodyBuilder.createJsonBody(dmaapModel)).thenReturn(
- "{\"correlationId\":\"NOKnhfsadhff\"," +
- "\"ipaddress-v4\":\"256.22.33.155\", " +
- "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}");
+ when(jsonBodyBuilderMock.createJsonBody(dmaapModelMock)).thenReturn(
+ "{\"correlationId\":\"NOKnhfsadhff\"," +
+ "\"ipaddress-v4\":\"256.22.33.155\", " +
+ "\"ipaddress-v6\":\"200J:0db8:85a3:0000:0000:8a2e:0370:7334\"}");
dmaapPublisherReactiveHttpClient =
- new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, Mono.just(restTemplate),jsonBodyBuilder);
+ new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, cloudHttpClientMock,
+ jsonBodyBuilderMock);
}
@Test
void getHttpResponse_Success() {
//given
- int responseSuccess = 200;
- ResponseEntity<String> mockedResponseEntity = mock(ResponseEntity.class);
+ Mono<Integer> expectedResult = Mono.just(Integer.valueOf(200));
//when
- when(mockedResponseEntity.getStatusCode()).thenReturn(HttpStatus.valueOf(responseSuccess));
- doReturn(mockedResponseEntity).when(restTemplate)
- .exchange(any(URI.class), any(HttpMethod.class), any(HttpEntity.class), (Class<Object>) any());
-
+ when(
+ cloudHttpClientMock
+ .post(getUri().toString(), requestDiagnosticContextOptionalMock.get(),
+ DMaaPClientServiceUtils.getHeaders(ContentType.APPLICATION_JSON.getMimeType()),
+ jsonBodyBuilderMock,
+ mock(ClientModel.class)))
+ .thenReturn(Mono.just(Integer.valueOf(200)));
//then
- StepVerifier.create(dmaapPublisherReactiveHttpClient.getDMaaPProducerResponse(dmaapModel))
- .expectSubscription().expectNext(mockedResponseEntity).verifyComplete();
+ StepVerifier.create(expectedResult).expectSubscription()
+ .expectNextMatches(results -> {
+ Assertions.assertEquals(results, expectedResult.block());
+ return true;
+ }).verifyComplete();
}
@Test
void getAppropriateUri_whenPassingCorrectedPathForPnf() {
Assertions.assertEquals(dmaapPublisherReactiveHttpClient.getUri(),
- URI.create("https://54.45.33.2:1234/unauthenticated.PNF_READY"));
+ getUri());
+ }
+
+ private URI getUri() {
+ return URI.create("https://54.45.33.2:1234/unauthenticated.PNF_READY");
}
} \ 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/producer/DmaaPRestTemplateFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java
index bd3b07e9..cc239fa4 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java
@@ -23,6 +23,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.produc
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import javax.net.ssl.SSLException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
@@ -38,21 +39,21 @@ class DmaaPRestTemplateFactoryTest {
private DmaaPRestTemplateFactory factory = new DmaaPRestTemplateFactory();
@Test
- void build_shouldCreateRestTemplateWithoutSslConfiguration() {
+ void build_shouldCreateRestTemplateWithoutSslConfiguration() throws SSLException {
when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(false);
- Assertions.assertNotNull(factory.build(publisherConfiguration).block());
+ Assertions.assertNotNull(factory.build(publisherConfiguration));
}
@Test
- void build_shouldCreateRestTemplateWithSslConfiguration() {
+ void build_shouldCreateRestTemplateWithSslConfiguration() throws SSLException {
when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(true);
when(publisherConfiguration.keyStorePath()).thenReturn(getPath(KEY_STORE));
when(publisherConfiguration.keyStorePasswordPath()).thenReturn(getPath(KEYSTORE_PASSWORD));
when(publisherConfiguration.trustStorePath()).thenReturn(getPath(TRUST_STORE));
when(publisherConfiguration.trustStorePasswordPath()).thenReturn(getPath(TRUSTSTORE_PASSWORD));
- Assertions.assertNotNull(factory.build(publisherConfiguration).block());
+ Assertions.assertNotNull(factory.build(publisherConfiguration));
}
private String getPath(String fileName) {
diff --git a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java
index 07b35673..380f8b15 100644
--- a/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java
+++ b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java
@@ -22,6 +22,7 @@ package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.produc
import static org.mockito.Mockito.mock;
+import javax.net.ssl.SSLException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
@@ -35,12 +36,11 @@ class PublisherReactiveHttpClientFactoryTest {
private DmaapPublisherConfiguration dmaapPublisherConfiguration = mock(DmaapPublisherConfiguration.class);
private JsonBodyBuilder<DmaapModel> jsonBodyBuilder = mock(JsonBodyBuilder.class);
-
private PublisherReactiveHttpClientFactory httpClientFactory =
- new PublisherReactiveHttpClientFactory(restTemplateFactory, jsonBodyBuilder);
+ new PublisherReactiveHttpClientFactory(restTemplateFactory, jsonBodyBuilder);
@Test
- void create_shouldReturnNotNullFactoryInstance() {
+ void create_shouldReturnNotNullFactoryInstance() throws SSLException {
Assertions.assertNotNull(httpClientFactory.create(dmaapPublisherConfiguration));
}
} \ No newline at end of file