move actors code in drools-applications to policy/models
[policy/models.git] / models-interactions / model-impl / appc / src / test / java / org / onap / policy / appc / util / SerializationTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * appc
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.appc.util;
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
26
27 import java.time.Instant;
28 import java.time.ZoneId;
29 import java.time.ZonedDateTime;
30
31 import org.junit.Test;
32
33 public class SerializationTest {
34
35     @Test
36     public void test() {
37         String nameString = "Dorothy";
38         String jsonName = Serialization.gsonPretty.toJson(nameString, String.class);
39         assertEquals("\"Dorothy\"", jsonName);
40         String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class);
41         assertEquals("Dorothy", jsonInOutName);
42
43         Instant instant = Instant.ofEpochMilli(1516127215000L);
44         String instantString = Serialization.gsonPretty.toJson(instant, Instant.class);
45         assertEquals("1516127215000", instantString);
46         Instant outInstant = Serialization.gsonPretty.fromJson(instantString, Instant.class);
47         assertEquals(instant, outInstant);
48
49         ZonedDateTime zdt = ZonedDateTime.ofInstant(instant, ZoneId.of("UTC"));
50         String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class);
51         assertEquals("\"2018-01-16 18:26:55.000000+00:00\"", zdtString);
52         ZonedDateTime outZdt = Serialization.gsonPretty.fromJson(zdtString, ZonedDateTime.class);
53         assertEquals(zdt.getDayOfWeek(), outZdt.getDayOfWeek());
54
55         assertNull(Serialization.gsonPretty.fromJson("oz time is weird", ZonedDateTime.class));
56     }
57 }