Jonathan Hart | aa38097 | 2014-04-03 10:24:46 -0700 | [diff] [blame] | 1 | package net.onrc.onos.core.intent; |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 2 | |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 3 | import static org.junit.Assert.assertEquals; |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 4 | |
Jonathan Hart | 23701d1 | 2014-04-03 10:45:48 -0700 | [diff] [blame] | 5 | import net.onrc.onos.core.util.serializers.KryoFactory; |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 6 | |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 7 | import org.junit.After; |
| 8 | import org.junit.Before; |
| 9 | import org.junit.Test; |
| 10 | |
Toshio Koide | 0e4d8d2 | 2014-02-14 10:56:10 -0800 | [diff] [blame] | 11 | import com.esotericsoftware.kryo.Kryo; |
| 12 | import com.esotericsoftware.kryo.io.Input; |
| 13 | import com.esotericsoftware.kryo.io.Output; |
| 14 | |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 15 | /** |
| 16 | * @author Toshio Koide (t-koide@onlab.us) |
| 17 | */ |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 18 | public class ConstrainedShortestPathIntentTest { |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 19 | @Before |
| 20 | public void setUp() throws Exception { |
| 21 | } |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 22 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 23 | @After |
| 24 | public void tearDown() throws Exception { |
| 25 | } |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 26 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 27 | @Test |
| 28 | public void testCreate() { |
| 29 | ConstrainedShortestPathIntent intent1 = |
| 30 | new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0); |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 31 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 32 | assertEquals("1", intent1.getId()); |
| 33 | assertEquals(2L, intent1.getSrcSwitchDpid()); |
| 34 | assertEquals(3L, intent1.getSrcPortNumber()); |
| 35 | assertEquals(4L, intent1.getSrcMac()); |
| 36 | assertEquals(5L, intent1.getDstSwitchDpid()); |
| 37 | assertEquals(6L, intent1.getDstPortNumber()); |
| 38 | assertEquals(7L, intent1.getDstMac()); |
| 39 | assertEquals(1000.0, intent1.getBandwidth(), 0.0); |
| 40 | } |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 41 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 42 | @Test |
| 43 | public void testKryo() { |
| 44 | KryoFactory factory = new KryoFactory(); |
| 45 | Kryo kryo = factory.newKryo(); |
| 46 | Output output = new Output(1000); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 47 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 48 | ConstrainedShortestPathIntent intent1 = |
| 49 | new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0); |
| 50 | kryo.writeObject(output, intent1); |
Toshio Koide | fe1d5d9 | 2014-02-26 20:09:48 -0800 | [diff] [blame] | 51 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 52 | output.close(); |
| 53 | byte bytes[] = output.toBytes(); |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 54 | |
Ray Milkey | 269ffb9 | 2014-04-03 14:43:30 -0700 | [diff] [blame] | 55 | Input input = new Input(bytes); |
| 56 | ConstrainedShortestPathIntent intent2 = kryo.readObject(input, ConstrainedShortestPathIntent.class); |
| 57 | input.close(); |
| 58 | assertEquals("1", intent2.getId()); |
| 59 | assertEquals(2L, intent2.getSrcSwitchDpid()); |
| 60 | assertEquals(3L, intent2.getSrcPortNumber()); |
| 61 | assertEquals(4L, intent2.getSrcMac()); |
| 62 | assertEquals(5L, intent2.getDstSwitchDpid()); |
| 63 | assertEquals(6L, intent2.getDstPortNumber()); |
| 64 | assertEquals(7L, intent2.getDstMac()); |
| 65 | assertEquals(1000.0, intent2.getBandwidth(), 0.0); |
| 66 | } |
Toshio Koide | ebdbb62 | 2014-02-12 20:28:38 -0800 | [diff] [blame] | 67 | } |