aboutsummaryrefslogtreecommitdiffstats
path: root/rest-services/dmaap-client/src/test
diff options
context:
space:
mode:
authorIzabela Zawadzka <izabela.zawadzka@nokia.com>2019-04-09 08:24:18 +0200
committerIzabela Zawadzka <izabela.zawadzka@nokia.com>2019-04-09 11:49:02 +0200
commit8daac07f7a45e38702901252972039cf8d46fe53 (patch)
treebedb857806a03ac58152f5582b1179bc7bfdf9d8 /rest-services/dmaap-client/src/test
parentc04fd10cc5e3b49e84f5a7a7d6da318891b591cb (diff)
Get rid of deprecated SslFactory
Change-Id: I928d6911a2516ffbfc05e9193e5d2d8467ec2545 Signed-off-by: Izabela Zawadzka <izabela.zawadzka@nokia.com> Issue-ID: DCAEGEN2-1408
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/service/consumer/DMaaPReactiveWebClientFactoryTest.java61
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java30
-rw-r--r--rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java10
3 files changed, 57 insertions, 44 deletions
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 6fd22007..9d670c65 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
@@ -20,17 +20,21 @@
package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import io.netty.handler.ssl.SslContext;
-import javax.net.ssl.SSLException;
-import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.mockito.ArgumentCaptor;
import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapConsumerConfiguration;
-import org.onap.dcaegen2.services.sdk.rest.services.ssl.SslFactory;
import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClient;
+import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.utlis.SecurityKeysUtil;
+import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys;
+import org.onap.dcaegen2.services.sdk.security.ssl.SslFactory;
/**
@@ -38,16 +42,18 @@ import org.onap.dcaegen2.services.sdk.rest.services.adapters.http.CloudHttpClien
*/
class DMaaPReactiveWebClientFactoryTest {
- private static final String KEY_STORE = "keyStore";
- private static final String KEY_STORE_PASS = "keyStorePass";
- private static final String TRUST_STORE = "trustStore";
- private static final String TRUST_STORE_PASS = "trustStorePass";
+ private static final String KEY_STORE_RESOURCE_PATH = "/org.onap.dcae.jks";
+ private static final String KEY_STORE_PASS_RESOURCE_PATH = "/keystore.password";
+ private static final String TRUST_STORE_RESOURCE_PATH = "/org.onap.dcae.trust.jks";
+ private static final String TRUST_STORE_PASS_RESOURCE_PATH = "/truststore.password";
private SslFactory sslFactory = mock(SslFactory.class);
private SslContext dummySslContext = mock(SslContext.class);
private DMaaPReactiveWebClientFactory webClientFactory = new DMaaPReactiveWebClientFactory(sslFactory);
+ private ArgumentCaptor<SecurityKeys> securityKeysArgumentCaptor = ArgumentCaptor
+ .forClass(SecurityKeys.class);
@Test
- void builder_shouldBuildDMaaPReactiveWebClientwithInsecureSslContext() throws Exception {
+ void builder_shouldBuildDMaaPReactiveWebClientwithInsecureSslContext(){
//given
DmaapConsumerConfiguration dmaapConsumerConfiguration = givenDmaapConfigurationWithSslDisabled();
@@ -55,39 +61,50 @@ class DMaaPReactiveWebClientFactoryTest {
CloudHttpClient dmaapReactiveWebClient = webClientFactory.build(dmaapConsumerConfiguration);
//then
- Assertions.assertNotNull(dmaapReactiveWebClient);
- verify(sslFactory).createInsecureContext();
+ assertNotNull(dmaapReactiveWebClient);
+ verify(sslFactory).createInsecureClientContext();
}
@Test
- void builder_shouldBuildDMaaPReactiveWebClientwithSecureSslContext() throws Exception {
+ void builder_shouldBuildDMaaPReactiveWebClientwithSecureSslContext(){
//given
DmaapConsumerConfiguration dmaapConsumerConfiguration = givenDmaapConfigurationWithSslEnabled();
+ SecurityKeys givenKeys = SecurityKeysUtil.fromDmappCustomConfig(dmaapConsumerConfiguration);
//when
CloudHttpClient dmaapReactiveWebClient = webClientFactory.build(dmaapConsumerConfiguration);
//then
- Assertions.assertNotNull(dmaapReactiveWebClient);
- verify(sslFactory).createSecureContext(KEY_STORE, KEY_STORE_PASS, TRUST_STORE, TRUST_STORE_PASS);
+ assertNotNull(dmaapReactiveWebClient);
+
+ verify(sslFactory).createSecureClientContext(securityKeysArgumentCaptor.capture());
+
+ SecurityKeys capturedKeys = securityKeysArgumentCaptor.getValue();
+
+ assertEquals(capturedKeys.keyStore().path(), givenKeys.keyStore().path());
+ assertEquals(capturedKeys.keyStorePassword().toString(), givenKeys.keyStorePassword().toString());
+ assertEquals(capturedKeys.trustStore().path(), givenKeys.trustStore().path());
+ assertEquals(capturedKeys.trustStorePassword().toString(), givenKeys.trustStorePassword().toString());
}
- private DmaapConsumerConfiguration givenDmaapConfigurationWithSslDisabled() throws SSLException {
+ private DmaapConsumerConfiguration givenDmaapConfigurationWithSslDisabled(){
DmaapConsumerConfiguration dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class);
when(dmaapConsumerConfiguration.enableDmaapCertAuth()).thenReturn(false);
- when(sslFactory.createInsecureContext()).thenReturn(dummySslContext);
+ when(sslFactory.createInsecureClientContext()).thenReturn(dummySslContext);
return dmaapConsumerConfiguration;
}
- private DmaapConsumerConfiguration givenDmaapConfigurationWithSslEnabled() throws SSLException {
+ private DmaapConsumerConfiguration givenDmaapConfigurationWithSslEnabled(){
DmaapConsumerConfiguration dmaapConsumerConfiguration = mock(DmaapConsumerConfiguration.class);
+
when(dmaapConsumerConfiguration.enableDmaapCertAuth()).thenReturn(true);
- when(dmaapConsumerConfiguration.keyStorePath()).thenReturn(KEY_STORE);
- when(dmaapConsumerConfiguration.keyStorePasswordPath()).thenReturn(KEY_STORE_PASS);
- when(dmaapConsumerConfiguration.trustStorePath()).thenReturn(TRUST_STORE);
- when(dmaapConsumerConfiguration.trustStorePasswordPath()).thenReturn(TRUST_STORE_PASS);
- when(sslFactory.createSecureContext(KEY_STORE, KEY_STORE_PASS, TRUST_STORE, TRUST_STORE_PASS))
- .thenReturn(dummySslContext);
+ when(dmaapConsumerConfiguration.keyStorePath()).thenReturn(KEY_STORE_RESOURCE_PATH);
+ when(dmaapConsumerConfiguration.keyStorePasswordPath()).thenReturn(KEY_STORE_PASS_RESOURCE_PATH);
+ when(dmaapConsumerConfiguration.trustStorePath()).thenReturn(TRUST_STORE_RESOURCE_PATH);
+ when(dmaapConsumerConfiguration.trustStorePasswordPath()).thenReturn(TRUST_STORE_PASS_RESOURCE_PATH);
+
+ when(sslFactory.createSecureClientContext(any(SecurityKeys.class))).thenReturn(dummySslContext);
+
return dmaapConsumerConfiguration;
}
} \ 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 cc239fa4..80cf2243 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
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* DCAEGEN2-SERVICES-SDK
* ================================================================================
- * Copyright (C) 2018 NOKIA Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 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.
@@ -22,8 +22,6 @@ 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;
@@ -31,32 +29,30 @@ import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPub
class DmaaPRestTemplateFactoryTest {
- private static final String KEY_STORE = "org.onap.dcae.jks";
- private static final String KEYSTORE_PASSWORD = "keystore.password";
- private static final String TRUSTSTORE_PASSWORD = "truststore.password";
- private static final String TRUST_STORE = "org.onap.dcae.trust.jks";
+ private static final String KEY_STORE_RESOURCE_PATH = "/org.onap.dcae.jks";
+ private static final String KEYSTORE_PASSWORD_RESOURCE_PATH = "/keystore.password";
+ private static final String TRUSTSTORE_PASSWORD_RESOURCE_PATH = "/truststore.password";
+ private static final String TRUST_STORE_RESOURCE_PATH = "/org.onap.dcae.trust.jks";
private DmaapPublisherConfiguration publisherConfiguration = mock(DmaapPublisherConfiguration.class);
private DmaaPRestTemplateFactory factory = new DmaaPRestTemplateFactory();
@Test
- void build_shouldCreateRestTemplateWithoutSslConfiguration() throws SSLException {
+ void build_shouldCreateRestTemplateWithoutSslConfiguration(){
when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(false);
Assertions.assertNotNull(factory.build(publisherConfiguration));
}
@Test
- void build_shouldCreateRestTemplateWithSslConfiguration() throws SSLException {
+ void build_shouldCreateRestTemplateWithSslConfiguration() {
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));
+ when(publisherConfiguration.keyStorePath()).thenReturn(KEY_STORE_RESOURCE_PATH);
+ when(publisherConfiguration.keyStorePasswordPath()).thenReturn(
+ KEYSTORE_PASSWORD_RESOURCE_PATH);
+ when(publisherConfiguration.trustStorePath()).thenReturn(TRUST_STORE_RESOURCE_PATH);
+ when(publisherConfiguration.trustStorePasswordPath()).thenReturn(
+ TRUSTSTORE_PASSWORD_RESOURCE_PATH);
Assertions.assertNotNull(factory.build(publisherConfiguration));
}
-
- private String getPath(String fileName) {
- return this.getClass().getClassLoader().getResource(fileName).getPath();
- }
} \ 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/PublisherReactiveHttpClientFactoryTest.java b/rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java
index 380f8b15..55c2e233 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,7 +22,6 @@ 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;
@@ -33,14 +32,15 @@ import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
class PublisherReactiveHttpClientFactoryTest {
private DmaaPRestTemplateFactory restTemplateFactory = mock(DmaaPRestTemplateFactory.class);
- private DmaapPublisherConfiguration dmaapPublisherConfiguration = mock(DmaapPublisherConfiguration.class);
+ 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() throws SSLException {
+ void create_shouldReturnNotNullFactoryInstance() {
Assertions.assertNotNull(httpClientFactory.create(dmaapPublisherConfiguration));
}
-} \ No newline at end of file
+}