7ef734533448bf58f76b02317674aa5c799452d0
[clamp.git] / src / test / java / org / onap / clamp / clds / it / config / SdcControllersConfigurationItCase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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  */
20
21 package org.onap.clamp.clds.it.config;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
26
27 import com.google.gson.JsonSyntaxException;
28
29 import java.io.IOException;
30 import java.util.Map;
31
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.clamp.clds.config.sdc.SdcControllersConfiguration;
35 import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfiguration;
36 import org.onap.clamp.clds.exception.sdc.controller.SdcParametersException;
37 import org.springframework.beans.factory.annotation.Autowired;
38 import org.springframework.boot.test.context.SpringBootTest;
39 import org.springframework.test.context.ActiveProfiles;
40 import org.springframework.test.context.junit4.SpringRunner;
41 import org.springframework.test.util.ReflectionTestUtils;
42
43 /**
44  * This class tests the SDC Controller config.
45  */
46 @RunWith(SpringRunner.class)
47 @SpringBootTest
48 @ActiveProfiles(profiles = "clamp-default,clamp-default-user,clamp-sdc-controller")
49 public class SdcControllersConfigurationItCase {
50
51     @Autowired
52     private SdcControllersConfiguration sdcControllersConfiguration;
53
54     public final void loadFile(String fileName) throws IOException {
55         ReflectionTestUtils.setField(sdcControllersConfiguration, "sdcControllerFile", fileName);
56         sdcControllersConfiguration.loadConfiguration();
57     }
58
59     @Test
60     public void testGetAllDefinedControllers() throws IOException {
61         loadFile("classpath:/clds/sdc-controllers-config.json");
62         Map<String, SdcSingleControllerConfiguration> mapResult = sdcControllersConfiguration
63                 .getAllDefinedControllers();
64         assertTrue(mapResult.size() == 2);
65         assertEquals("sdc-controller1", mapResult.get("sdc-controller1").getSdcControllerName());
66         assertEquals("sdc-controller2", mapResult.get("sdc-controller2").getSdcControllerName());
67     }
68
69     @Test
70     public void testGetSdcSingleControllerConfiguration() throws IOException {
71         loadFile("classpath:/clds/sdc-controllers-config.json");
72         assertEquals("sdc-controller1", sdcControllersConfiguration
73                 .getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName());
74         assertEquals("sdc-controller2", sdcControllersConfiguration
75                 .getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName());
76     }
77
78     @Test(expected = JsonSyntaxException.class)
79     public void testBadJsonLoading() throws IOException {
80         loadFile("classpath:/clds/sdc-controllers-config-bad.json");
81         fail("Should have raised an exception");
82     }
83
84     @Test(expected = SdcParametersException.class)
85     public void testMissingParamInJsonLoading() throws IOException {
86         loadFile("classpath:/clds/sdc-controllers-config-missing-param.json");
87         sdcControllersConfiguration.getAllDefinedControllers();
88         fail("Should have raised an exception");
89     }
90 }