Update the license for 2017-2018 license
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / PojoUtilsTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 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 package org.onap.aai.util;
21
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25
26 import java.time.LocalDateTime;
27 import java.time.Month;
28
29 import org.junit.Test;
30 import org.mockito.Mockito;
31
32 public class PojoUtilsTest {
33
34         @Test
35         public void testGetJsonFromObject_Clazz_MockTest() throws Exception {
36
37                 String obj = "helloWorld";
38                 PojoUtils pojoUtils = Mockito.mock(PojoUtils.class);
39                 Mockito.doCallRealMethod().when(pojoUtils).getJsonFromObject(Mockito.anyString());
40
41                 pojoUtils.getJsonFromObject(obj);
42
43                 Mockito.verify(pojoUtils, Mockito.times(1)).getJsonFromObject(Mockito.anyString(), Mockito.eq(false), Mockito.eq(true));
44         }
45
46         @Test
47         public void testGetJsonFromObject_Clazz() throws Exception {
48                 
49                 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
50                 LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
51
52                 String res = pojoUtils.getJsonFromObject(date);
53
54                 assertNotNull(res);
55                 assertTrue(res.contains("\"dayOfMonth\" : 18"));
56                 assertTrue(res.contains("\"dayOfWeek\" : \"MONDAY\""));
57                 assertTrue(res.contains("\"dayOfYear\" : 261"));
58                 assertTrue(res.contains("\"hour\" : 10"));
59                 assertTrue(res.contains("\"minute\" : 55"));
60                 assertTrue(res.contains("\"month\" : \"SEPTEMBER\""));
61                 assertTrue(res.contains("\"monthValue\" : 9"));
62                 assertTrue(res.contains("\"nano\" : 300"));
63                 assertTrue(res.contains("\"second\" : 0"));
64                 assertTrue(res.contains("\"year\" : 2017"));
65         }
66         
67         @Test
68         public void testGetJsonFromObject_Clazz_null() throws Exception {
69                 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
70                 
71                 String res = pojoUtils.getJsonFromObject(null);
72
73                 assertNotNull(res);
74                 assertEquals("null", res);
75         }
76         
77         @Test
78         public void testGetJsonFromObject_null() throws Exception {
79                 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
80                 
81                 String res = pojoUtils.getJsonFromObject(null, false, true);
82
83                 assertNotNull(res);
84                 assertEquals("null", res);
85         }
86
87         @Test
88         public void testGetJsonFromObject() throws Exception {
89                 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
90                 LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
91                 
92                 String res = pojoUtils.getJsonFromObject(date, false, false);
93                 assertNotNull(res);
94                 
95                 res = pojoUtils.getJsonFromObject(date, true, false);
96                 assertNotNull(res);
97                 
98                 res = pojoUtils.getJsonFromObject(date, true, true);
99                 assertNotNull(res);
100         }
101
102         static PojoUtils getInstance() {
103                 return new PojoUtils(); 
104         }
105 }