2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.it;
26 import com.fasterxml.jackson.core.JsonProcessingException;
27 import com.fasterxml.jackson.databind.JsonNode;
28 import com.fasterxml.jackson.databind.ObjectMapper;
29 import com.fasterxml.jackson.databind.node.ArrayNode;
30 import com.fasterxml.jackson.databind.node.ObjectNode;
32 import java.io.IOException;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.onap.clamp.clds.AbstractIT;
38 import org.onap.clamp.clds.client.req.SdcReq;
39 import org.onap.clamp.clds.model.CldsSdcServiceDetail;
40 import org.springframework.boot.test.context.SpringBootTest;
41 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
42 import org.springframework.test.context.TestPropertySource;
43 import org.springframework.test.context.junit4.SpringRunner;
46 * Test SDC API - stand alone (except for some config). Replicates
47 * getSdcServices and getSdcServicesByUUID in the CldsService Adds test of
48 * putting putting an artifact to VF. TODO Also needs update and perhaps delete
51 @RunWith(SpringRunner.class)
52 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
53 @TestPropertySource(locations = "classpath:application-no-camunda.properties")
54 public class PropJsonBuilderIT extends AbstractIT {
56 private String globalPropsPartial;
57 private ObjectMapper mapper;
63 public void setUp() throws IOException {
64 String url = refProp.getStringValue("sdc.serviceUrl");
65 String basicAuth = SdcReq.getSdcBasicAuth(refProp);
66 System.out.println("value of string and basicAuth:" + url + basicAuth);
67 // cldsservicedetail.set
68 globalPropsPartial = refProp.getStringValue("globalPropsPartialTest");
69 mapper = new ObjectMapper();
73 * List services from SDC. List meta data for a particular service from SDC.
74 * Test uploading artifact to a VF in SDC.
77 public void testSdc() throws Exception {
78 // String createEmptySharedObject = createEmptySharedObject();
79 // System.out.println("value of emptySharedObject:" +
80 // createEmptySharedObject);
82 System.out.println(createTestEmptySharedObject());
85 private void sampleJsonObject() throws JsonProcessingException {
88 * Create three JSON Objects objectNode1, objectNode2, objectNode3. Add
89 * all these three objects in the array
91 ObjectNode objectNode1 = mapper.createObjectNode();
92 objectNode1.put("bookName", "Java");
93 objectNode1.put("price", "100");
95 ObjectNode objectNode2 = mapper.createObjectNode();
96 objectNode2.put("bookName", "Spring");
97 objectNode2.put("price", "200");
99 ObjectNode objectNode3 = mapper.createObjectNode();
100 objectNode3.put("bookName", "Liferay");
101 objectNode3.put("price", "500");
104 * Array contains JSON Objects.
106 ArrayNode arrayNode = mapper.createArrayNode();
107 arrayNode.add(objectNode1);
108 arrayNode.add(objectNode2);
109 arrayNode.add(objectNode3);
112 * We can directly write the JSON in the console. But it wont be pretty
115 System.out.println(arrayNode.toString());
118 * To make the JSON String pretty use the below code.
120 System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(arrayNode));
123 private String createEmptySharedObject() throws JsonProcessingException {
126 * Empty Object initialization. "": { "vf": { "": "" }, "location": {
127 * "": "" }, "alarmCondition": { "": "" } }
129 ObjectNode emptyObjectNode = mapper.createObjectNode();
130 emptyObjectNode.put("", "");
131 ObjectNode vfObjectNode = mapper.createObjectNode();
132 vfObjectNode.putPOJO("vf", emptyObjectNode);
133 ObjectNode locationObjectNode = mapper.createObjectNode();
134 locationObjectNode.putPOJO("location", emptyObjectNode);
135 ObjectNode alarmConditionObjectNode = mapper.createObjectNode();
136 alarmConditionObjectNode.putPOJO("alarmCondition", emptyObjectNode);
137 ArrayNode samArrayNode = mapper.createArrayNode();
138 samArrayNode.add(vfObjectNode);
139 samArrayNode.add(locationObjectNode);
140 samArrayNode.add(alarmConditionObjectNode);
141 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
142 emptyServiceObjectNode.putPOJO("", samArrayNode);
145 * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1":
146 * "DCAE_CLAMP_DEMO3" }
149 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
150 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
151 ArrayNode vfArrayNode = mapper.createArrayNode();
152 vfArrayNode.add(emptyObjectNode);
153 vfArrayNode.add(dcaeClampDemo3Node);
154 ObjectNode vfObjectNode2 = mapper.createObjectNode();
155 vfObjectNode2.putPOJO("vf", vfArrayNode);
158 * Object initialization. "location": { "SNDGCA64": "San Diego SAN3",
159 * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" },
161 ObjectNode sandiegoLocationNode = mapper.createObjectNode();
162 sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3");
163 ObjectNode alpharettaNode = mapper.createObjectNode();
164 alpharettaNode.put("ALPRGAED", "Alpharetta PDK1");
165 ArrayNode locationArrayNode = mapper.createArrayNode();
166 locationArrayNode.add(emptyObjectNode);
167 locationArrayNode.add(sandiegoLocationNode);
168 locationArrayNode.add(alpharettaNode);
169 ObjectNode locationObjectNode2 = mapper.createObjectNode();
170 locationObjectNode2.putPOJO("location", locationArrayNode);
173 * Object initialization. "alarmCondition": {
174 * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation
175 * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto
176 * Export Backup Failed",
178 ObjectNode alamrCondition1 = mapper.createObjectNode();
179 alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started");
180 ObjectNode alarmConditon2 = mapper.createObjectNode();
181 alarmConditon2.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed");
182 ArrayNode alarmArrayNode = mapper.createArrayNode();
183 alarmArrayNode.add(emptyObjectNode);
184 alarmArrayNode.add(alamrCondition1);
185 alarmArrayNode.add(alarmConditon2);
186 ObjectNode alarmConditionObjectNode2 = mapper.createObjectNode();
187 alarmConditionObjectNode2.putPOJO("alarmCondition", alarmArrayNode);
189 ArrayNode byServiceIdArrayNode = mapper.createArrayNode();
190 byServiceIdArrayNode.add(vfObjectNode2);
191 byServiceIdArrayNode.add(locationObjectNode2);
192 byServiceIdArrayNode.add(alarmConditionObjectNode2);
194 ObjectNode byServiceIdNode = mapper.createObjectNode();
195 byServiceIdNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", byServiceIdArrayNode);
197 ArrayNode byServiceBasicArrayNode = mapper.createArrayNode();
198 byServiceBasicArrayNode.add(emptyServiceObjectNode);
199 byServiceBasicArrayNode.add(byServiceIdNode);
201 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
203 byServiceBasicObjetNode.putPOJO("byService", byServiceBasicArrayNode);
206 * Object initialization. "byVf": { "": { "vfc": { "": "" },
207 * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } }
209 ObjectNode vfCObjectNode = mapper.createObjectNode();
210 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
211 ObjectNode vfcIdObjectNode = mapper.createObjectNode();
212 vfcIdObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", vfCObjectNode);
213 ArrayNode emptyvfcArrayNode = mapper.createArrayNode();
214 emptyvfcArrayNode.add(vfCObjectNode);
215 emptyvfcArrayNode.add(vfcIdObjectNode);
216 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
217 emptyvfcobjectNode.putPOJO("", emptyvfcArrayNode);
219 ObjectNode byVfCBasicNode = mapper.createObjectNode();
220 byVfCBasicNode.putPOJO("byVf", emptyvfcobjectNode);
222 ArrayNode finalSharedArrayObject = mapper.createArrayNode();
224 finalSharedArrayObject.add(byServiceBasicObjetNode);
225 finalSharedArrayObject.add(byVfCBasicNode);
227 ObjectNode finalSharedObjectNode = mapper.createObjectNode();
228 finalSharedObjectNode.putPOJO("shared", finalSharedArrayObject);
230 System.out.println("value :" + finalSharedObjectNode.toString());
231 String testFinal = finalSharedObjectNode.toString();
232 testFinal = testFinal.replaceFirst("\\{", ",");
233 return globalPropsPartial + testFinal;
236 private String createTestEmptySharedObject() throws IOException {
239 * Object initialization. "": { "vf": { "": "" }, "location": { "": ""
240 * }, "alarmCondition": { "": "" } }
242 ObjectNode emptyObjectNode = mapper.createObjectNode();
243 emptyObjectNode.put("", "");
244 ObjectNode vfObjectNode = mapper.createObjectNode();
245 vfObjectNode.putPOJO("vf", emptyObjectNode);
246 vfObjectNode.putPOJO("location", emptyObjectNode);
247 vfObjectNode.putPOJO("alarmCondition", emptyObjectNode);
248 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
249 emptyServiceObjectNode.putPOJO("", vfObjectNode);
252 * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1":
253 * "DCAE_CLAMP_DEMO3" }
256 ObjectNode vfObjectNode2 = mapper.createObjectNode();
257 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
258 dcaeClampDemo3Node.put("", "");
259 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
260 vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node);
263 * Object initialization. "location": { "SNDGCA64": "San Diego SAN3",
264 * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" },
266 // ObjectNode sandiegoLocationNode = mapper.createObjectNode();
267 // sandiegoLocationNode.put("SNDGCA64","San Diego SAN3");
268 // sandiegoLocationNode.put("ALPRGAED","Alpharetta PDK1");
269 String locationStringValue = refProp.getStringValue("ui.location.default");
270 ObjectNode locationJsonNode = (ObjectNode) mapper.readValue(locationStringValue, JsonNode.class);
271 vfObjectNode2.putPOJO("location", locationJsonNode);
274 * Object initialization. "alarmCondition": {
275 * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation
276 * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto
277 * Export Backup Failed",
279 // ObjectNode alamrCondition1 = mapper.createObjectNode();
280 // alamrCondition1.put("A+Fallback+Operation+will+soon+be+started","A
281 // Fallback Operation will soon be started");
282 // alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed","BRM, Scheduled
284 String alarmStringValue = refProp.getStringValue("ui.alarm.default");
285 ObjectNode alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class);
286 vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
287 emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2);
288 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
289 byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode);
292 * Object initialization. "byVf": { "": { "vfc": { "": "" },
293 * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } }
295 ObjectNode vfCObjectNode = mapper.createObjectNode();
296 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
297 ObjectNode subVfCObjectNode = mapper.createObjectNode();
298 subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
299 vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode);
300 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
301 emptyvfcobjectNode.putPOJO("", vfCObjectNode);
302 byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
304 ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class);
305 readTree.putPOJO("shared", byServiceBasicObjetNode);
306 System.out.println("valuie of objNode:" + readTree);
307 return readTree.toString();
310 private String createCldsSharedObject(CldsSdcServiceDetail CldsSdcServiceDetail) throws IOException {
312 * Object initialization. "": { "vf": { "": "" }, "location": { "": ""
313 * }, "alarmCondition": { "": "" } }
315 ObjectNode emptyObjectNode = mapper.createObjectNode();
316 emptyObjectNode.put("", "");
317 ObjectNode vfObjectNode = mapper.createObjectNode();
318 vfObjectNode.putPOJO("vf", emptyObjectNode);
319 vfObjectNode.putPOJO("location", emptyObjectNode);
320 vfObjectNode.putPOJO("alarmCondition", emptyObjectNode);
321 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
322 emptyServiceObjectNode.putPOJO("", vfObjectNode);
325 * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1":
326 * "DCAE_CLAMP_DEMO3" }
329 ObjectNode vfObjectNode2 = mapper.createObjectNode();
330 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
331 dcaeClampDemo3Node.put("", "");
332 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
333 vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node);
336 * Object initialization. "location": { "SNDGCA64": "San Diego SAN3",
337 * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" },
339 ObjectNode sandiegoLocationNode = mapper.createObjectNode();
340 sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3");
341 sandiegoLocationNode.put("ALPRGAED", "Alpharetta PDK1");
342 vfObjectNode2.putPOJO("location", sandiegoLocationNode);
345 * Object initialization. "alarmCondition": {
346 * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation
347 * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto
348 * Export Backup Failed",
350 ObjectNode alamrCondition1 = mapper.createObjectNode();
351 alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started");
352 alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed");
353 vfObjectNode2.putPOJO("alarmCondition", alamrCondition1);
354 emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2);
355 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
356 byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode);
359 * Object initialization. "byVf": { "": { "vfc": { "": "" },
360 * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } }
363 ObjectNode vfCObjectNode = mapper.createObjectNode();
364 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
365 ObjectNode subVfCObjectNode = mapper.createObjectNode();
366 subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
367 vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode);
368 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
369 emptyvfcobjectNode.putPOJO("", vfCObjectNode);
370 byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
372 ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class);
374 readTree.putPOJO("shared", byServiceBasicObjetNode);
375 System.out.println("valuie of objNode:" + readTree);
376 return readTree.toString();