2 * Copyright © 2016-2018 European Support Limited
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.openecomp.sdc.tosca.csar;
19 import org.junit.Test;
20 import org.openecomp.sdc.common.errors.Messages;
22 import java.io.IOException;
23 import java.io.InputStream;
25 import static junit.framework.TestCase.assertTrue;
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertFalse;
30 public class ManifestParsingTest {
33 public void testSuccessfulParsing() throws IOException {
34 try (InputStream is = getClass()
35 .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
36 Manifest onboardingManifest = OnboardingManifest.parse(is);
37 assertTrue(onboardingManifest.isValid());
38 assertEquals(onboardingManifest.getMetadata().size(), 4);
39 assertEquals(onboardingManifest.getSources().size(), 5);
44 public void testNoMetadataParsing() throws IOException {
45 try (InputStream is = getClass()
46 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) {
47 Manifest onboardingManifest = OnboardingManifest.parse(is);
48 assertFalse(onboardingManifest.isValid());
49 assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
50 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
55 public void testBrokenMDParsing() throws IOException {
56 try (InputStream is = getClass()
57 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) {
58 Manifest onboardingManifest = OnboardingManifest.parse(is);
59 assertFalse(onboardingManifest.isValid());
60 assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
61 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
66 public void testNoMetaParsing() throws IOException {
67 try (InputStream is = getClass()
68 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) {
69 Manifest onboardingManifest = OnboardingManifest.parse(is);
70 assertFalse(onboardingManifest.isValid());
71 assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
72 .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))));
77 public void testSuccessfulNonManoParsing() throws IOException {
78 try (InputStream is = getClass()
79 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
80 Manifest onboardingManifest = OnboardingManifest.parse(is);
81 assertTrue(onboardingManifest.isValid());
82 assertEquals(onboardingManifest.getMetadata().size(), 4);
83 assertEquals(onboardingManifest.getSources().size(), 5);
84 assertEquals(onboardingManifest.getNonManoSources().size(), 2);
89 public void testFailfulNonManoParsing() throws IOException {
90 try (InputStream is = getClass()
91 .getResourceAsStream("/vspmanager.csar/manifest/InValidNonManoTosca.mf")) {
92 Manifest onboardingManifest = OnboardingManifest.parse(is);
93 assertFalse(onboardingManifest.isValid());
98 public void testFailfulNonManoParsingWithGarbadge() throws IOException {
99 try (InputStream is = getClass()
100 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTocsaNonManoGarbadgeAtEnd.mf")) {
101 Manifest onboardingManifest = OnboardingManifest.parse(is);
102 assertFalse(onboardingManifest.isValid());
107 public void testParseManifestWithNoFile() throws IOException {
108 try (InputStream is = getClass()
109 .getResourceAsStream("/vspmanager.csar/manifest/SOME_WRONG_FILE")) {
110 Manifest onboardingManifest = OnboardingManifest.parse(is);
111 assertFalse(onboardingManifest.isValid());