2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.openstack.utils;
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.junit.Assert.assertNull;
28 import java.io.IOException;
31 import org.junit.Test;
32 import org.onap.so.TestDataSetup;
33 import org.onap.so.db.catalog.beans.HeatTemplateParam;
35 import com.fasterxml.jackson.core.JsonParseException;
36 import com.fasterxml.jackson.databind.JsonMappingException;
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 + "}";
49 public void getParameterListTest() throws JsonParseException, JsonMappingException, IOException {
50 yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY.getBytes());
52 MsoHeatEnvironmentParameter expectedHeatParam = mapper.readValue(new File(RESOURCE_PATH + "HeatEnvironmentParameter.json"), MsoHeatEnvironmentParameter.class);
54 Set<MsoHeatEnvironmentParameter> heatEnvironmentSet = yaml.getParameterListFromEnvt();
56 for(MsoHeatEnvironmentParameter heatEnvironment : heatEnvironmentSet) {
57 assertThat(heatEnvironment, sameBeanAs(expectedHeatParam));
62 public void getResourceListFromEnvtTest() {
63 yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_RESOURCE_REGISTRY.getBytes());
65 MsoHeatEnvironmentResource expectedHeatResource = new MsoHeatEnvironmentResource(RESOURCE_NAME, RESOURCE_VALUE);
67 Set<MsoHeatEnvironmentResource> heatResourceSet = yaml.getResourceListFromEnvt();
69 for(MsoHeatEnvironmentResource heatResource : heatResourceSet) {
70 assertThat(heatResource, sameBeanAs(expectedHeatResource));
75 public void getResourceListFromEnvtExceptionTest() {
76 yaml = new MsoYamlEditorWithEnvt();
78 Set<MsoHeatEnvironmentResource> heatResourceSet = yaml.getResourceListFromEnvt();
80 assertNull(heatResourceSet);
84 public void getParameterListFromEnvtTest() throws JsonParseException, JsonMappingException, IOException {
85 yaml = new MsoYamlEditorWithEnvt(RAW_ENTRY_WITH_NO_RESOURCE_REGISTRY.getBytes());
87 HeatTemplateParam expectedHeatParam = mapper.readValue(new File(RESOURCE_PATH + "HeatTemplateParamExpected.json"), HeatTemplateParam.class);
89 Set<HeatTemplateParam> heatParamSet = yaml.getParameterList();
91 for(HeatTemplateParam heatParam : heatParamSet) {
92 assertThat(heatParam, sameBeanAs(expectedHeatParam));