Changes for Checkstyle 8.32
[policy/models.git] / models-interactions / model-impl / appclcm / src / test / java / org / onap / policy / appclcm / util / SerializationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appclcm
4  * ================================================================================
5  * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2019 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.appclcm.util;
23
24 import static org.junit.Assert.assertEquals;
25
26 import java.time.Instant;
27 import java.time.ZoneId;
28 import java.time.ZonedDateTime;
29 import org.junit.Test;
30
31 public class SerializationTest {
32
33     @Test
34     public void test() {
35         String nameString = "Dorothy";
36         String jsonName = Serialization.gsonPretty.toJson(nameString, String.class);
37         assertEquals("\"Dorothy\"", jsonName);
38         String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class);
39         assertEquals("Dorothy", jsonInOutName);
40
41         Instant instant0 = Instant.ofEpochMilli(1516127215000L);
42         String instantString0 = Serialization.gsonPretty.toJson(instant0, Instant.class);
43         assertEquals("\"2018-01-16T18:26:55Z\"", instantString0);
44         Instant outInstant0 = Serialization.gsonPretty.fromJson(instantString0, Instant.class);
45         assertEquals(instant0, outInstant0);
46
47         Instant instant1 = Instant.ofEpochMilli(1516127215000L);
48         String instantString1 = Serialization.gsonJunit.toJson(instant1, Instant.class);
49         assertEquals("1516127215000", instantString1);
50         Instant outInstant1 = Serialization.gsonJunit.fromJson(instantString1, Instant.class);
51         assertEquals(instant1, outInstant1);
52
53         ZonedDateTime zdt = ZonedDateTime.ofInstant(instant0, ZoneId.of("UTC"));
54         String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class);
55         assertEquals("{\n  \"dateTime\": {\n    \"date\":", zdtString.substring(0, 29));
56     }
57 }