blob: 4d7c6c071bb51f71cf60c54bd49ecdd6ef18070a [file] [log] [blame]
Sean Condon0e89bda2017-03-21 14:23:19 +00001/*
2 * Copyright 2017-present Open Networking Foundation
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.incubator.net.l2monitoring.soam;
17
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertNull;
20
21import java.time.Duration;
22import java.time.OffsetDateTime;
23import java.time.ZoneOffset;
24import java.time.format.DateTimeFormatter;
25
26import org.junit.Test;
27import org.onosproject.incubator.net.l2monitoring.soam.StartTime.StartTimeOption;
28import org.onosproject.incubator.net.l2monitoring.soam.StopTime.StopTimeOption;
29
30public class StartTimeTest {
31
32 @Test
33 public void testStartImmediate() {
34 StartTime st = StartTime.immediate();
35 assertEquals(StartTimeOption.IMMEDIATE, st.option());
36 assertNull(st.relativeTime());
37 assertNull(st.absoluteTime());
38 }
39
40 @Test
41 public void testStartRelative() {
42 StartTime st = StartTime.relative(Duration.ofMinutes(20));
43 assertEquals(StartTimeOption.RELATIVE, st.option());
44 assertEquals(20 * 60, st.relativeTime().getSeconds());
45 assertNull(st.absoluteTime());
46 }
47
48 @Test
49 public void testStartAbsolute() {
50 StartTime st = StartTime.absolute(OffsetDateTime
51 .of(2017, 3, 20, 11, 43, 11, 0, ZoneOffset.ofHours(-7))
52 .toInstant());
53 assertEquals(StartTimeOption.ABSOLUTE, st.option());
54 assertNull(st.relativeTime());
55 assertEquals("2017-03-20T11:43:11-07:00", st
56 .absoluteTime()
57 .atOffset(ZoneOffset.ofHours(-7))
58 .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
59 }
60
61 @Test
62 public void testStopImmediate() {
63 StopTime st = StopTime.none();
64 assertEquals(StopTimeOption.NONE, st.option());
65 assertNull(st.relativeTime());
66 assertNull(st.absoluteTime());
67 }
68
69 @Test
70 public void testStopRelative() {
71 StopTime st = StopTime.relative(Duration.ofMinutes(20));
72 assertEquals(StopTimeOption.RELATIVE, st.option());
73 assertEquals(20 * 60, st.relativeTime().getSeconds());
74 assertNull(st.absoluteTime());
75 }
76
77 @Test
78 public void testStopAbsolute() {
79 StopTime st = StopTime.absolute(OffsetDateTime
80 .of(2017, 3, 20, 11, 43, 11, 0, ZoneOffset.ofHours(-7))
81 .toInstant());
82 assertEquals(StopTimeOption.ABSOLUTE, st.option());
83 assertNull(st.relativeTime());
84 assertEquals("2017-03-20T11:43:11-07:00", st
85 .absoluteTime()
86 .atOffset(ZoneOffset.ofHours(-7))
87 .format(DateTimeFormatter.ISO_OFFSET_DATE_TIME));
88 }
89
90}