Get rid of deprecated SslFactory 12/84612/4
authorIzabela Zawadzka <izabela.zawadzka@nokia.com>
Tue, 9 Apr 2019 06:24:18 +0000 (08:24 +0200)
committerIzabela Zawadzka <izabela.zawadzka@nokia.com>
Tue, 9 Apr 2019 09:49:02 +0000 (11:49 +0200)
Change-Id: I928d6911a2516ffbfc05e9193e5d2d8467ec2545
Signed-off-by: Izabela Zawadzka <izabela.zawadzka@nokia.com>
Issue-ID: DCAEGEN2-1408

rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/ssl/SslFactory.java [deleted file]
rest-services/dmaap-client/pom.xml
rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/ConsumerReactiveHttpClientFactory.java
rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactory.java
rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactory.java
rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactory.java
rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/utlis/SecurityKeysUtil.java [new file with mode: 0644]
rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/consumer/DMaaPReactiveWebClientFactoryTest.java
rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/DmaaPRestTemplateFactoryTest.java
rest-services/dmaap-client/src/test/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/service/producer/PublisherReactiveHttpClientFactoryTest.java

diff --git a/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/ssl/SslFactory.java b/rest-services/common-dependency/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/ssl/SslFactory.java
deleted file mode 100644 (file)
index 92de660..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * ============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.ssl;
-
-import io.netty.handler.ssl.SslContext;
-import io.netty.handler.ssl.SslContextBuilder;
-import io.netty.handler.ssl.util.InsecureTrustManagerFactory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLException;
-import javax.net.ssl.TrustManagerFactory;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.security.GeneralSecurityException;
-import java.security.KeyStore;
-
-/**
- * @deprecated org.onap.dcaegen2.services.sdk.security.ssl.SslFactory should be used instead
- */
-@Deprecated
-public class SslFactory {
-
-    private static final Logger LOGGER = LoggerFactory.getLogger(SslFactory.class);
-
-    /**
-     * Function for creating secure ssl context.
-     *
-     * @param keyStorePath - path to file with keystore
-     * @param keyStorePasswordPath - path to file with keystore password
-     * @param trustStorePath - path to file with truststore
-     * @param trustStorePasswordPath - path to file with truststore password
-     * @return configured ssl context
-     */
-    public SslContext createSecureContext(String keyStorePath,
-        String keyStorePasswordPath,
-        String trustStorePath,
-        String trustStorePasswordPath) throws SSLException {
-        LOGGER.info("Creating secure ssl context for: {} {}", keyStorePath, trustStorePath);
-        try {
-            return SslContextBuilder
-                .forClient()
-                .keyManager(keyManagerFactory(keyStorePath, loadPasswordFromFile(keyStorePasswordPath)))
-                .trustManager(trustManagerFactory(trustStorePath, loadPasswordFromFile(trustStorePasswordPath)))
-                .build();
-        } catch (GeneralSecurityException | IOException ex) {
-            throw new SSLException(ex);
-        }
-    }
-
-    /**
-     * Function for creating insecure ssl context.
-     *
-     * @return configured insecure ssl context
-     */
-    public SslContext createInsecureContext() throws SSLException {
-        LOGGER.info("Creating insecure ssl context");
-        return SslContextBuilder
-            .forClient()
-            .trustManager(InsecureTrustManagerFactory.INSTANCE)
-            .build();
-    }
-
-    private KeyManagerFactory keyManagerFactory(String path, String password)
-            throws GeneralSecurityException, IOException {
-        KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
-        kmf.init(loadKeyStoreFromFile(path, password),
-            password.toCharArray());
-        return kmf;
-    }
-
-    private TrustManagerFactory trustManagerFactory(String path, String password)
-            throws GeneralSecurityException, IOException {
-        TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
-        tmf.init(loadKeyStoreFromFile(path, password));
-        return tmf;
-    }
-
-    private KeyStore loadKeyStoreFromFile(String path, String keyStorePassword)
-            throws GeneralSecurityException, IOException {
-        KeyStore ks = KeyStore.getInstance("jks");
-        ks.load(getResource(path), keyStorePassword.toCharArray());
-        return ks;
-    }
-
-    private InputStream getResource(String path) throws FileNotFoundException {
-        return new FileInputStream(path);
-    }
-
-    private String loadPasswordFromFile(String path) throws IOException {
-        return new String(Files.readAllBytes(Paths.get(path)));
-    }
-}
index bad855b..ff5a520 100644 (file)
       </artifactId>
       <version>${project.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.onap.dcaegen2.services.sdk.security</groupId>
+      <artifactId>ssl</artifactId>
+      <version>${project.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.httpcomponents</groupId>
       <artifactId>httpclient</artifactId>
index 7fd1021..e92ad3f 100644 (file)
@@ -30,12 +30,13 @@ public class ConsumerReactiveHttpClientFactory {
 
     private final DMaaPReactiveWebClientFactory reactiveWebClientFactory;
 
-    public ConsumerReactiveHttpClientFactory(DMaaPReactiveWebClientFactory reactiveWebClientFactory) {
+    public ConsumerReactiveHttpClientFactory(
+            DMaaPReactiveWebClientFactory reactiveWebClientFactory) {
         this.reactiveWebClientFactory = reactiveWebClientFactory;
     }
 
-    public DMaaPConsumerReactiveHttpClient create(DmaapConsumerConfiguration consumerConfiguration)
-            throws SSLException {
+    public DMaaPConsumerReactiveHttpClient create(
+            DmaapConsumerConfiguration consumerConfiguration) {
         return new DMaaPConsumerReactiveHttpClient(consumerConfiguration,
                 reactiveWebClientFactory.build(consumerConfiguration));
     }
index fba6f18..3d3c54a 100644 (file)
@@ -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.
 package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.consumer;
 
 import io.netty.handler.ssl.SslContext;
-import javax.net.ssl.SSLException;
 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.ssl.SslFactory;
+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;
 
 /**
  * @author <a href="mailto:przemyslaw.wasala@nokia.com">Przemysław Wąsala</a> on 7/4/18
@@ -47,18 +48,16 @@ public class DMaaPReactiveWebClientFactory {
      * @return CloudHttpClient
      */
 
-    public CloudHttpClient build(DmaapConsumerConfiguration consumerConfiguration) throws SSLException {
+    public CloudHttpClient build(DmaapConsumerConfiguration consumerConfiguration){
         SslContext sslContext = createSslContext(consumerConfiguration);
         return new CloudHttpClient(sslContext);
     }
 
-    private SslContext createSslContext(DmaapConsumerConfiguration consumerConfiguration) throws SSLException {
+    private SslContext createSslContext(DmaapConsumerConfiguration consumerConfiguration){
         if (consumerConfiguration.enableDmaapCertAuth()) {
-            return sslFactory.createSecureContext(
-                consumerConfiguration.keyStorePath(), consumerConfiguration.keyStorePasswordPath(),
-                consumerConfiguration.trustStorePath(), consumerConfiguration.trustStorePasswordPath()
-            );
+            final SecurityKeys securityKeys = SecurityKeysUtil.fromDmappCustomConfig(consumerConfiguration);
+            return sslFactory.createSecureClientContext(securityKeys);
         }
-        return sslFactory.createInsecureContext();
+        return sslFactory.createInsecureClientContext();
     }
 }
index 765c64b..2d71760 100644 (file)
@@ -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.
 package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer;
 
 import io.netty.handler.ssl.SslContext;
-import javax.net.ssl.SSLException;
 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.ssl.SslFactory;
+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;
 
 public class DmaaPRestTemplateFactory {
 
@@ -44,18 +45,17 @@ public class DmaaPRestTemplateFactory {
      * @param publisherConfiguration - DMaaP publisher configuration object
      * @return RestTemplate with correct ssl configuration
      */
-    public CloudHttpClient build(DmaapPublisherConfiguration publisherConfiguration) throws SSLException {
+    public CloudHttpClient build(DmaapPublisherConfiguration publisherConfiguration){
         SslContext sslContext = createSslContext(publisherConfiguration);
         return new CloudHttpClient(sslContext);
     }
 
-    private SslContext createSslContext(DmaapPublisherConfiguration consumerConfiguration) throws SSLException {
+    private SslContext createSslContext(DmaapPublisherConfiguration consumerConfiguration) {
         if (consumerConfiguration.enableDmaapCertAuth()) {
-            return sslFactory.createSecureContext(
-                consumerConfiguration.keyStorePath(), consumerConfiguration.keyStorePasswordPath(),
-                consumerConfiguration.trustStorePath(), consumerConfiguration.trustStorePasswordPath()
-            );
+            final SecurityKeys securityKeys = SecurityKeysUtil
+                    .fromDmappCustomConfig(consumerConfiguration);
+            return sslFactory.createSecureClientContext(securityKeys);
         }
-        return sslFactory.createInsecureContext();
+        return sslFactory.createInsecureClientContext();
     }
 }
index 1cd3544..953a331 100644 (file)
@@ -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.
@@ -20,7 +20,6 @@
 
 package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer;
 
-import javax.net.ssl.SSLException;
 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
 import org.onap.dcaegen2.services.sdk.rest.services.model.JsonBodyBuilder;
 
@@ -31,14 +30,14 @@ public class PublisherReactiveHttpClientFactory {
     private final JsonBodyBuilder jsonBodyBuilder;
 
     public PublisherReactiveHttpClientFactory(DmaaPRestTemplateFactory restTemplateFactory,
-        JsonBodyBuilder jsonBodyBuilder) {
+            JsonBodyBuilder jsonBodyBuilder) {
         this.restTemplateFactory = restTemplateFactory;
         this.jsonBodyBuilder = jsonBodyBuilder;
     }
 
-    public DMaaPPublisherReactiveHttpClient create(DmaapPublisherConfiguration publisherConfiguration)
-        throws SSLException {
+    public DMaaPPublisherReactiveHttpClient create(
+            DmaapPublisherConfiguration publisherConfiguration) {
         return new DMaaPPublisherReactiveHttpClient(publisherConfiguration,
-            restTemplateFactory.build(publisherConfiguration), jsonBodyBuilder);
+                restTemplateFactory.build(publisherConfiguration), jsonBodyBuilder);
     }
 }
diff --git a/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/utlis/SecurityKeysUtil.java b/rest-services/dmaap-client/src/main/java/org/onap/dcaegen2/services/sdk/rest/services/dmaap/client/utlis/SecurityKeysUtil.java
new file mode 100644 (file)
index 0000000..7ee06e9
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * ============LICENSE_START=======================================================
+ * DCAEGEN2-SERVICES-SDK
+ * ================================================================================
+ * Copyright (C) 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.
+ * 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.utlis;
+
+import io.vavr.control.Try;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import org.jetbrains.annotations.NotNull;
+import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapCustomConfig;
+import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeys;
+import org.onap.dcaegen2.services.sdk.security.ssl.ImmutableSecurityKeysStore;
+import org.onap.dcaegen2.services.sdk.security.ssl.Passwords;
+import org.onap.dcaegen2.services.sdk.security.ssl.SecurityKeys;
+
+public final class SecurityKeysUtil {
+
+    private SecurityKeysUtil(){
+
+    }
+
+    @NotNull
+    public static SecurityKeys fromDmappCustomConfig(DmaapCustomConfig configuration){
+        return ImmutableSecurityKeys.builder()
+                .keyStore(ImmutableSecurityKeysStore.of(resource(configuration.keyStorePath()).get()))
+                .keyStorePassword(Passwords.fromResource(configuration.keyStorePasswordPath()))
+                .trustStore(ImmutableSecurityKeysStore.of(resource(configuration.trustStorePath()).get()))
+                .trustStorePassword(Passwords.fromResource(configuration.trustStorePasswordPath()))
+                .build();
+    }
+
+    private static Try<Path> resource(String resource) {
+        return Try.of(() -> Paths.get(Passwords.class.getResource(resource).toURI()));
+    }}
index 6fd2200..9d670c6 100644 (file)
 
 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
index cc239fa..80cf224 100644 (file)
@@ -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
index 380f8b1..55c2e23 100644 (file)
@@ -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
+}