3 * Copyright © 2017-2018 European Support Limited
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
20 package org.openecomp.sdc.heat.services;
22 import java.util.Collections;
23 import java.util.HashMap;
24 import java.util.HashSet;
28 import org.junit.Assert;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.mockito.Mock;
32 import org.mockito.Mockito;
33 import org.mockito.MockitoAnnotations;
34 import org.openecomp.core.validation.types.GlobalValidationContext;
35 import org.openecomp.sdc.heat.datatypes.model.ResourceReferenceFunctions;
37 public class HeatStructureUtilTest {
40 private GlobalValidationContext globalValidationContextMock;
43 public void setUp() throws Exception {
44 MockitoAnnotations.openMocks(this);
48 public void testIsResourceNestedFalse() {
49 Assert.assertFalse(HeatStructureUtil.isNestedResource("Test.txt"));
53 public void testIsResourceNestedNull() {
54 Assert.assertFalse(HeatStructureUtil.isNestedResource(null));
58 public void testIsResourceNestedTrue() {
59 Assert.assertTrue(HeatStructureUtil.isNestedResource("Test.yml"));
63 public void testGetReferencedValuesByFunctionNameAddMessageCall() {
64 Map<String, Object> propertyMap = new HashMap<>();
65 propertyMap.put(ResourceReferenceFunctions.GET_RESOURCE.getFunction(), Collections.emptyList());
67 Mockito.doNothing().when(globalValidationContextMock).addMessage(Mockito.anyString(), Mockito.any(),
70 Set<String> valueNames = HeatStructureUtil.getReferencedValuesByFunctionName("Main.yml",
71 ResourceReferenceFunctions.GET_RESOURCE.getFunction(), propertyMap, globalValidationContextMock);
73 Mockito.verify(globalValidationContextMock, Mockito.times(1))
74 .addMessage(Mockito.anyString(), Mockito.any(), Mockito.anyString());
75 Assert.assertTrue(valueNames.isEmpty());
79 public void testGetReferencedValuesByFunctionNameGetFile() {
80 Map<String, Object> propertyMap = new HashMap<>();
81 propertyMap.put(ResourceReferenceFunctions.GET_FILE.getFunction(), "file:///filename");
83 Set<String> valueNames = HeatStructureUtil.getReferencedValuesByFunctionName("Main.yml",
84 ResourceReferenceFunctions.GET_FILE.getFunction(), propertyMap, globalValidationContextMock);
86 Assert.assertFalse(valueNames.isEmpty());
87 Assert.assertTrue(valueNames.contains("filename"));
91 public void testGetReferencedValuesByFunctionNameGetFileValueList() {
92 Map<String, Object> propertyMap = new HashMap<>();
94 .put(ResourceReferenceFunctions.GET_FILE.getFunction(), Collections.singletonList("file:///filename"));
96 Set<String> valueNames = HeatStructureUtil.getReferencedValuesByFunctionName("Main.yml",
97 ResourceReferenceFunctions.GET_FILE.getFunction(), propertyMap, globalValidationContextMock);
99 Assert.assertFalse(valueNames.isEmpty());
100 Assert.assertTrue(valueNames.contains("filename"));
104 public void testGetReferencedValuesByFunctionNameGetFileValueListWithAnotherList() {
105 Map<String, Object> propertyMap = new HashMap<>();
106 propertyMap.put(ResourceReferenceFunctions.GET_FILE.getFunction(),
107 Collections.singletonList(Collections.emptyList()));
109 Set<String> valueNames = HeatStructureUtil.getReferencedValuesByFunctionName("Main.yml",
110 ResourceReferenceFunctions.GET_FILE.getFunction(), propertyMap, globalValidationContextMock);
112 Assert.assertTrue(valueNames.isEmpty());
116 public void testGetReferencedValuesByFunctionNamePassingPropertyMapWithSet() {
117 Set<String> valueNames = HeatStructureUtil.getReferencedValuesByFunctionName("Main.yml",
118 ResourceReferenceFunctions.GET_FILE.getFunction(), Collections.singletonList(new HashSet<>()),
119 globalValidationContextMock);
121 Assert.assertTrue(valueNames.isEmpty());
125 public void testGetReferencedValuesByFunctionNameGetFileValueListSet() {
126 Map<String, Object> propertyMap = new HashMap<>();
127 propertyMap.put(ResourceReferenceFunctions.GET_FILE.getFunction(),
130 Set<String> valueNames = HeatStructureUtil.getReferencedValuesByFunctionName("Main.yml",
131 ResourceReferenceFunctions.GET_FILE.getFunction(), propertyMap, globalValidationContextMock);
133 Assert.assertTrue(valueNames.isEmpty());
137 public void testGetReferencedValuesByFunctionNameIncorrectKeyWithSet() {
138 Map<String, Object> propertyMap = new HashMap<>();
139 propertyMap.put("test", new HashSet<>());
141 Set<String> valueNames = HeatStructureUtil.getReferencedValuesByFunctionName("Main.yml",
142 ResourceReferenceFunctions.GET_FILE.getFunction(), propertyMap, globalValidationContextMock);
144 Assert.assertTrue(valueNames.isEmpty());