Sean Condon | fae8e66 | 2016-12-15 10:25:13 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Laboratory |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package org.onosproject.drivers.microsemi.yang.utils; |
| 17 | |
| 18 | import static org.junit.Assert.assertEquals; |
| 19 | |
| 20 | import java.time.LocalDateTime; |
| 21 | import java.time.OffsetDateTime; |
| 22 | import java.time.ZoneId; |
| 23 | import java.time.ZoneOffset; |
| 24 | import java.time.ZonedDateTime; |
| 25 | |
| 26 | import org.junit.After; |
| 27 | import org.junit.Before; |
| 28 | import org.junit.Test; |
| 29 | import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715.ietfyangtypes.DateAndTime; |
| 30 | |
| 31 | public class IetfYangTypesUtilsTest { |
| 32 | |
| 33 | @Before |
| 34 | public void setUp() throws Exception { |
| 35 | } |
| 36 | |
| 37 | @After |
| 38 | public void tearDown() throws Exception { |
| 39 | } |
| 40 | |
| 41 | @Test |
| 42 | public void testFromYangDateTime() { |
| 43 | OffsetDateTime odt = IetfYangTypesUtils.fromYangDateTime(DateAndTime.fromString("2015-07-08T12:49:20.9Z")); |
| 44 | assertEquals(OffsetDateTime.of(2015, 7, 8, 12, 49, 20, 900000000, ZoneOffset.UTC), odt); |
| 45 | } |
| 46 | |
| 47 | @Test |
| 48 | public void testFromYangDateTimeZoned() { |
| 49 | ZonedDateTime zdt = IetfYangTypesUtils.fromYangDateTimeZoned(DateAndTime.fromString("2015-07-08T12:49:20.9Z"), |
| 50 | ZoneId.systemDefault()); |
| 51 | |
| 52 | assertEquals(OffsetDateTime.of(2015, 7, 8, 12, 49, 20, 900000000, ZoneOffset.UTC).toInstant(), |
| 53 | zdt.toOffsetDateTime().toInstant()); |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void testFromYangDateTimeToLocal() { |
| 58 | LocalDateTime ldt = IetfYangTypesUtils |
| 59 | .fromYangDateTimeToLocal(DateAndTime.fromString("2015-07-08T12:49:20.9Z")); |
| 60 | |
| 61 | OffsetDateTime odtExpected = OffsetDateTime.of(2015, 7, 8, 12, 49, 20, 900000000, ZoneOffset.UTC); |
| 62 | ZoneOffset offsetForcurrentZone = ZoneId.systemDefault().getRules().getOffset(ldt); |
| 63 | assertEquals(odtExpected.toInstant(), ldt.toInstant(offsetForcurrentZone)); |
| 64 | } |
| 65 | |
| 66 | } |