e1b16c110e4a1ba9fcc081aa35b1a2b1c883b3ea
[sdc/sdc-tosca.git] / sdc-tosca / src / test / java / org / onap / sdc / impl / ToscaParserSimpleYaml12Test.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 Nordix Foundation. All rights reserved.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.impl;
22
23 import static org.testng.Assert.assertNotNull;
24 import static org.testng.Assert.assertNull;
25
26 import java.io.File;
27 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
28 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
29 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
30 import org.testng.annotations.Test;
31
32 public class ToscaParserSimpleYaml12Test {
33
34     private static final SdcToscaParserFactory factory = SdcToscaParserFactory.getInstance();
35
36     @Test
37     public void testVersion() throws Exception {
38
39         verify("csars/resource-Networkfunction-tosca_simple_yaml_1_2.csar");
40         verify("csars/resource-Networkservice-tosca_simple_yaml_1_2.csar");
41         verify("csars/resource-Amf-tosca_simple_yaml_1_2.csar");
42         verify("csars/resource-Resource-tosca_simple_yaml_1_2.csar");
43     }
44
45     private void verify(final String resourceFileName) throws Exception {
46         final ISdcCsarHelper fdntCsarHelper = getCsarHelper(resourceFileName);
47
48         assertNotNull(fdntCsarHelper.getServiceMetadata());
49         assertNull(fdntCsarHelper.getServiceSubstitutionMappingsTypeName());
50         assertNotNull(fdntCsarHelper.getServiceMetadataAllProperties());
51         assertNull(fdntCsarHelper.getServiceInputs());
52         assertNotNull(fdntCsarHelper.getConformanceLevel());
53         assertNotNull(fdntCsarHelper.getDataTypes());
54         assertNull(fdntCsarHelper.getInputsWithAnnotations());
55         assertNotNull(fdntCsarHelper.getVFModule());
56     }
57
58     private ISdcCsarHelper getCsarHelper(final String path) throws SdcToscaParserException {
59         System.out.println("Parsing CSAR " + path + "...");
60         final String fileName = SdcToscaParserBasicTest.class.getClassLoader().getResource(path).getFile();
61         return factory.getSdcCsarHelper((new File(fileName)).getAbsolutePath());
62     }
63
64 }