Merge "Remove SDC query"
[clamp.git] / src / test / java / org / onap / clamp / clds / it / config / CldsReferencePropertiesItCase.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  *
22  */
23
24 package org.onap.clamp.clds.it.config;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertNull;
29 import static org.junit.Assert.assertTrue;
30
31
32 import com.google.gson.JsonElement;
33 import java.io.IOException;
34 import java.util.List;
35
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.onap.clamp.clds.config.ClampProperties;
39 import org.springframework.beans.factory.annotation.Autowired;
40 import org.springframework.boot.test.context.SpringBootTest;
41 import org.springframework.test.context.junit4.SpringRunner;
42
43 /**
44  * Test corg.onap.clamp.ClampDesigner.model.refprop package using RefProp.
45  */
46 @RunWith(SpringRunner.class)
47 @SpringBootTest
48 public class CldsReferencePropertiesItCase {
49
50     @Autowired
51     private ClampProperties refProp;
52
53     /**
54      * Test getting a value the properties in string.
55      */
56     @Test
57     public void testGetStringValue() {
58         assertEquals(refProp.getStringValue("policy.onap.name"), "DCAE");
59         assertEquals(refProp.getStringValue("policy.ms.policyNamePrefix", ""), "Config_MS_");
60         assertEquals(refProp.getStringValue("policy.ms.policyNamePrefix", "testos"), "Config_MS_");
61         assertEquals(refProp.getStringValue("policy.ms", "policyNamePrefix"), "Config_MS_");
62         assertNull(refProp.getStringValue("does.not.exist"));
63     }
64
65     @Test
66     public void shouldReturnJsonFromTemplate() throws IOException {
67         //when
68         JsonElement root = refProp.getJsonTemplate("ui.location.default");
69
70         //then
71         assertNotNull(root);
72         assertTrue(root.isJsonObject());
73         assertEquals(root.getAsJsonObject().get("DC1").getAsString(), "Data Center 1");
74     }
75
76     @Test
77     public void shouldReturnJsonFromTemplate_2() throws IOException {
78         //when
79         JsonElement root = refProp.getJsonTemplate("ui.location", "default");
80
81         //then
82         assertNotNull(root);
83         assertTrue(root.isJsonObject());
84         assertEquals(root.getAsJsonObject().get("DC1").getAsString(), "Data Center 1");
85     }
86
87     @Test
88     public void shouldReturnNullIfPropertyNotFound() throws IOException {
89         //when
90         JsonElement root = refProp.getJsonTemplate("ui.location", "");
91
92         //then
93         assertNull(root);
94     }
95
96     /**
97      * Test getting prop value as a JSON Node / template.
98      *
99      * @throws IOException
100      *         when JSON parsing fails
101      */
102     @Test
103     public void testGetFileContent() throws IOException {
104         String location = "{\n\t\"DC1\": \"Data Center 1\",\n\t\"DC2\": \"Data Center 2\",\n\t\"DC3\": \"Data Center 3\"\n}\n";
105         String content = refProp.getFileContent("ui.location.default");
106         assertEquals(location, content);
107         // Test composite key
108         content = refProp.getFileContent("ui.location", "default");
109         assertEquals(location, content);
110     }
111
112     @Test
113     public void testGetStringList() {
114         List<String> profileList = refProp.getStringList("policy.pdpUrl1", ",");
115         assertTrue(profileList.size() == 3);
116         assertTrue(profileList.get(0).trim().startsWith("http://localhost:"));
117         assertTrue(profileList.get(1).trim().equals("testpdp"));
118         assertTrue(profileList.get(2).trim().equals("alpha123"));
119     }
120 }