d922e8e10707aebc9597c98701de8a8cbb5e61d9
[aai/babel.git] / src / test / java / org / onap / aai / babel / testdata / CsarTest.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
22 package org.onap.aai.babel.testdata;
23
24 import com.google.gson.Gson;
25 import java.io.IOException;
26 import java.util.List;
27 import org.onap.aai.babel.csar.extractor.InvalidArchiveException;
28 import org.onap.aai.babel.csar.extractor.YamlExtractor;
29 import org.onap.aai.babel.csar.vnfcatalog.ToscaToCatalogException;
30 import org.onap.aai.babel.csar.vnfcatalog.VnfVendorImageExtractor;
31 import org.onap.aai.babel.service.data.BabelArtifact;
32 import org.onap.aai.babel.service.data.BabelRequest;
33 import org.onap.aai.babel.util.ArtifactTestUtils;
34 import org.onap.aai.babel.xml.generator.data.Artifact;
35 import org.onap.aai.babel.xml.generator.data.GeneratorUtil;
36
37 public enum CsarTest {
38     // @formatter:off
39     VNF_VENDOR_CSAR("catalog_csar.csar"),
40     NO_VNF_CONFIG_CSAR("noVnfConfiguration.csar"),
41     SD_WAN_CSAR_FILE("service-SdWanServiceTest-csar.csar"),
42     MISSING_METADATA_CSAR("service-MissingMetadataTest.csar"),
43     NO_YAML_FILES("noYmlFilesArchive.zip"),
44     PORT_MIRROR_CSAR("service_PortMirror.csar"),
45     MULTIPLE_VNF_CSAR("catalog_csar_too_many_vnfConfigurations.csar");
46     // @formatter:on
47
48     private String filename;
49     private ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
50
51     CsarTest(String filename) {
52         this.filename = filename;
53     }
54
55     public String getName() {
56         return filename;
57     }
58
59     public byte[] getContent() throws IOException {
60         return artifactTestUtils.getCompressedArtifact(filename);
61     }
62
63     /**
64      * Extract YAML Artifacts.
65      *
66      * @return the extracted artifacts
67      * @throws InvalidArchiveException if the CSAR is invalid
68      * @throws IOException for I/O errors
69      */
70     public List<Artifact> extractArtifacts() throws InvalidArchiveException, IOException {
71         return new YamlExtractor().extract(getContent(), getName(), "v1");
72     }
73
74     /**
75      * Extract VNF Vendor Image Artifacts.
76      *
77      * @return the extracted artifacts
78      * @throws IOException
79      * @throws ToscaToCatalogException
80      *
81      */
82     public BabelArtifact extractVnfVendorImages() throws ToscaToCatalogException, IOException {
83         return new VnfVendorImageExtractor().extract(getContent());
84     }
85
86     public String getJsonRequest() throws IOException {
87         BabelRequest request = new BabelRequest();
88         request.setArtifactName(getName());
89         request.setArtifactVersion("1.0");
90         request.setCsar(new String(GeneratorUtil.encode(getContent())));
91         return new Gson().toJson(request);
92     }
93 }