Improve javadoc comments and formatting
[aai/babel.git] / src / test / java / org / onap / aai / babel / parser / TestToscaParser.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright (c) 2017-2019 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
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
22 package org.onap.aai.babel.parser;
23
24 import static org.hamcrest.CoreMatchers.equalTo;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.junit.Assert.assertThat;
27
28 import java.io.IOException;
29 import java.util.HashMap;
30 import java.util.Map;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
34 import org.onap.aai.babel.testdata.CsarTest;
35 import org.onap.aai.babel.util.ArtifactTestUtils;
36 import org.onap.aai.babel.util.Resources;
37 import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator;
38 import org.onap.aai.babel.xml.generator.data.AdditionalParams;
39 import org.onap.aai.babel.xml.generator.data.GenerationData;
40
41 /**
42  * Direct tests of the {@link AaiArtifactGenerator} to improve code coverage.
43  */
44 public class TestToscaParser {
45
46     @Before
47     public void setup() {
48         new ArtifactTestUtils().setGeneratorSystemProperties();
49     }
50
51     @Test
52     public void testParserWithInvalidMappings() throws IOException, InvalidArchiveException {
53         System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_TOSCA_MAPPING_FILE,
54                 new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG));
55
56         GenerationData data = generateArtifactsFromCsarFile();
57         assertThat("Number of errors produced " + data.getErrorData(), data.getErrorData().size(), is(equalTo(1)));
58         assertThat("Number of resources generated", data.getResultData().size(), is(equalTo(0)));
59     }
60
61     @Test
62     public void testParserWithCsarFile() throws IOException, InvalidArchiveException {
63         GenerationData data = generateArtifactsFromCsarFile();
64         assertThat("Number of errors produced " + data.getErrorData(), data.getErrorData().size(), is(equalTo(0)));
65         assertThat("Number of resources generated", data.getResultData().size(), is(equalTo(2)));
66     }
67
68     /**
69      * Invoke the generator with a sample CSAR file.
70      * 
71      * @return the generated AAI Artifacts
72      * @throws InvalidArchiveException
73      *             if the test CSAR file is invalid
74      * @throws IOException
75      *             if there are I/O errors reading the CSAR content
76      */
77     private GenerationData generateArtifactsFromCsarFile() throws InvalidArchiveException, IOException {
78         Map<String, String> additionalParams = new HashMap<>();
79         additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), "1.0");
80         return new AaiArtifactGenerator().generateArtifact(CsarTest.VNF_VENDOR_CSAR.getContent(),
81                 CsarTest.VNF_VENDOR_CSAR.extractArtifacts(), additionalParams);
82     }
83 }