blob: b538acac115a290e8437d8a6a9618ed408af6879 [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() {
Ray Milkey269ffb92014-04-03 14:43:30 -070017 // reference bytes
18 final byte[] key = KVSwitch.getSwitchID(0x1L);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070019
Ray Milkey269ffb92014-04-03 14:43:30 -070020 assertEquals(0x1L, KVSwitch.getDpidFromKey(key));
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070021 }
22
23 @Test
24 public void testGetDpidFromKeyByteBuffer() {
Ray Milkey269ffb92014-04-03 14:43:30 -070025 // reference bytes
26 final ByteBuffer key = ByteBuffer.wrap(KVSwitch.getSwitchID(0x1L));
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070027
Ray Milkey269ffb92014-04-03 14:43:30 -070028 assertEquals(0x1L, KVSwitch.getDpidFromKey(key));
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070029 }
30
31 @Test
32 public void testCreateFromKeyByteArray() {
Ray Milkey269ffb92014-04-03 14:43:30 -070033 // reference bytes
34 Long dpid = Long.valueOf(0x1L);
35 final byte[] key = KVSwitch.getSwitchID(dpid);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070036
Ray Milkey269ffb92014-04-03 14:43:30 -070037 KVSwitch sw = KVSwitch.createFromKey(key);
38 assertNotNull(sw);
39 assertEquals(dpid, sw.getDpid());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070040 }
41
42 @Test
43 public void testGetStatus() {
Ray Milkey269ffb92014-04-03 14:43:30 -070044 KVSwitch sw = new KVSwitch(0x1L);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070045
Ray Milkey269ffb92014-04-03 14:43:30 -070046 assertEquals(STATUS.INACTIVE, sw.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070047 }
48
49 @Test
50 public void testSetStatus() {
Ray Milkey269ffb92014-04-03 14:43:30 -070051 KVSwitch sw = new KVSwitch(0x1L);
52 assertEquals(STATUS.INACTIVE, sw.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070053
Ray Milkey269ffb92014-04-03 14:43:30 -070054 sw.setStatus(STATUS.ACTIVE);
55 assertEquals(STATUS.ACTIVE, sw.getStatus());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070056 }
57
58 @Test
59 public void testGetDpid() {
Ray Milkey269ffb92014-04-03 14:43:30 -070060 Long dpid = 0x1L;
61 KVSwitch sw = new KVSwitch(dpid);
62 assertEquals(dpid, sw.getDpid());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070063 }
64
65 @Test
66 public void testGetId() {
Ray Milkey269ffb92014-04-03 14:43:30 -070067 // reference bytes
68 Long dpid = Long.valueOf(0x1L);
69 final byte[] key = KVSwitch.getSwitchID(dpid);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070070
Ray Milkey269ffb92014-04-03 14:43:30 -070071 KVSwitch sw = KVSwitch.createFromKey(key);
72 assertArrayEquals(key, sw.getId());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070073 }
74
75 @Test
76 public void testToString() {
Ray Milkey269ffb92014-04-03 14:43:30 -070077 final String expected = "[" + "KVSwitch"
78 + " 0x" + 1 + " STATUS:" + STATUS.INACTIVE + "]";
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070079
Ray Milkey269ffb92014-04-03 14:43:30 -070080 Long dpid = 0x1L;
81 KVSwitch sw = new KVSwitch(dpid);
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070082
Ray Milkey269ffb92014-04-03 14:43:30 -070083 assertEquals(expected, sw.toString());
Yuta HIGUCHI6a643132014-03-18 22:39:27 -070084 }
85}