80cf2243bb264827424f1cd8fc3108cc00637aa7
[dcaegen2/services/sdk.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * DCAEGEN2-SERVICES-SDK
4  * ================================================================================
5  * Copyright (C) 2018-2019 NOKIA Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.service.producer;
22
23 import static org.mockito.Mockito.mock;
24 import static org.mockito.Mockito.when;
25 import org.junit.jupiter.api.Assertions;
26 import org.junit.jupiter.api.Test;
27 import org.onap.dcaegen2.services.sdk.rest.services.dmaap.client.config.DmaapPublisherConfiguration;
28
29
30 class DmaaPRestTemplateFactoryTest {
31
32     private static final String KEY_STORE_RESOURCE_PATH = "/org.onap.dcae.jks";
33     private static final String KEYSTORE_PASSWORD_RESOURCE_PATH = "/keystore.password";
34     private static final String TRUSTSTORE_PASSWORD_RESOURCE_PATH = "/truststore.password";
35     private static final String TRUST_STORE_RESOURCE_PATH = "/org.onap.dcae.trust.jks";
36     private DmaapPublisherConfiguration publisherConfiguration = mock(DmaapPublisherConfiguration.class);
37     private DmaaPRestTemplateFactory factory = new DmaaPRestTemplateFactory();
38
39     @Test
40     void build_shouldCreateRestTemplateWithoutSslConfiguration(){
41         when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(false);
42
43         Assertions.assertNotNull(factory.build(publisherConfiguration));
44     }
45
46     @Test
47     void build_shouldCreateRestTemplateWithSslConfiguration() {
48         when(publisherConfiguration.enableDmaapCertAuth()).thenReturn(true);
49         when(publisherConfiguration.keyStorePath()).thenReturn(KEY_STORE_RESOURCE_PATH);
50         when(publisherConfiguration.keyStorePasswordPath()).thenReturn(
51                 KEYSTORE_PASSWORD_RESOURCE_PATH);
52         when(publisherConfiguration.trustStorePath()).thenReturn(TRUST_STORE_RESOURCE_PATH);
53         when(publisherConfiguration.trustStorePasswordPath()).thenReturn(
54                 TRUSTSTORE_PASSWORD_RESOURCE_PATH);
55
56         Assertions.assertNotNull(factory.build(publisherConfiguration));
57     }
58 }