blob: 39947636acc29c1e47eeab3a57bfbe20e29dc115 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
2 * Copyright 2014 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 */
tomca20e0c2014-09-03 23:22:24 -070016package org.onlab.onos.net.device;
17
alshabib63d5afe2014-09-15 09:40:24 -070018import static org.junit.Assert.assertEquals;
19import static org.onlab.onos.net.DeviceId.deviceId;
20
tomca20e0c2014-09-03 23:22:24 -070021import org.junit.Test;
22import org.onlab.onos.event.AbstractEventTest;
23import org.onlab.onos.net.DefaultDevice;
tom29df6f42014-09-05 08:14:14 -070024import org.onlab.onos.net.DefaultPort;
tomca20e0c2014-09-03 23:22:24 -070025import org.onlab.onos.net.Device;
tom29df6f42014-09-05 08:14:14 -070026import org.onlab.onos.net.Port;
27import org.onlab.onos.net.PortNumber;
tomca20e0c2014-09-03 23:22:24 -070028import org.onlab.onos.net.provider.ProviderId;
alshabib7911a052014-10-16 17:49:37 -070029import org.onlab.packet.ChassisId;
tomca20e0c2014-09-03 23:22:24 -070030
tomca20e0c2014-09-03 23:22:24 -070031/**
32 * Tests of the device event.
33 */
34public class DeviceEventTest extends AbstractEventTest {
35
36 private Device createDevice() {
tom7e02cda2014-09-18 12:05:46 -070037 return new DefaultDevice(new ProviderId("of", "foo"), deviceId("of:foo"),
alshabib7911a052014-10-16 17:49:37 -070038 Device.Type.SWITCH, "box", "hw", "sw", "sn", new ChassisId());
tomca20e0c2014-09-03 23:22:24 -070039 }
40
alshabib63d5afe2014-09-15 09:40:24 -070041 @Override
tomca20e0c2014-09-03 23:22:24 -070042 @Test
43 public void withTime() {
44 Device device = createDevice();
alshabib63d5afe2014-09-15 09:40:24 -070045 Port port = new DefaultPort(device, PortNumber.portNumber(123), true);
tomca20e0c2014-09-03 23:22:24 -070046 DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED,
alshabib63d5afe2014-09-15 09:40:24 -070047 device, port, 123L);
tomca20e0c2014-09-03 23:22:24 -070048 validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, 123L);
tom29df6f42014-09-05 08:14:14 -070049 assertEquals("incorrect port", port, event.port());
tomca20e0c2014-09-03 23:22:24 -070050 }
51
alshabib63d5afe2014-09-15 09:40:24 -070052 @Override
tomca20e0c2014-09-03 23:22:24 -070053 @Test
54 public void withoutTime() {
55 Device device = createDevice();
alshabib63d5afe2014-09-15 09:40:24 -070056 Port port = new DefaultPort(device, PortNumber.portNumber(123), true);
tomca20e0c2014-09-03 23:22:24 -070057 long before = System.currentTimeMillis();
Yuta HIGUCHI9ee0d5b2014-10-05 00:03:47 -070058 DeviceEvent event = new DeviceEvent(DeviceEvent.Type.DEVICE_ADDED, device, port);
tomca20e0c2014-09-03 23:22:24 -070059 long after = System.currentTimeMillis();
60 validateEvent(event, DeviceEvent.Type.DEVICE_ADDED, device, before, after);
61 }
62
63}