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.assertEquals;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30 import static org.junit.Assert.fail;
32 import com.google.gson.JsonObject;
33 import java.io.IOException;
34 import java.io.InputStreamReader;
35 import java.nio.charset.StandardCharsets;
36 import org.junit.Test;
37 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
38 import org.onap.clamp.clds.util.JsonUtils;
39 import org.onap.clamp.clds.util.ResourceFileUtils;
42 * This class tests the SDC Controller config.
44 public class SdcSingleControllerConfigurationTest {
47 * @param fileName file for sdc controller configuration.
48 * @param sdcControllerName sdc controller name.
49 * @return instance of SdcSingleControllerConfiguration.
51 public static SdcSingleControllerConfiguration loadControllerConfiguration(String fileName,
52 String sdcControllerName) {
54 InputStreamReader streamReader = new InputStreamReader(ResourceFileUtils.getResourceAsStream(fileName),
55 StandardCharsets.UTF_8);
56 JsonObject jsonNode = JsonUtils.GSON.fromJson(streamReader, JsonObject.class);
58 return new SdcSingleControllerConfiguration(jsonNode, sdcControllerName);
62 public final void testTheInit() throws SdcParametersException, IOException {
63 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
65 assertEquals("User", sdcConfig.getUser());
66 assertEquals("ThePassword", sdcConfig.getPassword());
67 assertEquals("consumerGroup", sdcConfig.getConsumerGroup());
68 assertEquals("consumerId", sdcConfig.getConsumerID());
69 assertEquals("environmentName", sdcConfig.getEnvironmentName());
70 assertEquals("hostname:8080", sdcConfig.getAsdcAddress());
71 assertEquals(10, sdcConfig.getPollingInterval());
72 assertEquals(30, sdcConfig.getPollingTimeout());
74 assertThat(SdcSingleControllerConfiguration.SUPPORTED_ARTIFACT_TYPES_LIST)
75 .hasSameSizeAs(sdcConfig.getRelevantArtifactTypes());
76 assertEquals("ThePassword", sdcConfig.getKeyStorePassword());
77 assertTrue(sdcConfig.activateServerTLSAuth());
78 assertThat(sdcConfig.getMsgBusAddress()).contains("localhost");
81 @Test(expected = SdcParametersException.class)
82 public final void testAllRequiredParameters() throws IOException {
83 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
85 // No exception should be raised
86 sdcConfig.testAllRequiredParameters();
87 sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-bad.json", "sdc-controller1");
88 fail("Should have raised an exception");
92 public final void testAllRequiredParametersEmptyEncrypted() throws IOException {
93 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration(
94 "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1");
95 sdcConfig.testAllRequiredParameters();
96 assertNull(sdcConfig.getKeyStorePassword());
100 public final void testConsumerGroupWithNull() throws IOException {
101 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
103 assertTrue(sdcConfig.getConsumerGroup() == null);