70b5f2699d087232fa24dae2536dab64b9cb6a75
[so.git] / adapters / mso-adapter-utils / src / test / java / org / onap / so / openstack / utils / MsoYamlEditorWithEnvtTest.java
1 /*
2 * ============LICENSE_START=======================================================
3  * ONAP : SO
4  * ================================================================================
5  * Copyright (C) 2018 TechMahindra
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19 */
20
21 package org.onap.so.openstack.utils;
22
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.junit.Assert.assertNull;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.util.Set;
30
31 import org.junit.Test;
32 import org.onap.so.TestDataSetup;
33 import org.onap.so.db.catalog.beans.HeatTemplateParam;
34
35 import com.fasterxml.jackson.core.JsonParseException;
36 import com.fasterxml.jackson.databind.JsonMappingException;
37
38 public class MsoYamlEditorWithEnvtTest extends TestDataSetup {
39         private MsoYamlEditorWithEnvt yaml;
40     private static final String PARAMETER_NAME = "keyTest";
41     private static final String PARAMETER_VALUE = "{type : paramType}";
42     private static final String RESOURCE_NAME = "resourceKey";
43     private static final String RESOURCE_VALUE = "resourceValue";
44     private static final String RAW_ENTRY_WITH_RESOURCE_REGISTRY = "resource_registry: {" + RESOURCE_NAME + " : " + RESOURCE_VALUE + "}";
45     private static final String RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY = "parameters: {"
46             + PARAMETER_NAME + ": " + PARAMETER_VALUE + "}";
47     
48         @Test
49         public void getParameterListTest() throws JsonParseException, JsonMappingException, IOException {
50             yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY.getBytes());
51
52             MsoHeatEnvironmentParameter expectedHeatParam = mapper.readValue(new File(RESOURCE_PATH + "HeatEnvironmentParameter.json"), MsoHeatEnvironmentParameter.class);
53             
54             Set<MsoHeatEnvironmentParameter> heatEnvironmentSet = yaml.getParameterListFromEnvt();
55             
56             for(MsoHeatEnvironmentParameter heatEnvironment : heatEnvironmentSet) {
57                         assertThat(heatEnvironment, sameBeanAs(expectedHeatParam));
58                 }
59         }
60         
61         @Test
62         public void getResourceListFromEnvtTest() {
63                 yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_RESOURCE_REGISTRY.getBytes());
64                 
65                 MsoHeatEnvironmentResource expectedHeatResource = new MsoHeatEnvironmentResource(RESOURCE_NAME, RESOURCE_VALUE);
66                 
67                 Set<MsoHeatEnvironmentResource> heatResourceSet = yaml.getResourceListFromEnvt();
68                 
69                 for(MsoHeatEnvironmentResource heatResource : heatResourceSet) {
70                         assertThat(heatResource, sameBeanAs(expectedHeatResource));
71                 }
72         }
73         
74         @Test
75         public void getResourceListFromEnvtExceptionTest() {
76                 yaml = new MsoYamlEditorWithEnvt();
77                 
78                 Set<MsoHeatEnvironmentResource> heatResourceSet = yaml.getResourceListFromEnvt();
79                 
80                 assertNull(heatResourceSet);
81         }
82         
83         @Test
84         public void getParameterListFromEnvtTest() throws JsonParseException, JsonMappingException, IOException {
85             yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY.getBytes());
86             
87             HeatTemplateParam expectedHeatParam = mapper.readValue(new File(RESOURCE_PATH + "HeatTemplateParamExpected.json"), HeatTemplateParam.class);
88                 
89                 Set<HeatTemplateParam> heatParamSet = yaml.getParameterList();
90             
91                 for(HeatTemplateParam heatParam : heatParamSet) {
92                         assertThat(heatParam, sameBeanAs(expectedHeatParam));
93                 }
94         }
95 }