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.Before;
20 import org.junit.Test;
21 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 {
32 private Manifest manifest;
36 manifest = new SOL004ManifestOnboarding();
40 public void testSuccessfulParsing() throws IOException {
41 try (InputStream is = getClass()
42 .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
44 assertTrue(manifest.isValid());
45 assertEquals(manifest.getMetadata().size(), 4);
46 assertEquals(manifest.getSources().size(), 5);
51 public void testNoMetadataParsing() throws IOException {
52 try (InputStream is = getClass()
53 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) {
55 assertFalse(manifest.isValid());
56 assertTrue(manifest.getErrors().stream().anyMatch(error -> error
57 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
62 public void testBrokenMDParsing() throws IOException {
63 try (InputStream is = getClass()
64 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) {
66 assertFalse(manifest.isValid());
67 assertTrue(manifest.getErrors().stream().anyMatch(error -> error
68 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
73 public void testNoMetaParsing() throws IOException {
74 try (InputStream is = getClass()
75 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) {
77 assertFalse(manifest.isValid());
78 assertTrue(manifest.getErrors().stream().anyMatch(error -> error
79 .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))));
84 public void testSuccessfulNonManoParsing() throws IOException {
85 try (InputStream is = getClass()
86 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
88 assertTrue(manifest.isValid());
89 assertEquals(manifest.getMetadata().size(), 4);
90 assertEquals(manifest.getSources().size(), 5);
91 assertEquals(manifest.getNonManoSources().size(), 2);
96 public void testFailfulNonManoParsing() throws IOException {
97 try (InputStream is = getClass()
98 .getResourceAsStream("/vspmanager.csar/manifest/InValidNonManoTosca.mf")) {
100 assertFalse(manifest.isValid());
105 public void testFailfulNonManoParsingWithGarbadge() throws IOException {
106 try (InputStream is = getClass()
107 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTocsaNonManoGarbadgeAtEnd.mf")) {
109 assertFalse(manifest.isValid());
114 public void testParseManifestWithNoFile() throws IOException {
115 try (InputStream is = getClass()
116 .getResourceAsStream("/vspmanager.csar/manifest/SOME_WRONG_FILE")) {
118 assertFalse(manifest.isValid());