dd60d27964998f44a0d84169a01cd525405f4370
[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.assertTrue;
26 import static org.junit.Assert.fail;
27
28 import com.fasterxml.jackson.core.JsonParseException;
29 import com.fasterxml.jackson.databind.JsonMappingException;
30 import com.fasterxml.jackson.databind.JsonNode;
31 import com.fasterxml.jackson.databind.ObjectMapper;
32
33 import java.io.IOException;
34
35 import org.junit.Test;
36 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
37 import org.onap.clamp.clds.util.ResourceFileUtil;
38
39 /**
40  * This class tests the SDC Controller config.
41  */
42 public class SdcSingleControllerConfigurationTest {
43
44     private SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, String sdcControllerName)
45             throws JsonParseException, JsonMappingException, IOException {
46         JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
47                 JsonNode.class);
48         SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
49                 jsonNode, sdcControllerName);
50         return sdcSingleControllerConfiguration;
51     }
52
53     @Test
54     public final void testTheInit() throws SdcParametersException, IOException {
55         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
56                 "sdc-controller1");
57         assertEquals("User", sdcConfig.getUser());
58         assertEquals("ThePassword", sdcConfig.getPassword());
59         assertEquals("consumerGroup", sdcConfig.getConsumerGroup());
60         assertEquals("consumerId", sdcConfig.getConsumerID());
61         assertEquals("environmentName", sdcConfig.getEnvironmentName());
62         assertEquals("hostname", sdcConfig.getAsdcAddress());
63         assertEquals(10, sdcConfig.getPollingInterval());
64         assertEquals(30, sdcConfig.getPollingTimeout());
65         assertEquals(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST.size(),
66                 sdcConfig.getRelevantArtifactTypes().size());
67         assertTrue(sdcConfig.activateServerTLSAuth());
68         assertEquals("ThePassword", sdcConfig.getKeyStorePassword());
69         assertArrayEquals(new String[] {
70                 "localhost"
71         }, sdcConfig.getMsgBusAddress().toArray());
72     }
73
74     @Test(expected = SdcParametersException.class)
75     public final void testAllRequiredParameters() throws JsonParseException, JsonMappingException, IOException {
76         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
77                 "sdc-controller1");
78         // No exception should be raised
79         sdcConfig.testAllRequiredParameters();
80         sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-bad.json", "sdc-controller1");
81         fail("Should have raised an exception");
82     }
83
84     @Test(expected = SdcParametersException.class)
85     public final void testAllRequiredParametersAddresses()
86             throws JsonParseException, JsonMappingException, IOException {
87         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration(
88                 "clds/sdc-controller-config-bad-address.json", "sdc-controller1");
89         sdcConfig.testAllRequiredParameters();
90         fail("Should have raised an exception");
91     }
92
93     @Test
94     public final void testConsumerGroupWithNull() throws JsonParseException, JsonMappingException, IOException {
95         SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
96                 "sdc-controller1");
97         assertTrue(sdcConfig.getConsumerGroup() == null);
98     }
99 }