blob: 767dce7dd554bd03e1957f0ce3c1470c78a9e600 [file] [log] [blame]
Andrea Campanellace279ee2016-01-25 10:21:45 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Andrea Campanellace279ee2016-01-25 10:21:45 -08003 *
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
17package org.onosproject.protocol.rest.ctl;
18
19import org.junit.Before;
20import org.junit.Test;
21import org.onlab.packet.IpAddress;
22import org.onosproject.protocol.rest.DefaultRestSBDevice;
23import org.onosproject.protocol.rest.RestSBDevice;
24
25import static org.junit.Assert.*;
26
27/**
28 * Basic testing for RestSBController.
29 */
30public class RestSBControllerImplTest {
31
32 RestSBControllerImpl controller;
33
34 RestSBDevice device1;
35 RestSBDevice device2;
36
37
38 @Before
39 public void setUp() {
40 controller = new RestSBControllerImpl();
41 controller.activate();
Andrea Campanella2947e622016-01-27 09:23:46 -080042 device1 = new DefaultRestSBDevice(IpAddress.valueOf("127.0.0.1"), 8080, "foo", "bar", "http", null, true);
43 device2 = new DefaultRestSBDevice(IpAddress.valueOf("127.0.0.2"), 8080, "foo1", "bar2", "http", null, true);
Andrea Campanellace279ee2016-01-25 10:21:45 -080044 controller.addDevice(device1);
45 }
46
47 @Test
48 public void basics() {
49 assertTrue("Device1 non added", controller.getDevices().containsValue(device1));
50 assertEquals("Device1 added but with wrong key", controller.getDevices()
51 .get(device1.deviceId()), device1);
52 assertEquals("Incorrect Get Device by ID", controller.getDevice(device1.deviceId()), device1);
53 assertEquals("Incorrect Get Device by IP, Port", controller.getDevice(device1.ip(), device1.port()), device1);
54 controller.addDevice(device2);
55 assertTrue("Device2 non added", controller.getDevices().containsValue(device2));
Andrea Campanella86294db2016-03-07 11:42:49 -080056 controller.removeDevice(device2.deviceId());
Andrea Campanellace279ee2016-01-25 10:21:45 -080057 assertFalse("Device2 not removed", controller.getDevices().containsValue(device2));
58 }
59}