aboutsummaryrefslogtreecommitdiffstats
path: root/prh-dmaap-client/src/test
diff options
context:
space:
mode:
authorpkaras <piotr.karas@nokia.com>2018-11-06 15:23:28 +0100
committerpkaras <piotr.karas@nokia.com>2018-11-07 13:32:56 +0100
commit6fb6c473ea98375ce965aca9f34c431d722c1c04 (patch)
treeeb7694f73ad9a50fd4ab6eb064ab3189135b1d7d /prh-dmaap-client/src/test
parentf4f1318b19c90016c70a0af457020361733b69f3 (diff)
SSL setup for dmaap publisher
Change-Id: I5dbfc551e515a5f3ce23ec9ffc766ae3012a057a Issue-ID: DCAEGEN2-952 Signed-off-by: piotr.karas <piotr.karas@nokia.com>
Diffstat (limited to 'prh-dmaap-client/src/test')
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPPublisherReactiveHttpClientTest.java3
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DmaaPRestTemplateFactoryTest.java62
-rw-r--r--prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/PublisherReactiveHttpClientFactoryTest.java4
-rw-r--r--prh-dmaap-client/src/test/resources/keystore.password1
-rw-r--r--prh-dmaap-client/src/test/resources/org.onap.dcae.jksbin0 -> 4512 bytes
-rw-r--r--prh-dmaap-client/src/test/resources/org.onap.dcae.trust.jksbin0 -> 1413 bytes
-rw-r--r--prh-dmaap-client/src/test/resources/truststore.password1
7 files changed, 69 insertions, 2 deletions
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPPublisherReactiveHttpClientTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPPublisherReactiveHttpClientTest.java
index ce2f7f36..a163fb74 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPPublisherReactiveHttpClientTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DMaaPPublisherReactiveHttpClientTest.java
@@ -37,6 +37,7 @@ import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
+import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
/**
@@ -62,7 +63,7 @@ class DMaaPPublisherReactiveHttpClientTest {
when(dmaapPublisherConfigurationMock.dmaapContentType()).thenReturn("application/json");
when(dmaapPublisherConfigurationMock.dmaapTopicName()).thenReturn("unauthenticated.PNF_READY");
dmaapPublisherReactiveHttpClient =
- new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, restTemplate);
+ new DMaaPPublisherReactiveHttpClient(dmaapPublisherConfigurationMock, Mono.just(restTemplate));
}
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DmaaPRestTemplateFactoryTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DmaaPRestTemplateFactoryTest.java
new file mode 100644
index 00000000..97303b35
--- /dev/null
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/DmaaPRestTemplateFactoryTest.java
@@ -0,0 +1,62 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * 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.prh.service.producer;
+
+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.prh.config.DmaapPublisherConfiguration;
+
+
+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 DmaapPublisherConfiguration publisherConfiguration = mock(DmaapPublisherConfiguration.class);
+ private DmaaPRestTemplateFactory factory = new DmaaPRestTemplateFactory();
+
+ @Test
+ void build_shouldCreateRestTemplateWithoutSslConfiguration() {
+ when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(false);
+
+ Assertions.assertNotNull(factory.build(publisherConfiguration).block());
+ }
+
+ @Test
+ 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));
+
+ Assertions.assertNotNull(factory.build(publisherConfiguration).block());
+ }
+
+ private String getPath(String fileName) {
+ return this.getClass().getClassLoader().getResource(fileName).getPath();
+ }
+} \ No newline at end of file
diff --git a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/PublisherReactiveHttpClientFactoryTest.java b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/PublisherReactiveHttpClientFactoryTest.java
index 3acfde9d..764d5788 100644
--- a/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/PublisherReactiveHttpClientFactoryTest.java
+++ b/prh-dmaap-client/src/test/java/org/onap/dcaegen2/services/prh/service/producer/PublisherReactiveHttpClientFactoryTest.java
@@ -29,8 +29,10 @@ import org.onap.dcaegen2.services.prh.config.DmaapPublisherConfiguration;
class PublisherReactiveHttpClientFactoryTest {
+ private DmaaPRestTemplateFactory restTemplateFactory = mock(DmaaPRestTemplateFactory.class);
private DmaapPublisherConfiguration dmaapPublisherConfiguration = mock(DmaapPublisherConfiguration.class);
- private PublisherReactiveHttpClientFactory httpClientFactory = new PublisherReactiveHttpClientFactory();
+ private PublisherReactiveHttpClientFactory httpClientFactory =
+ new PublisherReactiveHttpClientFactory(restTemplateFactory);
@Test
void create_shouldReturnNotNullFactoryInstance() {
diff --git a/prh-dmaap-client/src/test/resources/keystore.password b/prh-dmaap-client/src/test/resources/keystore.password
new file mode 100644
index 00000000..39823872
--- /dev/null
+++ b/prh-dmaap-client/src/test/resources/keystore.password
@@ -0,0 +1 @@
+mYHC98!qX}7h?W}jRv}MIXTJ \ No newline at end of file
diff --git a/prh-dmaap-client/src/test/resources/org.onap.dcae.jks b/prh-dmaap-client/src/test/resources/org.onap.dcae.jks
new file mode 100644
index 00000000..e74ce64f
--- /dev/null
+++ b/prh-dmaap-client/src/test/resources/org.onap.dcae.jks
Binary files differ
diff --git a/prh-dmaap-client/src/test/resources/org.onap.dcae.trust.jks b/prh-dmaap-client/src/test/resources/org.onap.dcae.trust.jks
new file mode 100644
index 00000000..10103cfb
--- /dev/null
+++ b/prh-dmaap-client/src/test/resources/org.onap.dcae.trust.jks
Binary files differ
diff --git a/prh-dmaap-client/src/test/resources/truststore.password b/prh-dmaap-client/src/test/resources/truststore.password
new file mode 100644
index 00000000..168e64bd
--- /dev/null
+++ b/prh-dmaap-client/src/test/resources/truststore.password
@@ -0,0 +1 @@
+*TQH?Lnszprs4LmlAj38yds( \ No newline at end of file