2e8a1ecbd00795befbee32e52011bccb044fb9d9
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.openecomp.sdc.tosca.csar;
18
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.openecomp.sdc.common.errors.Messages;
22 import java.io.IOException;
23 import java.io.InputStream;
24
25 import static junit.framework.TestCase.assertTrue;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
28
29
30 public class ManifestParsingTest {
31
32   private Manifest manifest;
33
34   @Before
35   public void setUp(){
36     manifest = new SOL004ManifestOnboarding();
37   }
38
39   @Test
40   public void testSuccessfulParsing() throws IOException {
41     try (InputStream is = getClass()
42         .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
43       manifest.parse(is);
44       assertTrue(manifest.isValid());
45       assertEquals(manifest.getMetadata().size(), 4);
46       assertEquals(manifest.getSources().size(), 5);
47     }
48   }
49
50   @Test
51   public void testNoMetadataParsing() throws IOException {
52     try (InputStream is = getClass()
53         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) {
54       manifest.parse(is);
55       assertFalse(manifest.isValid());
56       assertTrue(manifest.getErrors().stream().anyMatch(error -> error
57           .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
58     }
59   }
60
61   @Test
62   public void testBrokenMDParsing() throws IOException {
63     try (InputStream is = getClass()
64         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) {
65      manifest.parse(is);
66       assertFalse(manifest.isValid());
67       assertTrue(manifest.getErrors().stream().anyMatch(error -> error
68           .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
69     }
70   }
71
72   @Test
73   public void testNoMetaParsing() throws IOException {
74     try (InputStream is = getClass()
75         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) {
76       manifest.parse(is);
77       assertFalse(manifest.isValid());
78       assertTrue(manifest.getErrors().stream().anyMatch(error -> error
79           .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))));
80     }
81   }
82
83   @Test
84   public void testSuccessfulNonManoParsing() throws IOException {
85     try (InputStream is = getClass()
86             .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
87       manifest.parse(is);
88       assertTrue(manifest.isValid());
89       assertEquals(manifest.getMetadata().size(), 4);
90       assertEquals(manifest.getSources().size(), 5);
91       assertEquals(manifest.getNonManoSources().size(), 2);
92     }
93   }
94
95   @Test
96   public void testFailfulNonManoParsing() throws IOException {
97     try (InputStream is = getClass()
98             .getResourceAsStream("/vspmanager.csar/manifest/InValidNonManoTosca.mf")) {
99       manifest.parse(is);
100       assertFalse(manifest.isValid());
101     }
102   }
103
104   @Test
105   public void testFailfulNonManoParsingWithGarbadge() throws IOException {
106     try (InputStream is = getClass()
107             .getResourceAsStream("/vspmanager.csar/manifest/InvalidTocsaNonManoGarbadgeAtEnd.mf")) {
108       manifest.parse(is);
109       assertFalse(manifest.isValid());
110     }
111   }
112
113   @Test
114   public void testParseManifestWithNoFile() throws IOException {
115     try (InputStream is = getClass()
116             .getResourceAsStream("/vspmanager.csar/manifest/SOME_WRONG_FILE")) {
117       manifest.parse(is);
118       assertFalse(manifest.isValid());
119     }
120   }
121 }