blob: 937c0fad4213f77306d5374e6991870ed1040afd [file] [log] [blame]
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +05301/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Mahesh Poojary Huawei1d17cad2016-06-02 12:53:41 +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.pce.util;
17
18import java.util.LinkedList;
19import java.util.List;
20
21import org.onosproject.net.device.DeviceListener;
22import org.onosproject.net.device.DeviceServiceAdapter;
23import org.onosproject.net.Device;
24import org.onosproject.net.DeviceId;
25
26/**
27 * Test fixture for the device service.
28 */
29public class MockDeviceService extends DeviceServiceAdapter {
30 private List<Device> devices = new LinkedList<>();
31 private DeviceListener listener;
32
33 public void addDevice(Device dev) {
34 devices.add(dev);
35 }
36
37 public void removeDevice(Device dev) {
38 devices.remove(dev);
39 }
40
41 @Override
42 public Device getDevice(DeviceId deviceId) {
43 for (Device dev : devices) {
44 if (dev.id().equals(deviceId)) {
45 return dev;
46 }
47 }
48 return null;
49 }
50
51 @Override
52 public Iterable<Device> getAvailableDevices() {
53 return devices;
54 }
55
56 @Override
57 public void addListener(DeviceListener listener) {
58 this.listener = listener;
59 }
60
61 /**
62 * Get the listener.
63 */
64 public DeviceListener getListener() {
65 return listener;
66 }
67}