3f0a078bb80b306d5ab63ff5330af25912a06e7c
[clamp.git] / src / test / java / org / onap / clamp / clds / config / sdc / SdcSingleControllerConfigurationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T 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  * Modifications copyright (c) 2018 Nokia
20  * ================================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.config.sdc;
25
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
31
32 import com.fasterxml.jackson.databind.JsonNode;
33 import com.fasterxml.jackson.databind.ObjectMapper;
34
35 import java.io.IOException;
36
37 import org.junit.Test;
38 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
39 import org.onap.clamp.clds.util.ResourceFileUtil;
40
41 /**
42  * This class tests the SDC Controller config.
43  */
44 public class SdcSingleControllerConfigurationTest {
45
46     public static SdcSingleControllerConfiguration loadControllerConfiguration(String fileName,
47         String sdcControllerName) throws IOException {
48         JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
49             JsonNode.class);
50         SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
51             jsonNode, sdcControllerName);
52         return sdcSingleControllerConfiguration;
53     }
54
55     @Test
56     public final void testTheInit() throws SdcParametersException, IOException {
57         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
58             "sdc-controller1");
59         assertEquals("User", sdcConfig.getUser());
60         assertEquals("ThePassword", sdcConfig.getPassword());
61         assertEquals("consumerGroup", sdcConfig.getConsumerGroup());
62         assertEquals("consumerId", sdcConfig.getConsumerID());
63         assertEquals("environmentName", sdcConfig.getEnvironmentName());
64         assertEquals("hostname:8080", sdcConfig.getAsdcAddress());
65         assertEquals(10, sdcConfig.getPollingInterval());
66         assertEquals(30, sdcConfig.getPollingTimeout());
67
68         assertThat(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST)
69             .hasSameSizeAs(sdcConfig.getRelevantArtifactTypes());
70         assertEquals("ThePassword", sdcConfig.getKeyStorePassword());
71         assertTrue(sdcConfig.activateServerTLSAuth());
72         assertThat(sdcConfig.getMsgBusAddress()).contains("localhost");
73     }
74
75     @Test(expected = SdcParametersException.class)
76     public final void testAllRequiredParameters() throws IOException {
77         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
78             "sdc-controller1");
79         // No exception should be raised
80         sdcConfig.testAllRequiredParameters();
81         sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-bad.json", "sdc-controller1");
82         fail("Should have raised an exception");
83     }
84
85     @Test
86     public final void testAllRequiredParametersEmptyEncrypted() throws IOException {
87         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration(
88             "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1");
89         sdcConfig.testAllRequiredParameters();
90         assertNull(sdcConfig.getKeyStorePassword());
91     }
92
93     @Test
94     public final void testConsumerGroupWithNull() throws IOException {
95         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
96             "sdc-controller1");
97         assertTrue(sdcConfig.getConsumerGroup() == null);
98     }
99 }