Configurable option to load models via Gizmo
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / util / GizmoTranslatorTest.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 European Software Marketing Ltd.
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.aai.modelloader.util;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.List;
28
29 import org.junit.Test;
30 import org.onap.aai.modelloader.gizmo.GizmoBulkPayload;
31 import org.onap.aai.modelloader.gizmo.GizmoEdgeOperation;
32 import org.onap.aai.modelloader.gizmo.GizmoVertexOperation;
33
34 public class GizmoTranslatorTest {
35     
36     @Test
37     public void translateXmlModel1() throws Exception {
38         final String XML_MODEL_FILE = "src/test/resources/models/AAI-stellService-service-1.xml";
39
40         try {
41             byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE));
42             String originalXml = new String(encoded);
43             
44             String output = GizmoTranslator.translate(originalXml);
45             System.out.println("Test1 Outgoing:\n" + output);
46             
47             GizmoBulkPayload request = GizmoBulkPayload.fromJson(output);
48             
49             List<GizmoVertexOperation> ops = request.getVertexOperations(GizmoBulkPayload.ADD_OP);
50             assertTrue(ops.size() == 5);
51             
52             ops = request.getVertexOperations(GizmoBulkPayload.EXISTS_OP);
53             assertTrue(ops.size() == 3);
54             
55             List<GizmoEdgeOperation> edgeOps = request.getEdgeOperations(GizmoBulkPayload.ADD_OP);
56             assertTrue(edgeOps.size() == 7);                 
57         } catch (Exception e) {
58             e.printStackTrace();
59             assertTrue(false);
60         }     
61     }
62     
63     @Test
64     public void translateXmlModel2() throws Exception {
65         final String XML_MODEL_FILE2 = "src/test/resources/models/l3-network-widget.xml";
66
67         try {
68             byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE2));
69             String originalXml = new String(encoded);
70             
71             String output = GizmoTranslator.translate(originalXml);
72             System.out.println("Test2 Outgoing:\n" + output);
73             
74             GizmoBulkPayload request = GizmoBulkPayload.fromJson(output);
75             
76             List<GizmoVertexOperation> ops = request.getVertexOperations(GizmoBulkPayload.ADD_OP);
77             assertTrue(ops.size() == 2);
78             
79             ops = request.getVertexOperations(GizmoBulkPayload.EXISTS_OP);
80             assertTrue(ops.size() == 0);
81             
82             List<GizmoEdgeOperation> edgeOps = request.getEdgeOperations(GizmoBulkPayload.ADD_OP);
83             assertTrue(edgeOps.size() == 1);                     
84         } catch (Exception e) {
85             e.printStackTrace();
86             assertTrue(false);
87         }     
88     }
89     
90     @Test
91     public void translateXmlNamedQuery() throws Exception {
92         final String XML_MODEL_FILE3 = "src/test/resources/models/named-query-wan-connector.xml";
93
94         try {
95             byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE3));
96             String originalXml = new String(encoded);
97             
98             String output = GizmoTranslator.translate(originalXml);
99             System.out.println("Test3 Outgoing:\n" + output);
100             
101             GizmoBulkPayload request = GizmoBulkPayload.fromJson(output);
102             
103             List<GizmoVertexOperation> ops = request.getVertexOperations(GizmoBulkPayload.ADD_OP);
104             assertTrue(ops.size() == 5);
105             
106             ops = request.getVertexOperations(GizmoBulkPayload.EXISTS_OP);
107             assertTrue(ops.size() == 4);
108             
109             List<GizmoEdgeOperation> edgeOps = request.getEdgeOperations(GizmoBulkPayload.ADD_OP);
110             assertTrue(edgeOps.size() == 8);                     
111         } catch (Exception e) {
112             e.printStackTrace();
113             assertTrue(false);
114         }     
115     }
116 }