2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.appclcm.util;
24 import static org.junit.Assert.assertEquals;
26 import java.time.Instant;
27 import java.time.ZoneId;
28 import java.time.ZonedDateTime;
29 import org.junit.Test;
31 public class SerializationTest {
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);
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);
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);
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));