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() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 17 | // reference bytes |
| 18 | final byte[] key = KVSwitch.getSwitchID(0x1L); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 19 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 20 | assertEquals(0x1L, KVSwitch.getDpidFromKey(key)); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | @Test |
| 24 | public void testGetDpidFromKeyByteBuffer() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 25 | // reference bytes |
| 26 | final ByteBuffer key = ByteBuffer.wrap(KVSwitch.getSwitchID(0x1L)); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 27 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 28 | assertEquals(0x1L, KVSwitch.getDpidFromKey(key)); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | @Test |
| 32 | public void testCreateFromKeyByteArray() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 33 | // reference bytes |
| 34 | Long dpid = Long.valueOf(0x1L); |
| 35 | final byte[] key = KVSwitch.getSwitchID(dpid); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 36 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 37 | KVSwitch sw = KVSwitch.createFromKey(key); |
| 38 | assertNotNull(sw); |
| 39 | assertEquals(dpid, sw.getDpid()); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | @Test |
| 43 | public void testGetStatus() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 44 | KVSwitch sw = new KVSwitch(0x1L); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 45 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 46 | assertEquals(STATUS.INACTIVE, sw.getStatus()); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | @Test |
| 50 | public void testSetStatus() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 51 | KVSwitch sw = new KVSwitch(0x1L); |
| 52 | assertEquals(STATUS.INACTIVE, sw.getStatus()); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 53 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 54 | sw.setStatus(STATUS.ACTIVE); |
| 55 | assertEquals(STATUS.ACTIVE, sw.getStatus()); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Test |
| 59 | public void testGetDpid() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 60 | Long dpid = 0x1L; |
| 61 | KVSwitch sw = new KVSwitch(dpid); |
| 62 | assertEquals(dpid, sw.getDpid()); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | @Test |
| 66 | public void testGetId() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 67 | // reference bytes |
| 68 | Long dpid = Long.valueOf(0x1L); |
| 69 | final byte[] key = KVSwitch.getSwitchID(dpid); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 70 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 71 | KVSwitch sw = KVSwitch.createFromKey(key); |
| 72 | assertArrayEquals(key, sw.getId()); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | @Test |
| 76 | public void testToString() { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 77 | final String expected = "[" + "KVSwitch" |
| 78 | + " 0x" + 1 + " STATUS:" + STATUS.INACTIVE + "]"; |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 79 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 80 | Long dpid = 0x1L; |
| 81 | KVSwitch sw = new KVSwitch(dpid); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 82 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame^] | 83 | assertEquals(expected, sw.toString()); |
Yuta HIGUCHI | 6a64313 | 2014-03-18 22:39:27 -0700 | [diff] [blame] | 84 | } |
| 85 | } |