2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.babel.csar.vnfcatalog;
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;
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;
35 * Tests {@link VnfVendorImageExtractor}
37 public class VnfVendorImageExtractorTest {
39 @Test(expected = NullPointerException.class)
40 public void createVendorImageMappingsNullCsarSupplied() throws ToscaToCatalogException, IOException {
41 new VnfVendorImageExtractor().extract(null);
44 @Test(expected = ToscaToCatalogException.class)
45 public void createVendorImageMappingsEmptyCsarSupplied() throws ToscaToCatalogException, IOException {
46 new VnfVendorImageExtractor().extract(new byte[0]);
49 @Test(expected = ToscaToCatalogException.class)
50 public void createVendorImageMappingsInvalidCsarFile() throws IOException, ToscaToCatalogException {
51 extractArtifact("noYmlFilesArchive.zip");
54 @Test(expected = ToscaToCatalogException.class)
55 public void createVendorImageMappingsInvalidFile() throws IOException, ToscaToCatalogException {
56 extractArtifact("Duff.txt");
60 public void createVendorImageMappingsNoVnfConfigurationExists() throws IOException, ToscaToCatalogException {
61 assertThat(extractArtifact("noVnfConfiguration.csar"), is(nullValue()));
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"))));
73 private BabelArtifact extractArtifact(String artifactName) throws ToscaToCatalogException, IOException {
74 return new VnfVendorImageExtractor().extract(new ArtifactTestUtils().getCompressedArtifact(artifactName));