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=========================================================
22 package org.onap.aai.babel.csar.vnfcatalog;
24 import static org.hamcrest.CoreMatchers.equalTo;
25 import static org.hamcrest.CoreMatchers.instanceOf;
26 import static org.hamcrest.CoreMatchers.is;
27 import static org.hamcrest.CoreMatchers.nullValue;
28 import static org.junit.Assert.assertThat;
30 import java.io.IOException;
31 import org.junit.Test;
32 import org.onap.aai.babel.service.data.BabelArtifact;
33 import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType;
34 import org.onap.aai.babel.util.ArtifactTestUtils;
37 * Tests {@link VnfVendorImageExtractor}
39 public class VnfVendorImageExtractorTest {
41 @Test(expected = NullPointerException.class)
42 public void createVendorImageMappingsNullCsarSupplied() throws ToscaToCatalogException, IOException {
43 new VnfVendorImageExtractor().extract(null);
46 @Test(expected = ToscaToCatalogException.class)
47 public void createVendorImageMappingsEmptyCsarSupplied() throws ToscaToCatalogException, IOException {
48 new VnfVendorImageExtractor().extract(new byte[0]);
51 @Test(expected = ToscaToCatalogException.class)
52 public void createVendorImageMappingsInvalidCsarFile() throws IOException, ToscaToCatalogException {
53 extractArtifact("noYmlFilesArchive.zip");
56 @Test(expected = ToscaToCatalogException.class)
57 public void createVendorImageMappingsInvalidFile() throws IOException, ToscaToCatalogException {
58 extractArtifact("Duff.txt");
62 public void createVendorImageMappingsMoreThanOneVnfConfigurationExists() throws IOException {
64 extractArtifact("catalog_csar_too_many_vnfConfigurations.csar");
65 } catch (Exception e) {
66 assertThat(e, is(instanceOf(ToscaToCatalogException.class)));
67 assertThat(e.getLocalizedMessage(),
68 is(equalTo("An error occurred trying to get the vnf catalog from a csar file. "
69 + "2 vnfConfigurations were found in the csar file and only one is allowed.")));
74 public void createVendorImageMappingsNoVnfConfigurationExists() throws IOException, ToscaToCatalogException {
75 assertThat(extractArtifact("noVnfConfiguration.csar"), is(nullValue()));
79 public void createVendorImageMappingsValidFile() throws IOException, ToscaToCatalogException {
80 BabelArtifact artifact = extractArtifact("catalog_csar.csar");
81 assertThat(artifact.getName(), is(equalTo("vnfVendorImageConfigurations")));
82 assertThat(artifact.getType(), is(equalTo(ArtifactType.VNFCATALOG)));
83 assertThat(artifact.getPayload(),
84 is(equalTo(new ArtifactTestUtils().getRequestJson("vnfVendorImageConfigurations.json"))));
87 private BabelArtifact extractArtifact(String artifactName) throws ToscaToCatalogException, IOException {
88 return new VnfVendorImageExtractor().extract(new ArtifactTestUtils().getCompressedArtifact(artifactName));