Hesam Rahimi | 4a409b4 | 2016-08-12 18:37:33 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2016-present 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.restconf.ctl; |
| 18 | |
| 19 | import static org.junit.Assert.assertEquals; |
| 20 | import static org.junit.Assert.assertFalse; |
| 21 | import static org.junit.Assert.assertTrue; |
| 22 | |
| 23 | import java.util.concurrent.ExecutorService; |
| 24 | import java.util.concurrent.Executors; |
| 25 | |
| 26 | import org.junit.Before; |
| 27 | import org.junit.Test; |
| 28 | import org.onlab.packet.IpAddress; |
| 29 | import org.onosproject.protocol.rest.DefaultRestSBDevice; |
| 30 | import org.onosproject.protocol.rest.RestSBDevice; |
| 31 | |
| 32 | /** |
| 33 | * Basic testing for RestSBController. |
| 34 | */ |
| 35 | public class RestConfSBControllerImplTest { |
| 36 | |
| 37 | RestConfSBControllerImpl restConfController; |
| 38 | |
| 39 | RestSBDevice device3; |
| 40 | |
| 41 | ExecutorService executor = Executors.newSingleThreadExecutor(); |
| 42 | |
| 43 | @Before |
| 44 | public void setUp() { |
| 45 | restConfController = new RestConfSBControllerImpl(); |
| 46 | restConfController.activate(); |
| 47 | device3 = new DefaultRestSBDevice(IpAddress.valueOf("127.0.0.1"), 8181, |
| 48 | "", "", "http", null, true); |
| 49 | restConfController.addDevice(device3); |
| 50 | |
| 51 | } |
| 52 | |
| 53 | @Test |
| 54 | public void basics() { |
| 55 | assertTrue("Device3 non added", |
| 56 | restConfController.getDevices().containsValue(device3)); |
| 57 | assertEquals("Device3 added but with wrong key", |
| 58 | restConfController.getDevices().get(device3.deviceId()), |
| 59 | device3); |
| 60 | assertEquals("Incorrect Get Device by ID", |
| 61 | restConfController.getDevice(device3.deviceId()), device3); |
| 62 | assertEquals("Incorrect Get Device by IP, Port", |
| 63 | restConfController.getDevice(device3.ip(), device3.port()), |
| 64 | device3); |
| 65 | restConfController.removeDevice(device3.deviceId()); |
| 66 | assertFalse("Device3 not removed", |
| 67 | restConfController.getDevices().containsValue(device3)); |
| 68 | } |
| 69 | } |