blob: 274f4b88d80b42f395fa707351d2c05c7026e3cd [file] [log] [blame]
tom5a9383a2014-10-02 07:33:52 -07001package org.onlab.onos.net;
2
3import org.junit.Test;
4
5import static com.google.common.collect.ImmutableSet.of;
6import static org.junit.Assert.*;
7import static org.onlab.onos.net.DefaultAnnotations.builder;
8
9/**
10 * Tests of the default annotations.
11 */
12public class DefaultAnnotationsTest {
13
14 private DefaultAnnotations annotations;
15
16 @Test
17 public void basics() {
18 annotations = builder().set("foo", "1").set("bar", "2").build();
19 assertEquals("incorrect keys", of("foo", "bar"), annotations.keys());
20 assertEquals("incorrect value", "1", annotations.value("foo"));
21 assertEquals("incorrect value", "2", annotations.value("bar"));
22 }
23
24 @Test
25 public void empty() {
26 annotations = builder().build();
27 assertTrue("incorrect keys", annotations.keys().isEmpty());
28 }
29
30 @Test
31 public void remove() {
32 annotations = builder().remove("foo").set("bar", "2").build();
33 assertEquals("incorrect keys", of("foo", "bar"), annotations.keys());
34 assertNull("incorrect value", annotations.value("foo"));
35 assertEquals("incorrect value", "2", annotations.value("bar"));
36 }
37
38 @Test
39 public void merge() {
40 annotations = builder().set("foo", "1").set("bar", "2").build();
41 assertEquals("incorrect keys", of("foo", "bar"), annotations.keys());
42
43 SparseAnnotations updates = builder().remove("foo").set("bar", "3").set("goo", "4").build();
44
45 annotations = DefaultAnnotations.merge(annotations, updates);
46 assertEquals("incorrect keys", of("goo", "bar"), annotations.keys());
47 assertNull("incorrect value", annotations.value("foo"));
48 assertEquals("incorrect value", "3", annotations.value("bar"));
49 }
50
51 @Test
52 public void noopMerge() {
53 annotations = builder().set("foo", "1").set("bar", "2").build();
54 assertEquals("incorrect keys", of("foo", "bar"), annotations.keys());
55
56 SparseAnnotations updates = builder().build();
57 assertSame("same annotations expected", annotations,
58 DefaultAnnotations.merge(annotations, updates));
59 assertSame("same annotations expected", annotations,
60 DefaultAnnotations.merge(annotations, null));
61 }
62
63 @Test(expected = NullPointerException.class)
64 public void badMerge() {
65 DefaultAnnotations.merge(null, null);
66 }
67
68}