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 catalogUrl = refProp.getStringValue("sdc.catalog.url");
66 String basicAuth = SdcReq.getSdcBasicAuth(refProp);
67 System.out.println("value of string and basicAuth:" + url + basicAuth);
68 CldsSdcServiceDetail cldsservicedetail = new CldsSdcServiceDetail();
69 // cldsservicedetail.set
70 String globalProps = refProp.getStringValue("globalPropsTest");
71 globalPropsPartial = refProp.getStringValue("globalPropsPartialTest");
72 mapper = new ObjectMapper();
76 * List services from SDC. List meta data for a particular service from SDC.
77 * Test uploading artifact to a VF in SDC.
80 public void testSdc() throws Exception {
81 // String createEmptySharedObject = createEmptySharedObject();
82 // System.out.println("value of emptySharedObject:" +
83 // createEmptySharedObject);
85 System.out.println(createTestEmptySharedObject());
88 private void sampleJsonObject() throws JsonProcessingException {
91 * Create three JSON Objects objectNode1, objectNode2, objectNode3. Add
92 * all these three objects in the array
94 ObjectNode objectNode1 = mapper.createObjectNode();
95 objectNode1.put("bookName", "Java");
96 objectNode1.put("price", "100");
98 ObjectNode objectNode2 = mapper.createObjectNode();
99 objectNode2.put("bookName", "Spring");
100 objectNode2.put("price", "200");
102 ObjectNode objectNode3 = mapper.createObjectNode();
103 objectNode3.put("bookName", "Liferay");
104 objectNode3.put("price", "500");
107 * Array contains JSON Objects.
109 ArrayNode arrayNode = mapper.createArrayNode();
110 arrayNode.add(objectNode1);
111 arrayNode.add(objectNode2);
112 arrayNode.add(objectNode3);
115 * We can directly write the JSON in the console. But it wont be pretty
118 System.out.println(arrayNode.toString());
121 * To make the JSON String pretty use the below code.
123 System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(arrayNode));
126 private String createEmptySharedObject() throws JsonProcessingException {
129 * Empty Object initialization. "": { "vf": { "": "" }, "location": {
130 * "": "" }, "alarmCondition": { "": "" } }
132 ObjectNode emptyObjectNode = mapper.createObjectNode();
133 emptyObjectNode.put("", "");
134 ObjectNode vfObjectNode = mapper.createObjectNode();
135 vfObjectNode.putPOJO("vf", emptyObjectNode);
136 ObjectNode locationObjectNode = mapper.createObjectNode();
137 locationObjectNode.putPOJO("location", emptyObjectNode);
138 ObjectNode alarmConditionObjectNode = mapper.createObjectNode();
139 alarmConditionObjectNode.putPOJO("alarmCondition", emptyObjectNode);
140 ArrayNode samArrayNode = mapper.createArrayNode();
141 samArrayNode.add(vfObjectNode);
142 samArrayNode.add(locationObjectNode);
143 samArrayNode.add(alarmConditionObjectNode);
144 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
145 emptyServiceObjectNode.putPOJO("", samArrayNode);
148 * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1":
149 * "DCAE_CLAMP_DEMO3" }
152 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
153 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
154 ArrayNode vfArrayNode = mapper.createArrayNode();
155 vfArrayNode.add(emptyObjectNode);
156 vfArrayNode.add(dcaeClampDemo3Node);
157 ObjectNode vfObjectNode2 = mapper.createObjectNode();
158 vfObjectNode2.putPOJO("vf", vfArrayNode);
161 * Object initialization. "location": { "SNDGCA64": "San Diego SAN3",
162 * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" },
164 ObjectNode sandiegoLocationNode = mapper.createObjectNode();
165 sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3");
166 ObjectNode alpharettaNode = mapper.createObjectNode();
167 alpharettaNode.put("ALPRGAED", "Alpharetta PDK1");
168 ArrayNode locationArrayNode = mapper.createArrayNode();
169 locationArrayNode.add(emptyObjectNode);
170 locationArrayNode.add(sandiegoLocationNode);
171 locationArrayNode.add(alpharettaNode);
172 ObjectNode locationObjectNode2 = mapper.createObjectNode();
173 locationObjectNode2.putPOJO("location", locationArrayNode);
176 * Object initialization. "alarmCondition": {
177 * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation
178 * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto
179 * Export Backup Failed",
181 ObjectNode alamrCondition1 = mapper.createObjectNode();
182 alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started");
183 ObjectNode alarmConditon2 = mapper.createObjectNode();
184 alarmConditon2.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed");
185 ArrayNode alarmArrayNode = mapper.createArrayNode();
186 alarmArrayNode.add(emptyObjectNode);
187 alarmArrayNode.add(alamrCondition1);
188 alarmArrayNode.add(alarmConditon2);
189 ObjectNode alarmConditionObjectNode2 = mapper.createObjectNode();
190 alarmConditionObjectNode2.putPOJO("alarmCondition", alarmArrayNode);
192 ArrayNode byServiceIdArrayNode = mapper.createArrayNode();
193 byServiceIdArrayNode.add(vfObjectNode2);
194 byServiceIdArrayNode.add(locationObjectNode2);
195 byServiceIdArrayNode.add(alarmConditionObjectNode2);
197 ObjectNode byServiceIdNode = mapper.createObjectNode();
198 byServiceIdNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", byServiceIdArrayNode);
200 ArrayNode byServiceBasicArrayNode = mapper.createArrayNode();
201 byServiceBasicArrayNode.add(emptyServiceObjectNode);
202 byServiceBasicArrayNode.add(byServiceIdNode);
204 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
206 byServiceBasicObjetNode.putPOJO("byService", byServiceBasicArrayNode);
209 * Object initialization. "byVf": { "": { "vfc": { "": "" },
210 * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } }
212 ObjectNode vfCObjectNode = mapper.createObjectNode();
213 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
214 ObjectNode vfcIdObjectNode = mapper.createObjectNode();
215 vfcIdObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", vfCObjectNode);
216 ArrayNode emptyvfcArrayNode = mapper.createArrayNode();
217 emptyvfcArrayNode.add(vfCObjectNode);
218 emptyvfcArrayNode.add(vfcIdObjectNode);
219 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
220 emptyvfcobjectNode.putPOJO("", emptyvfcArrayNode);
222 ObjectNode byVfCBasicNode = mapper.createObjectNode();
223 byVfCBasicNode.putPOJO("byVf", emptyvfcobjectNode);
225 ArrayNode finalSharedArrayObject = mapper.createArrayNode();
227 finalSharedArrayObject.add(byServiceBasicObjetNode);
228 finalSharedArrayObject.add(byVfCBasicNode);
230 ObjectNode finalSharedObjectNode = mapper.createObjectNode();
231 finalSharedObjectNode.putPOJO("shared", finalSharedArrayObject);
233 System.out.println("value :" + finalSharedObjectNode.toString());
234 String testFinal = finalSharedObjectNode.toString();
235 testFinal = testFinal.replaceFirst("\\{", ",");
236 return globalPropsPartial + testFinal;
239 private String createTestEmptySharedObject() throws IOException {
242 * Object initialization. "": { "vf": { "": "" }, "location": { "": ""
243 * }, "alarmCondition": { "": "" } }
245 ObjectNode emptyObjectNode = mapper.createObjectNode();
246 emptyObjectNode.put("", "");
247 ObjectNode vfObjectNode = mapper.createObjectNode();
248 vfObjectNode.putPOJO("vf", emptyObjectNode);
249 vfObjectNode.putPOJO("location", emptyObjectNode);
250 vfObjectNode.putPOJO("alarmCondition", emptyObjectNode);
251 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
252 emptyServiceObjectNode.putPOJO("", vfObjectNode);
255 * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1":
256 * "DCAE_CLAMP_DEMO3" }
259 ObjectNode vfObjectNode2 = mapper.createObjectNode();
260 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
261 dcaeClampDemo3Node.put("", "");
262 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
263 vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node);
266 * Object initialization. "location": { "SNDGCA64": "San Diego SAN3",
267 * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" },
269 // ObjectNode sandiegoLocationNode = mapper.createObjectNode();
270 // sandiegoLocationNode.put("SNDGCA64","San Diego SAN3");
271 // sandiegoLocationNode.put("ALPRGAED","Alpharetta PDK1");
272 String locationStringValue = refProp.getStringValue("ui.location.default");
273 ObjectNode locationJsonNode = (ObjectNode) mapper.readValue(locationStringValue, JsonNode.class);
274 vfObjectNode2.putPOJO("location", locationJsonNode);
277 * Object initialization. "alarmCondition": {
278 * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation
279 * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto
280 * Export Backup Failed",
282 // ObjectNode alamrCondition1 = mapper.createObjectNode();
283 // alamrCondition1.put("A+Fallback+Operation+will+soon+be+started","A
284 // Fallback Operation will soon be started");
285 // alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed","BRM, Scheduled
287 String alarmStringValue = refProp.getStringValue("ui.alarm.default");
288 ObjectNode alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class);
289 vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
290 emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2);
291 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
292 byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode);
295 * Object initialization. "byVf": { "": { "vfc": { "": "" },
296 * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } }
298 ObjectNode vfCObjectNode = mapper.createObjectNode();
299 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
300 ObjectNode subVfCObjectNode = mapper.createObjectNode();
301 subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
302 vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode);
303 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
304 emptyvfcobjectNode.putPOJO("", vfCObjectNode);
305 byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
307 ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class);
308 readTree.putPOJO("shared", byServiceBasicObjetNode);
309 System.out.println("valuie of objNode:" + readTree);
310 return readTree.toString();
313 private String createCldsSharedObject(CldsSdcServiceDetail CldsSdcServiceDetail) throws IOException {
315 * Object initialization. "": { "vf": { "": "" }, "location": { "": ""
316 * }, "alarmCondition": { "": "" } }
318 ObjectNode emptyObjectNode = mapper.createObjectNode();
319 emptyObjectNode.put("", "");
320 ObjectNode vfObjectNode = mapper.createObjectNode();
321 vfObjectNode.putPOJO("vf", emptyObjectNode);
322 vfObjectNode.putPOJO("location", emptyObjectNode);
323 vfObjectNode.putPOJO("alarmCondition", emptyObjectNode);
324 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
325 emptyServiceObjectNode.putPOJO("", vfObjectNode);
328 * Object initialization. "vf": { " ": " ", "DCAE_CLAMP_DEMO3 1":
329 * "DCAE_CLAMP_DEMO3" }
332 ObjectNode vfObjectNode2 = mapper.createObjectNode();
333 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
334 dcaeClampDemo3Node.put("", "");
335 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
336 vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node);
339 * Object initialization. "location": { "SNDGCA64": "San Diego SAN3",
340 * "ALPRGAED": "Alpharetta PDK1", "LSLEILAA": "Lisle DPA3" },
342 ObjectNode sandiegoLocationNode = mapper.createObjectNode();
343 sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3");
344 sandiegoLocationNode.put("ALPRGAED", "Alpharetta PDK1");
345 vfObjectNode2.putPOJO("location", sandiegoLocationNode);
348 * Object initialization. "alarmCondition": {
349 * "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation
350 * will soon be started", "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto
351 * Export Backup Failed",
353 ObjectNode alamrCondition1 = mapper.createObjectNode();
354 alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started");
355 alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed");
356 vfObjectNode2.putPOJO("alarmCondition", alamrCondition1);
357 emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2);
358 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
359 byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode);
362 * Object initialization. "byVf": { "": { "vfc": { "": "" },
363 * "03596c12-c7e3-44b7-8994-5cdfeda8afdd": { "vfc": { " ": " " } } } }
366 ObjectNode vfCObjectNode = mapper.createObjectNode();
367 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
368 ObjectNode subVfCObjectNode = mapper.createObjectNode();
369 subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
370 vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode);
371 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
372 emptyvfcobjectNode.putPOJO("", vfCObjectNode);
373 byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
375 ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class);
377 readTree.putPOJO("shared", byServiceBasicObjetNode);
378 System.out.println("valuie of objNode:" + readTree);
379 return readTree.toString();