97d7a19fbdc868ce0d7cd262c47baded1fbac5d3
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / util / TestGizmoTranslator.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright (c) 2017-2019 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
22 package org.onap.aai.modelloader.util;
23
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.junit.Assert.assertThat;
26
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import org.junit.Test;
31 import org.onap.aai.modelloader.gizmo.GizmoBulkPayload;
32
33 public class TestGizmoTranslator {
34
35     @Test(expected = IOException.class)
36     public void translateInvalidXml() throws IOException {
37         GizmoTranslator.translate("not valid XML");
38     }
39
40     @Test
41     public void translateXmlModel1() throws IOException {
42         GizmoBulkPayload request = createBulkRequest("src/test/resources/models/AAI-stellService-service-1.xml");
43         assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(5));
44         assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(3));
45         assertThat(request.getEdgeOperations(GizmoBulkPayload.ADD_OP).size(), is(7));
46     }
47
48     @Test
49     public void translateXmlModel2() throws IOException {
50         GizmoBulkPayload request = createBulkRequest("src/test/resources/models/l3-network-widget.xml");
51         assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(2));
52         assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(0));
53         assertThat(request.getEdgeOperations(GizmoBulkPayload.ADD_OP).size(), is(1));
54     }
55
56     @Test
57     public void translateXmlNamedQuery() throws IOException {
58         GizmoBulkPayload request = createBulkRequest("src/test/resources/models/named-query-wan-connector.xml");
59         assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(5));
60         assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(4));
61         assertThat(request.getEdgeOperations(GizmoBulkPayload.ADD_OP).size(), is(8));
62     }
63
64     private GizmoBulkPayload createBulkRequest(String filePath) throws IOException {
65         final String xmlPayload = new String(Files.readAllBytes(Paths.get(filePath)));
66         return GizmoBulkPayload.fromJson(GizmoTranslator.translate(xmlPayload));
67     }
68
69 }