Catalog alignment
[sdc.git] / common-be / src / test / java / org / openecomp / sdc / be / utils / TypeUtilsTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
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  * Modifications copyright (c) 2019 Nokia
20  * ================================================================================
21  */
22 package org.openecomp.sdc.be.utils;
23
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.mockito.Mockito;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
29
30 import java.util.HashMap;
31 import java.util.Map;
32 import java.util.function.Consumer;
33
34 @RunWith(MockitoJUnitRunner.class)
35 public class TypeUtilsTest {
36
37     private static final String ANY_GROUP = "anyGroup";
38
39     @SuppressWarnings("unchecked")
40     private Consumer<String> anyConsumer = (Consumer<String>) Mockito.spy(Consumer.class);
41
42     @Test
43     public void testSetFieldShouldConsumeForJSONContainingParam() {
44         Map<String, Object> toscaJson = new HashMap<>();
45         toscaJson.put(ToscaTagNamesEnum.GROUPS.getElementName(), ANY_GROUP);
46         TypeUtils.setField(toscaJson, ToscaTagNamesEnum.GROUPS, anyConsumer);
47         Mockito.verify(anyConsumer).accept(ANY_GROUP);
48     }
49
50     @Test
51     public void testSetFieldShouldDoNothingForJSONNotContainingParam() {
52         Map<String, Object> toscaJson = new HashMap<>();
53         toscaJson.put(ToscaTagNamesEnum.GROUPS.getElementName(), ANY_GROUP);
54         TypeUtils.setField(toscaJson, ToscaTagNamesEnum.INPUTS, anyConsumer);
55         Mockito.verifyZeroInteractions(anyConsumer);
56     }
57
58 }