Adding unit tests
[sdc.git] / catalog-model / src / test / java / org / openecomp / sdc / be / model / tosca / converters / ToscaValueBaseConverterTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2021 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  */
20
21 package org.openecomp.sdc.be.model.tosca.converters;
22
23 import com.google.gson.JsonPrimitive;
24 import static org.junit.jupiter.api.Assertions.assertFalse;
25 import static org.junit.jupiter.api.Assertions.assertTrue;
26 import org.junit.jupiter.api.Test;
27
28
29 import java.util.HashMap;
30 import java.util.LinkedList;
31
32
33 public class ToscaValueBaseConverterTest {
34
35     private ToscaValueBaseConverter converter = new ToscaValueBaseConverter();
36
37     @Test
38     public void testJson2JavaPrimitive() throws Exception {
39         JsonPrimitive prim1 = new JsonPrimitive(Boolean.FALSE);
40         Object res1 = converter.json2JavaPrimitive(prim1);
41         assertFalse((Boolean)res1);
42
43         JsonPrimitive prim2 = new JsonPrimitive("Test");
44         Object res2 = converter.json2JavaPrimitive(prim2);
45         assertTrue(res2.equals("Test"));
46
47         JsonPrimitive prim3 = new JsonPrimitive(3);
48         Object res3 = converter.json2JavaPrimitive(prim3);
49         assertTrue((Integer)res3 == 3);
50
51         JsonPrimitive prim4 = new JsonPrimitive(3.6);
52         Object res4 = converter.json2JavaPrimitive(prim4);
53         assertTrue((Double)res4 == 3.6);
54     }
55
56     @Test
57     public void testIsEmptyObjectValue() throws Exception {
58         boolean res1 = ToscaValueBaseConverter.isEmptyObjectValue(null);
59         assertTrue(res1);
60
61         boolean res2 = ToscaValueBaseConverter.isEmptyObjectValue("");
62         assertTrue(res2);
63
64         boolean res3 = ToscaValueBaseConverter.isEmptyObjectValue(new HashMap<>());
65         assertTrue(res3);
66
67         boolean res4 = ToscaValueBaseConverter.isEmptyObjectValue(new LinkedList<>());
68         assertTrue(res4);
69
70         boolean res5 = ToscaValueBaseConverter.isEmptyObjectValue("test");
71         assertFalse(res5);
72     }
73 }