blob: 4e62beb82908b61cd3cedf77c4cd92828519c958 [file] [log] [blame]
Sean Condonfae8e662016-12-15 10:25:13 +00001/*
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 */
16package org.onosproject.drivers.microsemi.yang.utils;
17
18import static org.junit.Assert.assertEquals;
19
20import java.time.LocalDateTime;
21import java.time.OffsetDateTime;
22import java.time.ZoneId;
23import java.time.ZoneOffset;
24import java.time.ZonedDateTime;
25
26import org.junit.After;
27import org.junit.Before;
28import org.junit.Test;
29import org.onosproject.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev20130715.ietfyangtypes.DateAndTime;
30
31public 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}