d27396d9aad5e4ed5904ffe8f543c3f81c15708b
[aai/babel.git] / src / test / java / org / onap / aai / babel / parser / TestToscaParser.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.babel.parser;
22
23 import static org.hamcrest.CoreMatchers.equalTo;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.junit.Assert.assertThat;
26
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33 import java.util.Properties;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
37 import org.onap.aai.babel.csar.extractor.YamlExtractor;
38 import org.onap.aai.babel.util.ArtifactTestUtils;
39 import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator;
40 import org.onap.aai.babel.xml.generator.data.AdditionalParams;
41 import org.onap.aai.babel.xml.generator.data.Artifact;
42 import org.onap.aai.babel.xml.generator.data.GenerationData;
43 import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
44 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
45
46 /**
47  * Direct tests of the Model so as to improve code coverage
48  */
49 public class TestToscaParser {
50
51     static {
52         if (System.getProperty("APP_HOME") == null) {
53             System.setProperty("APP_HOME", ".");
54         }
55     }
56
57     @Before
58     public void setup() throws FileNotFoundException, IOException {
59         System.setProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE,
60                 new ArtifactTestUtils().getResourcePath("artifact-generator.properties"));
61         InputStream in = TestToscaParser.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
62         Properties properties = new Properties();
63         properties.load(in);
64         in.close();
65         WidgetConfigurationUtil.setConfig(properties);
66     }
67
68     @Test
69     public void testParserWithCsarFile() throws IOException, InvalidArchiveException {
70         String csarResourceName = "catalog_csar.csar";
71         byte[] csarBytes = new ArtifactTestUtils().getCompressedArtifact(csarResourceName);
72         List<Artifact> ymlFiles = new YamlExtractor().extract(csarBytes, csarResourceName, "1.0");
73
74         Map<String, String> additionalParams = new HashMap<>();
75         additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), "1.0");
76
77         AaiArtifactGenerator generator = new AaiArtifactGenerator();
78         GenerationData data = generator.generateArtifact(csarBytes, ymlFiles, additionalParams);
79
80         assertThat(data.getErrorData().size(), is(equalTo(0)));
81         assertThat(data.getResultData().size(), is(equalTo(2)));
82     }
83
84 }