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.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
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;
32 import java.io.IOException;
34 import org.junit.Test;
35 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
36 import org.onap.clamp.clds.util.ResourceFileUtil;
39 * This class tests the SDC Controller config.
41 public class SdcSingleControllerConfigurationTest {
43 private SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, String sdcControllerName)
44 throws JsonParseException, JsonMappingException, IOException {
45 JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName),
47 SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration(
48 jsonNode, sdcControllerName);
49 return sdcSingleControllerConfiguration;
53 public final void testTheInit() throws SdcParametersException, IOException {
54 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
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());
70 @Test(expected = SdcParametersException.class)
71 public final void testAllRequiredParameters() throws JsonParseException, JsonMappingException, IOException {
72 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
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");
81 public final void testConsumerGroupWithNull() throws JsonParseException, JsonMappingException, IOException {
82 SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json",
84 assertTrue(sdcConfig.getConsumerGroup() == null);