Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / test / java / org / onap / sdc / toscaparser / api / JToscaMetadataParse.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.sdc.toscaparser.api;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26
27 import java.io.File;
28 import java.util.LinkedHashMap;
29
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;
34
35 public class JToscaMetadataParse {
36
37     @Test
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);
47     }
48
49     @Test
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);
56     }
57
58     @Test
59     public void testEmptyCsar() throws JToscaException {
60         String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("csars/emptyCsar.csar").getFile();
61         File file = new File(fileStr);
62         try {
63             ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
64         } catch (JToscaException e) {
65             assertTrue(e.getCode().equals(JToscaErrorCodes.INVALID_CSAR_FORMAT.getValue()));
66         }
67         int validationIssuesCaught = ThreadLocalsHolder.getCollector().validationIssuesCaught();
68         assertTrue(validationIssuesCaught == 0);
69     }
70
71     @Test
72     public void testEmptyPath() throws JToscaException {
73         String fileStr = JToscaMetadataParse.class.getClassLoader().getResource("").getFile();
74         File file = new File(fileStr);
75         try {
76             ToscaTemplate toscaTemplate = new ToscaTemplate(file.getAbsolutePath(), null, true, null);
77         } catch (JToscaException e) {
78             assertTrue(e.getCode().equals(JToscaErrorCodes.PATH_NOT_VALID.getValue()));
79         }
80     }
81 }