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=========================================================
19 * Modifications copyright (c) 2018 Nokia
20 * ================================================================================
24 package org.onap.clamp.clds.config.sdc;
26 import static org.assertj.core.api.Assertions.assertThat;
27 import static org.junit.Assert.assertArrayEquals;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertNull;
30 import static org.junit.Assert.assertTrue;
31 import static org.junit.Assert.fail;
33 import com.fasterxml.jackson.core.JsonParseException;
34 import com.fasterxml.jackson.databind.JsonMappingException;
35 import com.fasterxml.jackson.databind.JsonNode;
36 import com.fasterxml.jackson.databind.ObjectMapper;
38 import java.io.IOException;
40 import org.junit.Test;
41 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
42 import org.onap.clamp.clds.util.ResourceFileUtil;
45 * This class tests the SDC Controller config.
47 public class SdcSingleControllerConfigurationTest {
49 private SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, String sdcControllerName)
51 JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
53 SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
54 jsonNode, sdcControllerName);
55 return sdcSingleControllerConfiguration;
59 public final void testTheInit() throws SdcParametersException, IOException {
60 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
62 assertEquals("User", sdcConfig.getUser());
63 assertEquals("ThePassword", sdcConfig.getPassword());
64 assertEquals("consumerGroup", sdcConfig.getConsumerGroup());
65 assertEquals("consumerId", sdcConfig.getConsumerID());
66 assertEquals("environmentName", sdcConfig.getEnvironmentName());
67 assertEquals("hostname:8080", sdcConfig.getAsdcAddress());
68 assertEquals(10, sdcConfig.getPollingInterval());
69 assertEquals(30, sdcConfig.getPollingTimeout());
71 assertThat(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST)
72 .hasSameSizeAs(sdcConfig.getRelevantArtifactTypes());
73 assertEquals("ThePassword", sdcConfig.getKeyStorePassword());
74 assertTrue(sdcConfig.activateServerTLSAuth());
75 assertThat(sdcConfig.getMsgBusAddress()).contains("localhost");
78 @Test(expected = SdcParametersException.class)
79 public final void testAllRequiredParameters() throws IOException {
80 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
82 // No exception should be raised
83 sdcConfig.testAllRequiredParameters();
84 sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-bad.json", "sdc-controller1");
85 fail("Should have raised an exception");
89 public final void testAllRequiredParametersEmptyEncrypted()
91 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration(
92 "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1");
93 sdcConfig.testAllRequiredParameters();
94 assertNull(sdcConfig.getKeyStorePassword());
98 public final void testConsumerGroupWithNull() throws IOException {
99 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
101 assertTrue(sdcConfig.getConsumerGroup() == null);