2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.clamp.clds.config.sdc;
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;
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;
33 import java.io.IOException;
35 import org.junit.Test;
36 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
37 import org.onap.clamp.clds.util.ResourceFileUtil;
40 * This class tests the SDC Controller config.
42 public class SdcSingleControllerConfigurationTest {
44 private SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, String sdcControllerName)
45 throws JsonParseException, JsonMappingException, IOException {
46 JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
48 SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
49 jsonNode, sdcControllerName);
50 return sdcSingleControllerConfiguration;
54 public final void testTheInit() throws SdcParametersException, IOException {
55 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
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[] {
71 }, sdcConfig.getMsgBusAddress().toArray());
74 @Test(expected = SdcParametersException.class)
75 public final void testAllRequiredParameters() throws JsonParseException, JsonMappingException, IOException {
76 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
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");
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");
94 public final void testConsumerGroupWithNull() throws JsonParseException, JsonMappingException, IOException {
95 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
97 assertTrue(sdcConfig.getConsumerGroup() == null);