Update SDC library
[clamp.git] / src / test / java / org / onap / clamp / clds / config / sdc / SdcSingleControllerConfigurationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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  */
20
21 package org.onap.clamp.clds.config.sdc;
22
23 import static org.junit.Assert.assertArrayEquals;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.assertTrue;
27 import static org.junit.Assert.fail;
28
29 import com.fasterxml.jackson.core.JsonParseException;
30 import com.fasterxml.jackson.databind.JsonMappingException;
31 import com.fasterxml.jackson.databind.JsonNode;
32 import com.fasterxml.jackson.databind.ObjectMapper;
33
34 import java.io.IOException;
35
36 import org.junit.Test;
37 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
38 import org.onap.clamp.clds.util.ResourceFileUtil;
39
40 /**
41  * This class tests the SDC Controller config.
42  */
43 public class SdcSingleControllerConfigurationTest {
44
45     private SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, String sdcControllerName)
46             throws JsonParseException, JsonMappingException, IOException {
47         JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
48                 JsonNode.class);
49         SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
50                 jsonNode, sdcControllerName);
51         return sdcSingleControllerConfiguration;
52     }
53
54     @Test
55     public final void testTheInit() throws SdcParametersException, IOException {
56         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
57                 "sdc-controller1");
58         assertEquals("User", sdcConfig.getUser());
59         assertEquals("ThePassword", sdcConfig.getPassword());
60         assertEquals("consumerGroup", sdcConfig.getConsumerGroup());
61         assertEquals("consumerId", sdcConfig.getConsumerID());
62         assertEquals("environmentName", sdcConfig.getEnvironmentName());
63         assertEquals("hostname:8080", sdcConfig.getAsdcAddress());
64         assertEquals(10, sdcConfig.getPollingInterval());
65         assertEquals(30, sdcConfig.getPollingTimeout());
66         assertEquals(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST.size(),
67                 sdcConfig.getRelevantArtifactTypes().size());
68         assertTrue(sdcConfig.activateServerTLSAuth());
69         assertEquals("ThePassword", sdcConfig.getKeyStorePassword());
70         assertArrayEquals(new String[] {
71                 "localhost"
72         }, sdcConfig.getMsgBusAddress().toArray());
73     }
74
75     @Test(expected = SdcParametersException.class)
76     public final void testAllRequiredParameters() throws JsonParseException, JsonMappingException, 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()
87             throws JsonParseException, JsonMappingException, IOException {
88         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration(
89                 "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1");
90         sdcConfig.testAllRequiredParameters();
91         assertNull(sdcConfig.getKeyStorePassword());
92     }
93
94     @Test
95     public final void testConsumerGroupWithNull() throws JsonParseException, JsonMappingException, IOException {
96         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
97                 "sdc-controller1");
98         assertTrue(sdcConfig.getConsumerGroup() == null);
99     }
100 }