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;
31 import org.onap.clamp.clds.AbstractIT;
32 import org.onap.clamp.clds.client.req.SdcReq;
33 import org.onap.clamp.clds.model.CldsAsdcServiceDetail;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.junit.runner.RunWith;
37 import org.springframework.boot.test.context.SpringBootTest;
38 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
39 import org.springframework.test.context.junit4.SpringRunner;
41 import java.io.IOException;
44 * Test ASDC API - stand alone (except for some config).
45 * Replicates getAsdcServices and getAsdcServicesByUUID in the CldsService
46 * Adds test of putting putting an artifact to VF.
47 * TODO Also needs update and perhaps delete tests.
49 @RunWith(SpringRunner.class)
50 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
51 public class PropJsonBuilderIT extends AbstractIT {
53 private String globalPropsPartial;
54 private ObjectMapper mapper;
57 public void setUp() throws IOException {
58 String url = refProp.getStringValue("asdc.serviceUrl");
59 String catalogUrl = refProp.getStringValue("asdc.catalog.url");
60 String basicAuth = SdcReq.getAsdcBasicAuth(refProp);
61 System.out.println("value of string and basicAuth:" + url + basicAuth);
62 CldsAsdcServiceDetail cldsservicedetail = new CldsAsdcServiceDetail();
63 // cldsservicedetail.set
64 String globalProps = refProp.getStringValue("globalPropsTest");
65 globalPropsPartial = refProp.getStringValue("globalPropsPartialTest");
66 mapper = new ObjectMapper();
70 * List services from ASDC.
71 * List meta data for a particular service from ASDC.
72 * Test uploading artifact to a VF in ASDC.
75 public void testAsdc() throws Exception {
76 // String createEmptySharedObject = createEmptySharedObject();
77 // System.out.println("value of emptySharedObject:" + createEmptySharedObject);
79 System.out.println(createTestEmptySharedObject());
82 private void sampleJsonObject() throws JsonProcessingException {
83 ArrayNode arrayNode = mapper.createArrayNode();
86 * Create three JSON Objects objectNode1, objectNode2, objectNode3
87 * Add all these three objects in the array
90 ObjectNode objectNode1 = mapper.createObjectNode();
91 objectNode1.put("bookName", "Java");
92 objectNode1.put("price", "100");
94 ObjectNode objectNode2 = mapper.createObjectNode();
95 objectNode2.put("bookName", "Spring");
96 objectNode2.put("price", "200");
98 ObjectNode objectNode3 = mapper.createObjectNode();
99 objectNode3.put("bookName", "Liferay");
100 objectNode3.put("price", "500");
103 * Array contains JSON Objects
105 arrayNode.add(objectNode1);
106 arrayNode.add(objectNode2);
107 arrayNode.add(objectNode3);
110 * We can directly write the JSON in the console.
111 * But it wont be pretty JSON String
113 System.out.println(arrayNode.toString());
116 * To make the JSON String pretty use the below code
118 System.out.println(mapper.writerWithDefaultPrettyPrinter().writeValueAsString(arrayNode));
121 private String createEmptySharedObject() throws JsonProcessingException {
136 ObjectNode emptyObjectNode = mapper.createObjectNode();
137 emptyObjectNode.put("", "");
138 ObjectNode vfObjectNode = mapper.createObjectNode();
139 vfObjectNode.putPOJO("vf", emptyObjectNode);
140 ObjectNode locationObjectNode = mapper.createObjectNode();
141 locationObjectNode.putPOJO("location", emptyObjectNode);
142 ObjectNode alarmConditionObjectNode = mapper.createObjectNode();
143 alarmConditionObjectNode.putPOJO("alarmCondition", emptyObjectNode);
144 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
145 ArrayNode samArrayNode = mapper.createArrayNode();
146 samArrayNode.add(vfObjectNode);
147 samArrayNode.add(locationObjectNode);
148 samArrayNode.add(alarmConditionObjectNode);
149 emptyServiceObjectNode.putPOJO("", samArrayNode);
154 * "DCAE_CLAMP_DEMO3 1": "DCAE_CLAMP_DEMO3"
158 ObjectNode vfObjectNode2 = mapper.createObjectNode();
159 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
160 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
161 ArrayNode vfArrayNode = mapper.createArrayNode();
162 vfArrayNode.add(emptyObjectNode);
163 vfArrayNode.add(dcaeClampDemo3Node);
164 vfObjectNode2.putPOJO("vf", vfArrayNode);
168 "SNDGCA64": "San Diego SAN3",
169 "ALPRGAED": "Alpharetta PDK1",
170 "LSLEILAA": "Lisle DPA3"
173 ObjectNode locationObjectNode2 = mapper.createObjectNode();
174 ObjectNode sandiegoLocationNode = mapper.createObjectNode();
175 sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3");
176 ObjectNode alpharettaNode = mapper.createObjectNode();
177 alpharettaNode.put("ALPRGAED", "Alpharetta PDK1");
178 ArrayNode locationArrayNode = mapper.createArrayNode();
179 locationArrayNode.add(emptyObjectNode);
180 locationArrayNode.add(sandiegoLocationNode);
181 locationArrayNode.add(alpharettaNode);
182 locationObjectNode2.putPOJO("location", locationArrayNode);
185 * "alarmCondition": {
186 "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation will soon be started",
187 "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto Export Backup Failed",
189 ObjectNode alarmConditionObjectNode2 = mapper.createObjectNode();
190 ObjectNode alamrCondition1 = mapper.createObjectNode();
191 alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started");
192 ObjectNode alarmConditon2 = mapper.createObjectNode();
193 alarmConditon2.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed");
194 ArrayNode alarmArrayNode = mapper.createArrayNode();
195 alarmArrayNode.add(emptyObjectNode);
196 alarmArrayNode.add(alamrCondition1);
197 alarmArrayNode.add(alarmConditon2);
198 alarmConditionObjectNode2.putPOJO("alarmCondition", alarmArrayNode);
200 ArrayNode byServiceIdArrayNode = mapper.createArrayNode();
201 byServiceIdArrayNode.add(vfObjectNode2);
202 byServiceIdArrayNode.add(locationObjectNode2);
203 byServiceIdArrayNode.add(alarmConditionObjectNode2);
205 ObjectNode byServiceIdNode = mapper.createObjectNode();
206 byServiceIdNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", byServiceIdArrayNode);
208 ArrayNode byServiceBasicArrayNode = mapper.createArrayNode();
209 byServiceBasicArrayNode.add(emptyServiceObjectNode);
210 byServiceBasicArrayNode.add(byServiceIdNode);
212 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
214 byServiceBasicObjetNode.putPOJO("byService", byServiceBasicArrayNode);
222 "03596c12-c7e3-44b7-8994-5cdfeda8afdd": {
231 ObjectNode byVfCBasicNode = mapper.createObjectNode();
232 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
233 ObjectNode vfCObjectNode = mapper.createObjectNode();
234 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
235 ObjectNode vfcIdObjectNode = mapper.createObjectNode();
236 vfcIdObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", vfCObjectNode);
237 ArrayNode emptyvfcArrayNode = mapper.createArrayNode();
238 emptyvfcArrayNode.add(vfCObjectNode);
239 emptyvfcArrayNode.add(vfcIdObjectNode);
240 emptyvfcobjectNode.putPOJO("", emptyvfcArrayNode);
242 byVfCBasicNode.putPOJO("byVf", emptyvfcobjectNode);
244 ArrayNode finalSharedArrayObject = mapper.createArrayNode();
246 finalSharedArrayObject.add(byServiceBasicObjetNode);
247 finalSharedArrayObject.add(byVfCBasicNode);
249 ObjectNode finalSharedObjectNode = mapper.createObjectNode();
250 finalSharedObjectNode.putPOJO("shared", finalSharedArrayObject);
252 System.out.println("value :" + finalSharedObjectNode.toString());
253 String testFinal = finalSharedObjectNode.toString();
254 testFinal = testFinal.replaceFirst("\\{", ",");
255 return globalPropsPartial + testFinal;
258 private String createTestEmptySharedObject() throws IOException {
259 String locationStringValue = refProp.getStringValue("ui.location.default");
260 String alarmStringValue = refProp.getStringValue("ui.alarm.default");
262 ObjectNode locationJsonNode = (ObjectNode) mapper.readValue(locationStringValue, JsonNode.class);
263 ObjectNode alarmStringJsonNode = (ObjectNode) mapper.readValue(alarmStringValue, JsonNode.class);
277 ObjectNode emptyObjectNode = mapper.createObjectNode();
278 emptyObjectNode.put("", "");
279 ObjectNode vfObjectNode = mapper.createObjectNode();
280 vfObjectNode.putPOJO("vf", emptyObjectNode);
281 vfObjectNode.putPOJO("location", emptyObjectNode);
282 vfObjectNode.putPOJO("alarmCondition", emptyObjectNode);
283 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
284 emptyServiceObjectNode.putPOJO("", vfObjectNode);
289 * "DCAE_CLAMP_DEMO3 1": "DCAE_CLAMP_DEMO3"
293 ObjectNode vfObjectNode2 = mapper.createObjectNode();
294 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
295 dcaeClampDemo3Node.put("", "");
296 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
297 vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node);
301 "SNDGCA64": "San Diego SAN3",
302 "ALPRGAED": "Alpharetta PDK1",
303 "LSLEILAA": "Lisle DPA3"
306 // ObjectNode sandiegoLocationNode = mapper.createObjectNode();
307 // sandiegoLocationNode.put("SNDGCA64","San Diego SAN3");
308 // sandiegoLocationNode.put("ALPRGAED","Alpharetta PDK1");
309 vfObjectNode2.putPOJO("location", locationJsonNode);
312 * "alarmCondition": {
313 "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation will soon be started",
314 "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto Export Backup Failed",
316 // ObjectNode alamrCondition1 = mapper.createObjectNode();
317 // alamrCondition1.put("A+Fallback+Operation+will+soon+be+started","A Fallback Operation will soon be started");
318 // alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed","BRM, Scheduled Backup Failed");
319 vfObjectNode2.putPOJO("alarmCondition", alarmStringJsonNode);
320 emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2);
321 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
322 byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode);
330 "03596c12-c7e3-44b7-8994-5cdfeda8afdd": {
339 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
340 ObjectNode vfCObjectNode = mapper.createObjectNode();
341 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
342 ObjectNode subVfCObjectNode = mapper.createObjectNode();
343 subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
344 vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode);
345 emptyvfcobjectNode.putPOJO("", vfCObjectNode);
346 byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
348 ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class);
350 readTree.putPOJO("shared", byServiceBasicObjetNode);
351 System.out.println("valuie of objNode:" + readTree);
352 return readTree.toString();
355 private String createCldsSharedObject(CldsAsdcServiceDetail cldsAsdcServiceDetail) throws IOException {
369 ObjectNode emptyObjectNode = mapper.createObjectNode();
370 emptyObjectNode.put("", "");
371 ObjectNode vfObjectNode = mapper.createObjectNode();
372 vfObjectNode.putPOJO("vf", emptyObjectNode);
373 vfObjectNode.putPOJO("location", emptyObjectNode);
374 vfObjectNode.putPOJO("alarmCondition", emptyObjectNode);
375 ObjectNode emptyServiceObjectNode = mapper.createObjectNode();
376 emptyServiceObjectNode.putPOJO("", vfObjectNode);
381 * "DCAE_CLAMP_DEMO3 1": "DCAE_CLAMP_DEMO3"
385 ObjectNode vfObjectNode2 = mapper.createObjectNode();
386 ObjectNode dcaeClampDemo3Node = mapper.createObjectNode();
387 dcaeClampDemo3Node.put("", "");
388 dcaeClampDemo3Node.put("DCAE_CLAMP_DEMO3", "DCAE_CLAMP_DEMO3");
389 vfObjectNode2.putPOJO("vf", dcaeClampDemo3Node);
393 "SNDGCA64": "San Diego SAN3",
394 "ALPRGAED": "Alpharetta PDK1",
395 "LSLEILAA": "Lisle DPA3"
398 ObjectNode sandiegoLocationNode = mapper.createObjectNode();
399 sandiegoLocationNode.put("SNDGCA64", "San Diego SAN3");
400 sandiegoLocationNode.put("ALPRGAED", "Alpharetta PDK1");
401 vfObjectNode2.putPOJO("location", sandiegoLocationNode);
404 * "alarmCondition": {
405 "A+Fallback+Operation+will+soon+be+started": "A Fallback Operation will soon be started",
406 "BRM%2C+Auto+Export+Backup+Failed": "BRM, Auto Export Backup Failed",
408 ObjectNode alamrCondition1 = mapper.createObjectNode();
409 alamrCondition1.put("A+Fallback+Operation+will+soon+be+started", "A Fallback Operation will soon be started");
410 alamrCondition1.put("BRM%2C+Scheduled+Backup+Failed", "BRM, Scheduled Backup Failed");
411 vfObjectNode2.putPOJO("alarmCondition", alamrCondition1);
412 emptyServiceObjectNode.putPOJO("c989a551-69f7-4b30-b10a-2e85bb227c30", vfObjectNode2);
413 ObjectNode byServiceBasicObjetNode = mapper.createObjectNode();
414 byServiceBasicObjetNode.putPOJO("byService", emptyServiceObjectNode);
422 "03596c12-c7e3-44b7-8994-5cdfeda8afdd": {
431 ObjectNode emptyvfcobjectNode = mapper.createObjectNode();
432 ObjectNode vfCObjectNode = mapper.createObjectNode();
433 vfCObjectNode.putPOJO("vfC", emptyObjectNode);
434 ObjectNode subVfCObjectNode = mapper.createObjectNode();
435 subVfCObjectNode.putPOJO("vfc", emptyObjectNode);
436 vfCObjectNode.putPOJO("03596c12-c7e3-44b7-8994-5cdfeda8afdd", subVfCObjectNode);
437 emptyvfcobjectNode.putPOJO("", vfCObjectNode);
438 byServiceBasicObjetNode.putPOJO("byVf", emptyvfcobjectNode);
440 ObjectNode readTree = (ObjectNode) mapper.readValue(globalPropsPartial, JsonNode.class);
442 readTree.putPOJO("shared", byServiceBasicObjetNode);
443 System.out.println("valuie of objNode:" + readTree);
444 return readTree.toString();