X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fmodel-loader.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fmodelloader%2Futil%2FTestGizmoTranslator.java;h=c1a862a7444a13216d0f7b850d7ab32ccc76b66e;hp=e82af47dd25ab656d39650f9d934b81a0085d511;hb=HEAD;hpb=ecdc4859a0eaf97db959b1064b1060e392fe1bf4 diff --git a/src/test/java/org/onap/aai/modelloader/util/TestGizmoTranslator.java b/src/test/java/org/onap/aai/modelloader/util/TestGizmoTranslator.java index e82af47..c1a862a 100644 --- a/src/test/java/org/onap/aai/modelloader/util/TestGizmoTranslator.java +++ b/src/test/java/org/onap/aai/modelloader/util/TestGizmoTranslator.java @@ -2,8 +2,8 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. + * Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright (c) 2017-2019 European Software Marketing Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,23 +18,31 @@ * limitations under the License. * ============LICENSE_END========================================================= */ + package org.onap.aai.modelloader.util; import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import javax.xml.parsers.ParserConfigurationException; -import org.junit.Test; + +import org.junit.jupiter.api.Test; import org.onap.aai.modelloader.gizmo.GizmoBulkPayload; -import org.xml.sax.SAXException; public class TestGizmoTranslator { @Test - public void translateXmlModel1() throws Exception { + public void translateInvalidXml() throws IOException { + assertThrows(IOException.class, () -> { + GizmoTranslator.translate("not valid XML"); + }); + } + + @Test + public void translateXmlModel1() throws IOException { GizmoBulkPayload request = createBulkRequest("src/test/resources/models/AAI-stellService-service-1.xml"); assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(5)); assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(3)); @@ -42,7 +50,7 @@ public class TestGizmoTranslator { } @Test - public void translateXmlModel2() throws Exception { + public void translateXmlModel2() throws IOException { GizmoBulkPayload request = createBulkRequest("src/test/resources/models/l3-network-widget.xml"); assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(2)); assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(0)); @@ -50,15 +58,14 @@ public class TestGizmoTranslator { } @Test - public void translateXmlNamedQuery() throws Exception { + public void translateXmlNamedQuery() throws IOException { GizmoBulkPayload request = createBulkRequest("src/test/resources/models/named-query-wan-connector.xml"); assertThat(request.getVertexOperations(GizmoBulkPayload.ADD_OP).size(), is(5)); assertThat(request.getVertexOperations(GizmoBulkPayload.EXISTS_OP).size(), is(4)); assertThat(request.getEdgeOperations(GizmoBulkPayload.ADD_OP).size(), is(8)); } - private GizmoBulkPayload createBulkRequest(String filePath) - throws IOException, ParserConfigurationException, SAXException { + private GizmoBulkPayload createBulkRequest(String filePath) throws IOException { final String xmlPayload = new String(Files.readAllBytes(Paths.get(filePath))); return GizmoBulkPayload.fromJson(GizmoTranslator.translate(xmlPayload)); }