Andrea Campanella | ce279ee | 2016-01-25 10:21:45 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016 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 | */ |
| 16 | |
| 17 | package org.onosproject.protocol.rest.ctl; |
| 18 | |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | import org.onlab.packet.IpAddress; |
| 22 | import org.onosproject.protocol.rest.DefaultRestSBDevice; |
| 23 | import org.onosproject.protocol.rest.RestSBDevice; |
| 24 | |
| 25 | import static org.junit.Assert.*; |
| 26 | |
| 27 | /** |
| 28 | * Basic testing for RestSBController. |
| 29 | */ |
| 30 | public 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(); |
| 42 | device1 = new DefaultRestSBDevice(IpAddress.valueOf("127.0.0.1"), 8080, "foo", "bar", "http", true); |
| 43 | device2 = new DefaultRestSBDevice(IpAddress.valueOf("127.0.0.2"), 8080, "foo1", "bar2", "http", true); |
| 44 | 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)); |
| 56 | controller.removeDevice(device2); |
| 57 | assertFalse("Device2 not removed", controller.getDevices().containsValue(device2)); |
| 58 | } |
| 59 | } |