Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 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 | package org.onosproject.net.driver; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 21 | import org.onosproject.net.DeviceId; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 22 | |
Andrea Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 23 | import java.util.ArrayList; |
| 24 | |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 25 | import static org.junit.Assert.*; |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 26 | import static org.onosproject.net.DeviceId.deviceId; |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 27 | |
| 28 | public class DefaultDriverDataTest { |
| 29 | |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 30 | public static final DeviceId DEVICE_ID = deviceId("of:0011223344556677"); |
| 31 | |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 32 | DefaultDriver ddc; |
| 33 | DefaultDriverData data; |
| 34 | |
| 35 | @Before |
| 36 | public void setUp() { |
Andrea Campanella | 80520b8 | 2016-01-05 17:55:29 -0800 | [diff] [blame] | 37 | ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a", |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 38 | ImmutableMap.of(TestBehaviour.class, |
| 39 | TestBehaviourImpl.class), |
| 40 | ImmutableMap.of("foo", "bar")); |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 41 | data = new DefaultDriverData(ddc, DEVICE_ID); |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | @Test |
| 45 | public void basics() { |
Thomas Vachuska | 80b0a80 | 2015-07-17 08:43:30 -0700 | [diff] [blame] | 46 | assertSame("incorrect driver", ddc, data.driver()); |
| 47 | assertEquals("incorrect device id", DEVICE_ID, data.deviceId()); |
Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 48 | assertTrue("incorrect toString", data.toString().contains("foo.bar")); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void behaviour() { |
| 53 | TestBehaviour behaviour = data.behaviour(TestBehaviour.class); |
| 54 | assertTrue("incorrect behaviour", behaviour instanceof TestBehaviourImpl); |
| 55 | } |
| 56 | |
| 57 | @Test |
| 58 | public void setAndClearAnnotations() { |
| 59 | data.set("croc", "aqua"); |
| 60 | data.set("roo", "mars"); |
| 61 | data.set("dingo", "bat"); |
| 62 | assertEquals("incorrect property", "bat", data.value("dingo")); |
| 63 | data.clear("dingo", "roo"); |
| 64 | assertNull("incorrect property", data.value("dingo")); |
| 65 | assertNull("incorrect property", data.value("root")); |
| 66 | assertEquals("incorrect property", "aqua", data.value("croc")); |
| 67 | assertEquals("incorrect properties", 1, data.keys().size()); |
| 68 | } |
| 69 | |
| 70 | @Test |
| 71 | public void clearAllAnnotations() { |
| 72 | data.set("croc", "aqua"); |
| 73 | data.set("roo", "mars"); |
| 74 | data.set("dingo", "bat"); |
| 75 | assertEquals("incorrect property", "bat", data.value("dingo")); |
| 76 | data.clear(); |
| 77 | assertEquals("incorrect properties", 0, data.keys().size()); |
| 78 | } |
| 79 | |
| 80 | } |