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;
 
  30 import org.junit.Test;
 
  32 public class SerializationTest {
 
  36         String nameString = "Dorothy";
 
  37         String jsonName = Serialization.gsonPretty.toJson(nameString, String.class);
 
  38         assertEquals("\"Dorothy\"", jsonName);
 
  39         String jsonInOutName = Serialization.gsonPretty.fromJson(jsonName, String.class);
 
  40         assertEquals("Dorothy", jsonInOutName);
 
  42         Instant instant0 = Instant.ofEpochMilli(1516127215000L);
 
  43         String instantString0 = Serialization.gsonPretty.toJson(instant0, Instant.class);
 
  44         assertEquals("\"2018-01-16T18:26:55Z\"", instantString0);
 
  45         Instant outInstant0 = Serialization.gsonPretty.fromJson(instantString0, Instant.class);
 
  46         assertEquals(instant0, outInstant0);
 
  48         Instant instant1 = Instant.ofEpochMilli(1516127215000L);
 
  49         String instantString1 = Serialization.gsonJunit.toJson(instant1, Instant.class);
 
  50         assertEquals("1516127215000", instantString1);
 
  51         Instant outInstant1 = Serialization.gsonJunit.fromJson(instantString1, Instant.class);
 
  52         assertEquals(instant1, outInstant1);
 
  54         ZonedDateTime zdt = ZonedDateTime.ofInstant(instant0, ZoneId.of("UTC"));
 
  55         String zdtString = Serialization.gsonPretty.toJson(zdt, ZonedDateTime.class);
 
  56         assertEquals("{\n  \"dateTime\": {\n    \"date\":", zdtString.substring(0, 29));