Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Foundation |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [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 | */ |
| 16 | package org.onosproject.pcelabelstore.util; |
| 17 | |
Ray Milkey | d1c34da | 2018-06-22 18:10:53 -0700 | [diff] [blame^] | 18 | import org.onosproject.net.Device; |
| 19 | import org.onosproject.net.DeviceId; |
| 20 | import org.onosproject.net.device.DeviceListener; |
| 21 | import org.onosproject.net.device.DeviceServiceAdapter; |
| 22 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 23 | import java.util.LinkedList; |
| 24 | import java.util.List; |
| 25 | |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 26 | /** |
| 27 | * Test fixture for the device service. |
| 28 | */ |
Ray Milkey | d1c34da | 2018-06-22 18:10:53 -0700 | [diff] [blame^] | 29 | public class MockDeviceService extends DeviceServiceAdapter { |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 30 | private List<Device> devices = new LinkedList<>(); |
| 31 | private DeviceListener listener; |
| 32 | |
| 33 | /** |
| 34 | * Adds a new device. |
| 35 | * |
| 36 | * @param dev device to be added |
| 37 | */ |
| 38 | public void addDevice(Device dev) { |
| 39 | devices.add(dev); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Removes the specified device. |
| 44 | * |
| 45 | * @param dev device to be removed |
| 46 | */ |
| 47 | public void removeDevice(Device dev) { |
| 48 | devices.remove(dev); |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public Device getDevice(DeviceId deviceId) { |
| 53 | for (Device dev : devices) { |
| 54 | if (dev.id().equals(deviceId)) { |
| 55 | return dev; |
| 56 | } |
| 57 | } |
| 58 | return null; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public Iterable<Device> getAvailableDevices() { |
| 63 | return devices; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public void addListener(DeviceListener listener) { |
| 68 | this.listener = listener; |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * Get the listener. |
| 73 | */ |
| 74 | public DeviceListener getListener() { |
| 75 | return listener; |
| 76 | } |
Avantika-Huawei | 9e848e8 | 2016-09-01 12:12:42 +0530 | [diff] [blame] | 77 | } |