blob: e3d69109c08f4c6c5895028d8d66ab6c42f9fbfe [file] [log] [blame]
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08001/*
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 */
16package org.onosproject.net.driver;
17
18import com.google.common.collect.ImmutableMap;
19import org.junit.Before;
20import org.junit.Test;
Thomas Vachuska80b0a802015-07-17 08:43:30 -070021import org.onosproject.net.DeviceId;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080022
23import static org.junit.Assert.*;
Thomas Vachuska80b0a802015-07-17 08:43:30 -070024import static org.onosproject.net.DeviceId.deviceId;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080025
26public class DefaultDriverDataTest {
27
Thomas Vachuska80b0a802015-07-17 08:43:30 -070028 public static final DeviceId DEVICE_ID = deviceId("of:0011223344556677");
29
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080030 DefaultDriver ddc;
31 DefaultDriverData data;
32
33 @Before
34 public void setUp() {
Thomas Vachuska635c2d72015-05-08 14:32:13 -070035 ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a",
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080036 ImmutableMap.of(TestBehaviour.class,
37 TestBehaviourImpl.class),
38 ImmutableMap.of("foo", "bar"));
Thomas Vachuska80b0a802015-07-17 08:43:30 -070039 data = new DefaultDriverData(ddc, DEVICE_ID);
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080040 }
41
42 @Test
43 public void basics() {
Thomas Vachuska80b0a802015-07-17 08:43:30 -070044 assertSame("incorrect driver", ddc, data.driver());
45 assertEquals("incorrect device id", DEVICE_ID, data.deviceId());
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080046 assertTrue("incorrect toString", data.toString().contains("foo.bar"));
47 }
48
49 @Test
50 public void behaviour() {
51 TestBehaviour behaviour = data.behaviour(TestBehaviour.class);
52 assertTrue("incorrect behaviour", behaviour instanceof TestBehaviourImpl);
53 }
54
55 @Test
56 public void setAndClearAnnotations() {
57 data.set("croc", "aqua");
58 data.set("roo", "mars");
59 data.set("dingo", "bat");
60 assertEquals("incorrect property", "bat", data.value("dingo"));
61 data.clear("dingo", "roo");
62 assertNull("incorrect property", data.value("dingo"));
63 assertNull("incorrect property", data.value("root"));
64 assertEquals("incorrect property", "aqua", data.value("croc"));
65 assertEquals("incorrect properties", 1, data.keys().size());
66 }
67
68 @Test
69 public void clearAllAnnotations() {
70 data.set("croc", "aqua");
71 data.set("roo", "mars");
72 data.set("dingo", "bat");
73 assertEquals("incorrect property", "bat", data.value("dingo"));
74 data.clear();
75 assertEquals("incorrect properties", 0, data.keys().size());
76 }
77
78}