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 | |
Jonathan Hart | a88fd24 | 2014-04-03 11:24:54 -0700 | [diff] [blame] | 3 | import static org.junit.Assert.assertArrayEquals; |
| 4 | import static org.junit.Assert.assertEquals; |
| 5 | import static org.junit.Assert.assertNotNull; |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 6 | |
| 7 | import java.nio.ByteBuffer; |
| 8 | |
Jonathan Hart | 6df9017 | 2014-04-03 10:13:11 -0700 | [diff] [blame] | 9 | import net.onrc.onos.core.datastore.topology.KVSwitch.STATUS; |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 10 | |
| 11 | import org.junit.Test; |
| 12 | |
| 13 | public 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 | } |