tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 1 | package org.onlab.onos.net.device; |
| 2 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
| 4 | import static org.onlab.onos.net.DeviceId.deviceId; |
| 5 | |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 6 | import org.junit.Test; |
| 7 | import org.onlab.onos.event.AbstractEventTest; |
| 8 | import org.onlab.onos.net.DefaultDevice; |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 9 | import org.onlab.onos.net.DefaultPort; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 10 | import org.onlab.onos.net.Device; |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 11 | import org.onlab.onos.net.Port; |
| 12 | import org.onlab.onos.net.PortNumber; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 13 | import org.onlab.onos.net.provider.ProviderId; |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame^] | 14 | import org.onlab.packet.ChassisId; |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 15 | |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 16 | /** |
| 17 | * Tests of the device event. |
| 18 | */ |
| 19 | public class DeviceEventTest extends AbstractEventTest { |
| 20 | |
| 21 | private Device createDevice() { |
tom | 7e02cda | 2014-09-18 12:05:46 -0700 | [diff] [blame] | 22 | return new DefaultDevice(new ProviderId("of", "foo"), deviceId("of:foo"), |
alshabib | 7911a05 | 2014-10-16 17:49:37 -0700 | [diff] [blame^] | 23 | Device.Type.SWITCH, "box", "hw", "sw", "sn", new ChassisId()); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 24 | } |
| 25 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 26 | @Override |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 27 | @Test |
| 28 | public void withTime() { |
| 29 | Device device = createDevice(); |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 30 | Port port = new DefaultPort(device, PortNumber.portNumber(123), true); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 31 | DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 32 | device, port, 123L); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 33 | validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, 123L); |
tom | 29df6f4 | 2014-09-05 08:14:14 -0700 | [diff] [blame] | 34 | assertEquals("incorrect port", port, event.port()); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 35 | } |
| 36 | |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 37 | @Override |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 38 | @Test |
| 39 | public void withoutTime() { |
| 40 | Device device = createDevice(); |
alshabib | 63d5afe | 2014-09-15 09:40:24 -0700 | [diff] [blame] | 41 | Port port = new DefaultPort(device, PortNumber.portNumber(123), true); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 42 | long before = System.currentTimeMillis(); |
Yuta HIGUCHI | 9ee0d5b | 2014-10-05 00:03:47 -0700 | [diff] [blame] | 43 | DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, port); |
tom | ca20e0c | 2014-09-03 23:22:24 -0700 | [diff] [blame] | 44 | long after = System.currentTimeMillis(); |
| 45 | validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, before, after); |
| 46 | } |
| 47 | |
| 48 | } |