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.babel.parser;
23 import static org.hamcrest.CoreMatchers.equalTo;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.junit.Assert.assertThat;
27 import java.io.FileNotFoundException;
28 import java.io.IOException;
29 import java.io.InputStream;
31 import java.util.HashMap;
32 import java.util.List;
34 import java.util.Properties;
35 import org.apache.commons.io.IOUtils;
36 import org.junit.Before;
37 import org.junit.Test;
38 import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
39 import org.onap.aai.babel.csar.extractor.YamlExtractor;
40 import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator;
41 import org.onap.aai.babel.xml.generator.data.AdditionalParams;
42 import org.onap.aai.babel.xml.generator.data.Artifact;
43 import org.onap.aai.babel.xml.generator.data.GenerationData;
44 import org.onap.aai.babel.xml.generator.data.GeneratorConstants;
45 import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil;
48 * Direct tests of the Model so as to improve code coverage
50 public class TestToscaParser {
53 if (System.getProperty("AJSC_HOME") == null) {
54 System.setProperty("AJSC_HOME", ".");
59 public void setup() throws FileNotFoundException, IOException {
60 URL url = TestToscaParser.class.getClassLoader().getResource("artifact-generator.properties");
61 System.setProperty(GeneratorConstants.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE, url.getPath());
63 InputStream in = TestToscaParser.class.getClassLoader().getResourceAsStream("artifact-generator.properties");
64 Properties properties = new Properties();
67 WidgetConfigurationUtil.setConfig(properties);
71 public void testParserWithCsarFile() throws IOException, InvalidArchiveException {
72 byte[] csar = loadResource("compressedArtifacts/catalog_csar.csar");
73 List<Artifact> ymlFiles = YamlExtractor.extract(csar, "catalog_csar.csar", "1.0");
75 Map<String, String> additionalParams = new HashMap<>();
76 additionalParams.put(AdditionalParams.SERVICE_VERSION.getName(), "1.0");
78 AaiArtifactGenerator generator = new AaiArtifactGenerator();
79 GenerationData data = generator.generateArtifact(csar, ymlFiles, additionalParams);
81 assertThat(data.getErrorData().size(), is(equalTo(0)));
82 assertThat(data.getResultData().size(), is(equalTo(2)));
85 private byte[] loadResource(String resourceName) throws IOException {
86 return IOUtils.toByteArray(TestToscaParser.class.getClassLoader().getResource(resourceName));