blob: 54eaf8c17c1217e4e92b129f47a50c6654ad3a29 [file] [log] [blame]
Jonathan Hart6df90172014-04-03 10:13:11 -07001package net.onrc.onos.core.datastore.topology;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -07002
Jonathan Harta88fd242014-04-03 11:24:54 -07003import static org.junit.Assert.assertArrayEquals;
4import static org.junit.Assert.assertEquals;
5import static org.junit.Assert.assertNotNull;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -07006
7import java.nio.ByteBuffer;
8
Jonathan Hart6df90172014-04-03 10:13:11 -07009import net.onrc.onos.core.datastore.topology.KVSwitch.STATUS;
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070010
11import org.junit.Test;
12
13public class KVSwitchNoDataStoreTest {
14
15 @Test
16 public void testGetDpidFromKeyByteArray() {
17 // reference bytes
18 final byte[] key = KVSwitch.getSwitchID(0x1L);
19
20 assertEquals(0x1L, KVSwitch.getDpidFromKey(key));
21 }
22
23 @Test
24 public void testGetDpidFromKeyByteBuffer() {
25 // reference bytes
26 final ByteBuffer key = ByteBuffer.wrap(KVSwitch.getSwitchID(0x1L));
27
28 assertEquals(0x1L, KVSwitch.getDpidFromKey(key));
29 }
30
31 @Test
32 public void testCreateFromKeyByteArray() {
33 // reference bytes
34 Long dpid = Long.valueOf(0x1L);
35 final byte[] key = KVSwitch.getSwitchID(dpid);
36
37 KVSwitch sw = KVSwitch.createFromKey(key);
38 assertNotNull(sw);
39 assertEquals(dpid, sw.getDpid());
40 }
41
42 @Test
43 public void testGetStatus() {
44 KVSwitch sw = new KVSwitch(0x1L);
45
46 assertEquals(STATUS.INACTIVE, sw.getStatus());
47 }
48
49 @Test
50 public void testSetStatus() {
51 KVSwitch sw = new KVSwitch(0x1L);
52 assertEquals(STATUS.INACTIVE, sw.getStatus());
53
54 sw.setStatus(STATUS.ACTIVE);
55 assertEquals(STATUS.ACTIVE, sw.getStatus());
56 }
57
58 @Test
59 public void testGetDpid() {
60 Long dpid = 0x1L;
61 KVSwitch sw = new KVSwitch(dpid);
62 assertEquals(dpid, sw.getDpid());
63 }
64
65 @Test
66 public void testGetId() {
67 // reference bytes
68 Long dpid = Long.valueOf(0x1L);
69 final byte[] key = KVSwitch.getSwitchID(dpid);
70
71 KVSwitch sw = KVSwitch.createFromKey(key);
72 assertArrayEquals(key, sw.getId());
73 }
74
75 @Test
76 public void testToString() {
77 final String expected = "[" + "KVSwitch"
78 + " 0x" + 1 + " STATUS:" + STATUS.INACTIVE + "]";
79
80 Long dpid = 0x1L;
81 KVSwitch sw = new KVSwitch(dpid);
82
83 assertEquals(expected, sw.toString());
84 }
85}