2 * ============LICENSE_START=======================================================
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
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=========================================================
22 package org.onap.aai.modelloader.util;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.junit.jupiter.api.Assertions.assertThrows;
28 import java.io.IOException;
29 import java.nio.file.Files;
30 import java.nio.file.Paths;
32 import org.junit.jupiter.api.Test;
33 import org.onap.aai.modelloader.gizmo.GizmoBulkPayload;
35 public class TestGizmoTranslator {
38 public void translateInvalidXml() throws IOException {
39 assertThrows(IOException.class, () -> {
40 GizmoTranslator.translate("not valid XML");
45 public void translateXmlModel1() throws IOException {
46 GizmoBulkPayload request = createBulkRequest("src/test/resources/models/AAI-stellService-service-1.xml");
47 assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(5));
48 assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(3));
49 assertThat(request.getEdgeOperations(GizmoBulkPayload.ADD_OP).size(), is(7));
53 public void translateXmlModel2() throws IOException {
54 GizmoBulkPayload request = createBulkRequest("src/test/resources/models/l3-network-widget.xml");
55 assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(2));
56 assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(0));
57 assertThat(request.getEdgeOperations(GizmoBulkPayload.ADD_OP).size(), is(1));
61 public void translateXmlNamedQuery() throws IOException {
62 GizmoBulkPayload request = createBulkRequest("src/test/resources/models/named-query-wan-connector.xml");
63 assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(5));
64 assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(4));
65 assertThat(request.getEdgeOperations(GizmoBulkPayload.ADD_OP).size(), is(8));
68 private GizmoBulkPayload createBulkRequest(String filePath) throws IOException {
69 final String xmlPayload = new String(Files.readAllBytes(Paths.get(filePath)));
70 return GizmoBulkPayload.fromJson(GizmoTranslator.translate(xmlPayload));