2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdc.toscaparser.api;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
28 import java.util.LinkedHashMap;
30 import org.junit.Test;
31 import org.onap.sdc.toscaparser.api.common.JToscaException;
32 import org.onap.sdc.toscaparser.api.utils.JToscaErrorCodes;
33 import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
35 public class JToscaMetadataParse {
38 public void testMetadataParsedCorrectly() throws JToscaException {
39 String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/csar_hello_world.csar").getFile();
40 File file = new File(fileStr);
41 ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
42 LinkedHashMap<String, Object> metadataProperties = toscaTemplate.getMetaProperties("TOSCA.meta");
43 assertNotNull(metadataProperties);
44 Object entryDefinition = metadataProperties.get("Entry-Definitions");
45 assertNotNull(entryDefinition);
46 assertEquals("tosca_helloworld.yaml", entryDefinition);
50 public void noWarningsAfterParse() throws JToscaException {
51 String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/tmpCSAR_Huawei_vSPGW_fixed.csar").getFile();
52 File file = new File(fileStr);
53 ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
54 int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
55 assertTrue(validationIssuesCaught == 0);
59 public void testEmptyCsar() throws JToscaException {
60 String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/emptyCsar.csar").getFile();
61 File file = new File(fileStr);
63 ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
64 } catch (JToscaException e) {
65 assertTrue(e.getCode().equals(JToscaErrorCodes.INVALID_CSAR_FORMAT.getValue()));
67 int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
68 assertTrue(validationIssuesCaught == 0);
72 public void testEmptyPath() throws JToscaException {
73 String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("").getFile();
74 File file = new File(fileStr);
76 ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
77 } catch (JToscaException e) {
78 assertTrue(e.getCode().equals(JToscaErrorCodes.PATH_NOT_VALID.getValue()));