Sorted out unit-test libraries in onboarding
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / upload / csar / ManifestParsingTest.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdc.vendorsoftwareproduct.upload.csar;
18
19 import static org.testng.Assert.assertEquals;
20 import static org.testng.Assert.assertFalse;
21 import static org.testng.Assert.assertTrue;
22
23 import org.openecomp.sdc.common.errors.Messages;
24 import org.openecomp.sdc.vendorsoftwareproduct.impl.orchestration.csar.OnboardingManifest;
25
26 import java.io.IOException;
27 import java.io.InputStream;
28 import org.testng.annotations.Test;
29
30
31 public class ManifestParsingTest {
32
33   @Test
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);
41     }
42   }
43
44   @Test
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))));
52     }
53   }
54
55   @Test
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))));
63     }
64   }
65
66   @Test
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))));
74     }
75   }
76
77
78 }