re base code
[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.*;
11
12 public class ManifestParsingTest {
13
14   @Test
15   public void testSuccessfulParsing() throws IOException {
16     try (InputStream is = getClass()
17         .getResourceAsStream("/vspmanager.csar/manifest/ValidTosca.mf")) {
18       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
19       assertTrue(onboardingManifest.isValid());
20       assertEquals(onboardingManifest.getMetadata().size(), 4);
21       assertEquals(onboardingManifest.getSources().size(), 5);
22     }
23   }
24
25   @Test
26   public void testNoMetadataParsing() throws IOException {
27     try (InputStream is = getClass()
28         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca1.mf")) {
29       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
30       assertFalse(onboardingManifest.isValid());
31       assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
32           .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
33     }
34   }
35
36   @Test
37   public void testBrokenMDParsing() throws IOException {
38     try (InputStream is = getClass()
39         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca2.mf")) {
40       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
41       assertFalse(onboardingManifest.isValid());
42       assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
43           .contains(Messages.MANIFEST_INVALID_LINE.getErrorMessage().substring(0, 10))));
44     }
45   }
46
47   @Test
48   public void testNoMetaParsing() throws IOException {
49     try (InputStream is = getClass()
50         .getResourceAsStream("/vspmanager.csar/manifest/InvalidTosca4.mf")) {
51       OnboardingManifest onboardingManifest = new OnboardingManifest(is);
52       assertFalse(onboardingManifest.isValid());
53       assertTrue(onboardingManifest.getErrors().stream().anyMatch(error -> error
54           .contains(Messages.MANIFEST_NO_METADATA.getErrorMessage().substring(0, 10))));
55     }
56   }
57
58
59 }