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.vendorsoftwareproduct.upload.csar;
19 import static org.testng.Assert.assertEquals;
20 import static org.testng.Assert.assertFalse;
21 import static org.testng.Assert.assertTrue;
23 import org.openecomp.sdc.common.errors.Messages;
24 import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest;
26 import java.io.IOException;
27 import java.io.InputStream;
28 import org.testng.annotations.Test;
31 public class ManifestParsingTest {
34 public void testSuccessfulParsing() throws IOException {
35 try (InputStream is = getClass()
36 .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
37 OnboardingManifest onboardingManifest = new OnboardingManifest(is);
38 assertTrue(onboardingManifest.isValid());
39 assertEquals(onboardingManifest.getMetadata().size(), 4);
40 assertEquals(onboardingManifest.getSources().size(), 5);
45 public void testNoMetadataParsing() throws IOException {
46 try (InputStream is = getClass()
47 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) {
48 OnboardingManifest onboardingManifest = new OnboardingManifest(is);
49 assertFalse(onboardingManifest.isValid());
50 assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
51 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
56 public void testBrokenMDParsing() throws IOException {
57 try (InputStream is = getClass()
58 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) {
59 OnboardingManifest onboardingManifest = new OnboardingManifest(is);
60 assertFalse(onboardingManifest.isValid());
61 assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
62 .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
67 public void testNoMetaParsing() throws IOException {
68 try (InputStream is = getClass()
69 .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) {
70 OnboardingManifest onboardingManifest = new OnboardingManifest(is);
71 assertFalse(onboardingManifest.isValid());
72 assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
73 .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))));