Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.device; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 17 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 18 | import static org.junit.Assert.assertEquals; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 19 | import static org.onosproject.net.DeviceId.deviceId; |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 20 | |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 21 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 22 | import org.onosproject.event.AbstractEventTest; |
| 23 | import org.onosproject.net.DefaultDevice; |
| 24 | import org.onosproject.net.DefaultPort; |
| 25 | import org.onosproject.net.Device; |
| 26 | import org.onosproject.net.Port; |
| 27 | import org.onosproject.net.PortNumber; |
| 28 | import org.onosproject.net.provider.ProviderId; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 29 | import org.onlab.packet.ChassisId; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 30 | |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 31 | /** |
| 32 | * Tests of the device event. |
| 33 | */ |
| 34 | public class DeviceEventTest extends AbstractEventTest { |
| 35 | |
| 36 | private Device createDevice() { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 37 | return new DefaultDevice(new ProviderId("of", "foo"), deviceId("of:foo"), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame] | 38 | Device.Type.SWITCH, "box", "hw", "sw", "sn", new ChassisId()); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 39 | } |
| 40 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 41 | @Override |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 42 | @Test |
| 43 | public void withTime() { |
| 44 | Device device = createDevice(); |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 45 | Port port = new DefaultPort(device, PortNumber.portNumber(123), true); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 46 | DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 47 | device, port, 123L); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 48 | validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, 123L); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 49 | assertEquals("incorrect port", port, event.port()); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 50 | } |
| 51 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 52 | @Override |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 53 | @Test |
| 54 | public void withoutTime() { |
| 55 | Device device = createDevice(); |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 56 | Port port = new DefaultPort(device, PortNumber.portNumber(123), true); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 57 | long before = System.currentTimeMillis(); |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 58 | DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, port); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 59 | long after = System.currentTimeMillis(); |
| 60 | validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, before, after); |
| 61 | } |
| 62 | |
| 63 | } |