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