2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
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.Assert.assertTrue;
24 import static org.junit.Assert.fail;
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.List;
29 import org.junit.Test;
30 import org.mockito.Mockito;
31 import org.onap.aai.babel.service.data.BabelArtifact;
32 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
33 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
34 import org.openecomp.sdc.api.notification.INotificationData;
35 import org.powermock.api.mockito.PowerMockito;
38 * Tests {@link BabelArtifactConverter}
40 public class BabelArtifactConverterTest {
42 @Test(expected = NullPointerException.class)
43 public void convert_nullToscaFiles() throws BabelArtifactParsingException {
44 new BabelArtifactConverter().convertToModel(null);
45 fail("An instance of ArtifactGenerationException should have been thrown");
49 public void convert_emptyToscaFiles() throws BabelArtifactParsingException {
50 assertTrue("Nothing should have been returned",
51 new BabelArtifactConverter().convertToModel(new ArrayList<>()).isEmpty());
52 PowerMockito.verifyStatic(Mockito.times(1));
55 @Test(expected = BabelArtifactParsingException.class)
56 public void convert_problemWithConvertedXML() throws IOException, BabelArtifactParsingException {
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 List<BabelArtifact> toscaArtifacts = setupTest(problemXML, data);
65 new BabelArtifactConverter().convertToModel(toscaArtifacts);
66 fail("An instance of ModelArtifactParsingException should have been thrown");
69 private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
70 List<BabelArtifact> toscaArtifacts = new ArrayList<>();
71 org.openecomp.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
73 BabelArtifact xmlArtifact =
74 new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml));
75 toscaArtifacts.add(xmlArtifact);
77 return toscaArtifacts;