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.be.datatypes.enums.ResourceTypeEnum;
22 import org.openecomp.sdc.common.errors.Messages;
23 import java.io.IOException;
24 import java.io.InputStream;
25 import java.util.Optional;
27 import static junit.framework.TestCase.assertTrue;
28 import static org.junit.Assert.assertEquals;
29 import static org.junit.Assert.assertFalse;
32 public class ManifestParsingTest {
34 private Manifest manifest;
38 manifest = new SOL004ManifestOnboarding();
42 public void testSuccessfulParsing() throws IOException {
43 try (InputStream is = getClass()
44 .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
46 assertTrue(manifest.isValid());
47 assertEquals(manifest.getMetadata().size(), 4);
48 assertEquals(manifest.getSources().size(), 5);
49 Optional<ResourceTypeEnum> resourceTypeEnum = manifest.getType();
50 if(resourceTypeEnum.isPresent()){
51 assertTrue(resourceTypeEnum.get() == ResourceTypeEnum.VF);
57 public void testNoMetadataParsing() throws IOException {
58 try (InputStream is = getClass()
59 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) {
61 assertFalse(manifest.isValid());
62 assertTrue(manifest.getErrors().stream().anyMatch(error -> error
63 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
68 public void testBrokenMDParsing() throws IOException {
69 try (InputStream is = getClass()
70 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) {
72 assertFalse(manifest.isValid());
73 assertTrue(manifest.getErrors().stream().anyMatch(error -> error
74 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
79 public void testNoMetaParsing() throws IOException {
80 try (InputStream is = getClass()
81 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) {
83 assertFalse(manifest.isValid());
84 assertTrue(manifest.getErrors().stream().anyMatch(error -> error
85 .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))));
90 public void testSuccessfulNonManoParsing() throws IOException {
91 try (InputStream is = getClass()
92 .getResourceAsStream("/vspmanager.csar/manifest/ValidNonManoTosca.mf")) {
94 assertTrue(manifest.isValid());
95 assertEquals(manifest.getMetadata().size(), 4);
96 assertEquals(manifest.getSources().size(), 5);
97 assertEquals(manifest.getNonManoSources().size(), 2);
102 public void testFailfulNonManoParsing() throws IOException {
103 try (InputStream is = getClass()
104 .getResourceAsStream("/vspmanager.csar/manifest/InValidNonManoTosca.mf")) {
106 assertFalse(manifest.isValid());
111 public void testFailfulNonManoParsingWithGarbadge() throws IOException {
112 try (InputStream is = getClass()
113 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTocsaNonManoGarbadgeAtEnd.mf")) {
115 assertFalse(manifest.isValid());
120 public void testParseManifestWithNoFile() throws IOException {
121 try (InputStream is = getClass()
122 .getResourceAsStream("/vspmanager.csar/manifest/SOME_WRONG_FILE")) {
124 assertFalse(manifest.isValid());