blob: 298fd3950e59426b28e80b2ae59c8e8493ff1bdb [file] [log] [blame]
Avantika-Huawei9e848e82016-09-01 12:12:42 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Avantika-Huawei9e848e82016-09-01 12:12:42 +05303 *
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.pcelabelstore.util;
17
Ray Milkeyd1c34da2018-06-22 18:10:53 -070018import org.onosproject.net.Device;
19import org.onosproject.net.DeviceId;
20import org.onosproject.net.device.DeviceListener;
21import org.onosproject.net.device.DeviceServiceAdapter;
22
Avantika-Huawei9e848e82016-09-01 12:12:42 +053023import java.util.LinkedList;
24import java.util.List;
25
Avantika-Huawei9e848e82016-09-01 12:12:42 +053026/**
27 * Test fixture for the device service.
28 */
Ray Milkeyd1c34da2018-06-22 18:10:53 -070029public class MockDeviceService extends DeviceServiceAdapter {
Avantika-Huawei9e848e82016-09-01 12:12:42 +053030 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-Huawei9e848e82016-09-01 12:12:42 +053077}