Apply multiplicity Rule upon Edge creation
[aai/gizmo.git] / src / test / java / org / onap / crud / service / BulkPayloadTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.crud.service;
22
23 import com.google.gson.JsonArray;
24 import com.google.gson.JsonElement;
25 import com.google.gson.JsonObject;
26
27 import org.junit.Test;
28 import org.onap.crud.parser.BulkPayload;
29 import java.util.ArrayList;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.Set;
33
34
35 public class BulkPayloadTest {
36
37   @Test
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();
45
46     prop.addProperty("p1", "value1");
47     prop.addProperty("p2", "value2");
48     v1.add("v1", prop);
49     v2.add("v2", prop);
50
51     vertices.add(v1);
52     vertices.add(v2);
53
54     root.add("objects", vertices);
55
56     String s = "{\"objects\":[{\"v1\":{\"p1\":\"value1\",\"p2\":\"value2\"}},{\"v2\":{\"p1\":\"value1\",\"p2\":\"value2\"}}]}";
57
58     p = BulkPayload.fromJson(s);
59
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();
64
65       for (Map.Entry<String, JsonElement> entry : entries) {
66         ids.add(entry.getKey());
67       }
68     }
69
70     System.out.println("root: " + root.toString());
71     System.out.println("payload ids: " + ids.toString());
72   }
73 }