blob: eb1a853a12be3856a0da8e2270103a3124af22b3 [file] [log] [blame]
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -08003 *
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
Andrea Campanella80520b82016-01-05 17:55:29 -080023import java.util.ArrayList;
24
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080025import static org.junit.Assert.*;
Thomas Vachuska80b0a802015-07-17 08:43:30 -070026import static org.onosproject.net.DeviceId.deviceId;
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080027
28public class DefaultDriverDataTest {
29
Thomas Vachuska80b0a802015-07-17 08:43:30 -070030 public static final DeviceId DEVICE_ID = deviceId("of:0011223344556677");
31
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080032 DefaultDriver ddc;
33 DefaultDriverData data;
34
35 @Before
36 public void setUp() {
Andrea Campanella80520b82016-01-05 17:55:29 -080037 ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a",
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080038 ImmutableMap.of(TestBehaviour.class,
39 TestBehaviourImpl.class),
40 ImmutableMap.of("foo", "bar"));
Thomas Vachuska80b0a802015-07-17 08:43:30 -070041 data = new DefaultDriverData(ddc, DEVICE_ID);
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080042 }
43
44 @Test
45 public void basics() {
Thomas Vachuska80b0a802015-07-17 08:43:30 -070046 assertSame("incorrect driver", ddc, data.driver());
47 assertEquals("incorrect device id", DEVICE_ID, data.deviceId());
Thomas Vachuskaa8f4e7d2015-01-08 17:31:55 -080048 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}