2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
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=========================================================
21 package org.onap.crud.service;
23 import com.google.gson.JsonArray;
24 import com.google.gson.JsonElement;
25 import com.google.gson.JsonObject;
27 import org.junit.Test;
29 import java.util.ArrayList;
30 import java.util.List;
35 public class BulkPayloadTest {
38 public void testBulkPayload() throws Exception {
39 BulkPayload p = new BulkPayload();
40 JsonObject root = new JsonObject();
41 JsonArray vertices = new JsonArray();
42 JsonObject v1 = new JsonObject();
43 JsonObject v2 = new JsonObject();
44 JsonObject prop = new JsonObject();
46 prop.addProperty("p1", "value1");
47 prop.addProperty("p2", "value2");
54 root.add("objects", vertices);
56 String s = "{\"objects\":[{\"v1\":{\"p1\":\"value1\",\"p2\":\"value2\"}},{\"v2\":{\"p1\":\"value1\",\"p2\":\"value2\"}}]}";
58 p = BulkPayload.fromJson(s);
60 List<JsonElement> po = p.getObjects();
61 List<String> ids = new ArrayList<String>();
62 for (JsonElement e : po) {
63 Set<Map.Entry<String, JsonElement>> entries = e.getAsJsonObject().entrySet();
65 for (Map.Entry<String, JsonElement> entry : entries) {
66 ids.add(entry.getKey());
70 System.out.println("root: " + root.toString());
71 System.out.println("payload ids: " + ids.toString());