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