Add a CSAR validator for model ETSI SOL001 2.5.1
[sdc.git] / openecomp-be / lib / openecomp-tosca-lib / src / test / java / org / openecomp / sdc / tosca / csar / MetadataParsingTest.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.openecomp.sdc.tosca.csar;
22
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNull;
27 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ENTRY_DEFINITIONS;
28 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_CHANGE_LOG;
29 import static org.openecomp.sdc.tosca.csar.ToscaMetaEntryVersion261.ETSI_ENTRY_MANIFEST;
30
31 import java.io.IOException;
32 import java.io.InputStream;
33 import org.junit.Test;
34
35
36
37 public class MetadataParsingTest {
38
39   @Test
40   public void testNoEntryDefinitions() throws IOException {
41     try (InputStream is = getClass()
42         .getResourceAsStream("/vspmanager.csar/metadata/Invalidtosca.meta")) {
43       ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
44       assertFalse(onboardingToscaMetadata.isValid());
45       assertNull(onboardingToscaMetadata.getMetaEntries().get(ENTRY_DEFINITIONS.getName()));
46     }
47   }
48
49   @Test
50   public void testValidMetadataFile() throws IOException {
51     try (InputStream is = getClass()
52         .getResourceAsStream("/vspmanager.csar/metadata/Validtosca.meta")) {
53       ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
54       assertEquals("Definitions/MainServiceTemplate.yaml", onboardingToscaMetadata.getMetaEntries().get(
55           ENTRY_DEFINITIONS.getName()));
56     }
57
58   }
59
60   @Test
61   public void testInvalidMetadataFileEmptyKey() throws IOException {
62     try (InputStream is = getClass()
63             .getResourceAsStream("/vspmanager.csar/metadata/InvalidtoscaEmptyKey.meta")) {
64       ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
65       assertFalse(onboardingToscaMetadata.isValid());
66     }
67   }
68
69   @Test
70   public void testInvalidMetadataFileEmptyValue() throws IOException {
71     try (InputStream is = getClass()
72             .getResourceAsStream("/vspmanager.csar/metadata/InvalidtoscaEmptyValue.meta")) {
73       ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
74       assertFalse(onboardingToscaMetadata.isValid());
75     }
76   }
77
78   @Test
79   public void testValidETSIMetadataFile() throws IOException {
80     try (InputStream is = getClass()
81             .getResourceAsStream("/vspmanager.csar/metadata/ValidETSItosca.meta")) {
82       ToscaMetadata onboardingToscaMetadata = OnboardingToscaMetadata.parseToscaMetadataFile(is);
83       assertEquals("Definitions/MainServiceTemplate.yaml", onboardingToscaMetadata.getMetaEntries().get(
84           ENTRY_DEFINITIONS.getName()));
85       assertEquals("MainServiceTemplate.mf", onboardingToscaMetadata.getMetaEntries().get(ETSI_ENTRY_MANIFEST.getName()));
86       assertEquals("change.log", onboardingToscaMetadata.getMetaEntries().get(ETSI_ENTRY_CHANGE_LOG.getName()));
87     }
88
89   }
90 }