2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.onap.aai.modelloader.notification;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25 import static org.junit.jupiter.api.Assertions.fail;
27 import java.io.IOException;
28 import java.util.List;
30 import org.junit.jupiter.api.Test;
31 import org.onap.aai.babel.service.data.BabelArtifact;
32 import org.onap.aai.modelloader.entity.Artifact;
33 import org.onap.aai.modelloader.entity.ArtifactType;
34 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
35 import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
36 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
37 import org.onap.aai.modelloader.util.ArtifactTestUtils;
38 import org.onap.sdc.api.notification.IArtifactInfo;
39 import org.onap.sdc.api.notification.INotificationData;
42 * Tests {@link BabelArtifactConverter}.
44 public class TestBabelArtifactConverter {
47 public void convert_nullToscaFiles() throws BabelArtifactParsingException {
48 assertThrows(NullPointerException.class, () -> {
49 new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(null);
50 fail("An instance of ArtifactGenerationException should have been thrown");
55 public void testInvalidXml() throws IOException, BabelArtifactParsingException {
56 assertThrows(BabelArtifactParsingException.class, () -> {
58 "<model xmlns=\"http://org.openecomp.aai.inventory/v10\"><rubbish>This is some xml that should cause the model artifact parser to throw an erorr</rubbish></model>"
61 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
63 BabelArtifact toscaArtifact = setupTest(problemXml, data);
65 new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
66 fail("An instance of ModelArtifactParsingException should have been thrown");
70 private BabelArtifact setupTest(byte[] xml, INotificationData data) throws IOException {
71 IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
73 BabelArtifact xmlArtifact =
74 new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml));
80 public void convert_singleResourceFile() throws BabelArtifactParsingException, IOException {
81 INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
83 byte[] xml = new ArtifactTestUtils().loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
84 BabelArtifact toscaArtifact = setupTest(xml, data);
86 List<Artifact> modelArtifacts = new BabelArtifactConverter(new ModelArtifactParser()).convertToModel(toscaArtifact);
88 assertEquals(1, modelArtifacts.size(), "There should have been 1 artifact");
89 assertEquals(new String(xml), modelArtifacts.get(0).getPayload());
90 assertEquals(ArtifactType.MODEL, modelArtifacts.get(0).getType());