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.it.config;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import com.google.gson.JsonSyntaxException;
28 import java.io.IOException;
31 import org.junit.Test;
32 import org.junit.runner.RunWith;
33 import org.onap.clamp.clds.config.sdc.SdcControllersConfiguration;
34 import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
35 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
36 import org.springframework.beans.factory.annotation.Autowired;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.test.context.junit4.SpringRunner;
39 import org.springframework.test.util.ReflectionTestUtils;
42 * This class tests the SDC Controller config.
44 @RunWith(SpringRunner.class)
46 public class SdcControllersConfigurationItCase {
49 private SdcControllersConfiguration sdcControllersConfiguration;
51 public final void loadFile(String fileName) throws IOException {
52 ReflectionTestUtils.setField(sdcControllersConfiguration, "sdcControllerFile", fileName);
53 sdcControllersConfiguration.loadConfiguration();
57 public void testGetAllDefinedControllers() throws IOException {
58 loadFile("classpath:/clds/sdc-controllers-config.json");
59 Map<String, SdcSingleControllerConfiguration> mapResult = sdcControllersConfiguration
60 .getAllDefinedControllers();
61 assertTrue(mapResult.size() == 2);
62 assertEquals("sdc-controller1", mapResult.get("sdc-controller1").getSdcControllerName());
63 assertEquals("sdc-controller2", mapResult.get("sdc-controller2").getSdcControllerName());
67 public void testGetSdcSingleControllerConfiguration() throws IOException {
68 loadFile("classpath:/clds/sdc-controllers-config.json");
69 assertEquals("sdc-controller1",
70 sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName());
71 assertEquals("sdc-controller2",
72 sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName());
75 @Test(expected = JsonSyntaxException.class)
76 public void testBadJsonLoading() throws IOException {
77 loadFile("classpath:/clds/sdc-controllers-config-bad.json");
78 fail("Should have raised an exception");
81 @Test(expected = SdcParametersException.class)
82 public void testMissingParamInJsonLoading() throws IOException {
83 loadFile("classpath:/clds/sdc-controllers-config-missing-param.json");
84 sdcControllersConfiguration.getAllDefinedControllers();
85 fail("Should have raised an exception");