Convert project from AJSC to Spring Boot
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / notification / BabelArtifactConverterTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.aai.modelloader.notification;
22
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.List;
29 import org.junit.Test;
30 import org.onap.aai.babel.service.data.BabelArtifact;
31 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
32 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
33 import org.onap.sdc.api.notification.IArtifactInfo;
34 import org.onap.sdc.api.notification.INotificationData;
35
36 /**
37  * Tests {@link BabelArtifactConverter}
38  */
39 public class BabelArtifactConverterTest {
40
41     @Test(expected = NullPointerException.class)
42     public void convert_nullToscaFiles() throws BabelArtifactParsingException {
43         new BabelArtifactConverter().convertToModel(null);
44         fail("An instance of ArtifactGenerationException should have been thrown");
45     }
46
47     @Test
48     public void convert_emptyToscaFiles() throws BabelArtifactParsingException {
49         assertTrue("Nothing should have been returned",
50                 new BabelArtifactConverter().convertToModel(new ArrayList<>()).isEmpty());
51     }
52
53     @Test(expected = BabelArtifactParsingException.class)
54     public void convert_problemWithConvertedXML() throws IOException, BabelArtifactParsingException {
55         byte[] problemXML =
56                 "<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>"
57                         .getBytes();
58
59         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
60
61         List<BabelArtifact> toscaArtifacts = setupTest(problemXML, data);
62
63         new BabelArtifactConverter().convertToModel(toscaArtifacts);
64         fail("An instance of ModelArtifactParsingException should have been thrown");
65     }
66
67     private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
68         List<BabelArtifact> toscaArtifacts = new ArrayList<>();
69         IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
70
71         BabelArtifact xmlArtifact =
72                 new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml));
73         toscaArtifacts.add(xmlArtifact);
74
75         return toscaArtifacts;
76     }
77 }