Additional junit tests for artifact generation
[aai/babel.git] / src / test / java / org / onap / aai / babel / csar / vnfcatalog / VnfVendorImageExtractorTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017-2018 European Software Marketing Ltd.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *       http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21 package org.onap.aai.babel.csar.vnfcatalog;
22
23 import static org.hamcrest.CoreMatchers.equalTo;
24 import static org.hamcrest.CoreMatchers.is;
25 import static org.hamcrest.CoreMatchers.nullValue;
26 import static org.junit.Assert.assertThat;
27
28 import java.io.IOException;
29 import org.junit.Test;
30 import org.onap.aai.babel.service.data.BabelArtifact;
31 import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType;
32 import org.onap.aai.babel.util.ArtifactTestUtils;
33
34 /**
35  * Tests {@link VnfVendorImageExtractor}
36  */
37 public class VnfVendorImageExtractorTest {
38
39     @Test(expected = NullPointerException.class)
40     public void createVendorImageMappingsNullCsarSupplied() throws ToscaToCatalogException, IOException {
41         new VnfVendorImageExtractor().extract(null);
42     }
43
44     @Test(expected = ToscaToCatalogException.class)
45     public void createVendorImageMappingsEmptyCsarSupplied() throws ToscaToCatalogException, IOException {
46         new VnfVendorImageExtractor().extract(new byte[0]);
47     }
48
49     @Test(expected = ToscaToCatalogException.class)
50     public void createVendorImageMappingsInvalidCsarFile() throws IOException, ToscaToCatalogException {
51         extractArtifact("noYmlFilesArchive.zip");
52     }
53
54     @Test(expected = ToscaToCatalogException.class)
55     public void createVendorImageMappingsInvalidFile() throws IOException, ToscaToCatalogException {
56         extractArtifact("Duff.txt");
57     }
58
59     @Test
60     public void createVendorImageMappingsNoVnfConfigurationExists() throws IOException, ToscaToCatalogException {
61         assertThat(extractArtifact("noVnfConfiguration.csar"), is(nullValue()));
62     }
63
64     @Test
65     public void createVendorImageMappingsValidFile() throws IOException, ToscaToCatalogException {
66         BabelArtifact artifact = extractArtifact("catalog_csar.csar");
67         assertThat(artifact.getName(), is(equalTo("vnfVendorImageConfigurations")));
68         assertThat(artifact.getType(), is(equalTo(ArtifactType.VNFCATALOG)));
69         assertThat(artifact.getPayload(),
70                 is(equalTo(new ArtifactTestUtils().getRequestJson("vnfVendorImageConfigurations.json"))));
71     }
72
73     private BabelArtifact extractArtifact(String artifactName) throws ToscaToCatalogException, IOException {
74         return new VnfVendorImageExtractor().extract(new ArtifactTestUtils().getCompressedArtifact(artifactName));
75     }
76 }