Add collaboration feature
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / upload / csar / ManifestParsingTest.java
1 package org.openecomp.sdc.vendorsoftwareproduct.upload.csar;
2
3 import org.junit.Test;
4 import org.openecomp.sdc.common.errors.Messages;
5 import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest;
6
7 import java.io.IOException;
8 import java.io.InputStream;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13
14 public class ManifestParsingTest {
15
16   @Test
17   public void testSuccessfulParsing() throws IOException {
18     try (InputStream is = getClass()
19         .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
20       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
21       assertTrue(onboardingManifest.isValid());
22       assertEquals(onboardingManifest.getMetadata().size(), 4);
23       assertEquals(onboardingManifest.getSources().size(), 5);
24     }
25   }
26
27   @Test
28   public void testNoMetadataParsing() throws IOException {
29     try (InputStream is = getClass()
30         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) {
31       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
32       assertFalse(onboardingManifest.isValid());
33       assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
34           .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
35     }
36   }
37
38   @Test
39   public void testBrokenMDParsing() throws IOException {
40     try (InputStream is = getClass()
41         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) {
42       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
43       assertFalse(onboardingManifest.isValid());
44       assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
45           .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
46     }
47   }
48
49   @Test
50   public void testNoMetaParsing() throws IOException {
51     try (InputStream is = getClass()
52         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) {
53       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
54       assertFalse(onboardingManifest.isValid());
55       assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
56           .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))));
57     }
58   }
59
60
61 }