Thomas Vachuska | a8f4e7d | 2015-01-08 17:31:55 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2015 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 | package org.onosproject.net.driver; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableMap; |
| 19 | import org.junit.Before; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import static org.junit.Assert.*; |
| 23 | |
| 24 | public class DefaultDriverDataTest { |
| 25 | |
| 26 | DefaultDriver ddc; |
| 27 | DefaultDriverData data; |
| 28 | |
| 29 | @Before |
| 30 | public void setUp() { |
| 31 | ddc = new DefaultDriver("foo.bar", "Circus", "lux", "1.2a", |
| 32 | ImmutableMap.of(TestBehaviour.class, |
| 33 | TestBehaviourImpl.class), |
| 34 | ImmutableMap.of("foo", "bar")); |
| 35 | data = new DefaultDriverData(ddc); |
| 36 | } |
| 37 | |
| 38 | @Test |
| 39 | public void basics() { |
| 40 | assertSame("incorrect type", ddc, data.type()); |
| 41 | assertTrue("incorrect toString", data.toString().contains("foo.bar")); |
| 42 | } |
| 43 | |
| 44 | @Test |
| 45 | public void behaviour() { |
| 46 | TestBehaviour behaviour = data.behaviour(TestBehaviour.class); |
| 47 | assertTrue("incorrect behaviour", behaviour instanceof TestBehaviourImpl); |
| 48 | } |
| 49 | |
| 50 | @Test |
| 51 | public void setAndClearAnnotations() { |
| 52 | data.set("croc", "aqua"); |
| 53 | data.set("roo", "mars"); |
| 54 | data.set("dingo", "bat"); |
| 55 | assertEquals("incorrect property", "bat", data.value("dingo")); |
| 56 | data.clear("dingo", "roo"); |
| 57 | assertNull("incorrect property", data.value("dingo")); |
| 58 | assertNull("incorrect property", data.value("root")); |
| 59 | assertEquals("incorrect property", "aqua", data.value("croc")); |
| 60 | assertEquals("incorrect properties", 1, data.keys().size()); |
| 61 | } |
| 62 | |
| 63 | @Test |
| 64 | public void clearAllAnnotations() { |
| 65 | data.set("croc", "aqua"); |
| 66 | data.set("roo", "mars"); |
| 67 | data.set("dingo", "bat"); |
| 68 | assertEquals("incorrect property", "bat", data.value("dingo")); |
| 69 | data.clear(); |
| 70 | assertEquals("incorrect properties", 0, data.keys().size()); |
| 71 | } |
| 72 | |
| 73 | } |