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