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