Additional junit tests for artifact generation
[aai/babel.git] / src / test / java / org / onap / aai / babel / csar / vnfcatalog / ConfigurationsToBabelArtifactConverterTest.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.nullValue;
25 import static org.hamcrest.MatcherAssert.assertThat;
26 import static org.hamcrest.core.Is.is;
27
28 import com.google.gson.Gson;
29 import com.google.gson.reflect.TypeToken;
30 import java.io.IOException;
31 import java.util.ArrayList;
32 import java.util.List;
33 import org.junit.Test;
34 import org.onap.aai.babel.service.data.BabelArtifact;
35 import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType;
36 import org.onap.aai.babel.util.ArtifactTestUtils;
37
38 /**
39  * Tests {@link ConfigurationsToBabelArtifactConverter}.
40  */
41 public class ConfigurationsToBabelArtifactConverterTest {
42     @Test
43     public void testNullListSupplied() {
44         assertThat(ConfigurationsToBabelArtifactConverter.convert(null), is(nullValue()));
45     }
46
47     @Test
48     public void testEmptyListSupplied() {
49         assertThat(ConfigurationsToBabelArtifactConverter.convert(new ArrayList<>()), is(nullValue()));
50     }
51
52     @Test
53     public void testValidListSupplied() throws IOException {
54         String expectedJson = new ArtifactTestUtils().getRequestJson("vnfVendorImageConfigurations.json");
55         List<VendorImageConfiguration> configurations =
56                 new Gson().fromJson(expectedJson, new TypeToken<ArrayList<VendorImageConfiguration>>() {}.getType());
57
58         BabelArtifact artifact = ConfigurationsToBabelArtifactConverter.convert(configurations);
59
60         assertThat(artifact.getName(), is(equalTo("vnfVendorImageConfigurations")));
61         assertThat(artifact.getType(), is(equalTo(ArtifactType.VNFCATALOG)));
62         assertThat(artifact.getPayload(), is(equalTo(expectedJson)));
63     }
64 }