Toshio Koide | b39c9d3 | 2014-02-20 01:21:47 -0800 | [diff] [blame] | 1 | package net.onrc.onos.intent; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | import net.onrc.onos.ofcontroller.networkgraph.LinkEvent; |
| 5 | import net.onrc.onos.ofcontroller.networkgraph.Path; |
| 6 | import net.onrc.onos.ofcontroller.util.serializers.KryoFactory; |
| 7 | |
| 8 | import org.junit.After; |
| 9 | import org.junit.Before; |
| 10 | import org.junit.Test; |
| 11 | |
| 12 | import com.esotericsoftware.kryo.Kryo; |
| 13 | import com.esotericsoftware.kryo.io.Input; |
| 14 | import com.esotericsoftware.kryo.io.Output; |
| 15 | |
Toshio Koide | 066506e | 2014-02-20 19:52:09 -0800 | [diff] [blame] | 16 | /** |
| 17 | * @author Toshio Koide (t-koide@onlab.us) |
| 18 | */ |
Toshio Koide | b39c9d3 | 2014-02-20 01:21:47 -0800 | [diff] [blame] | 19 | public class IntentOperationListTest { |
| 20 | |
| 21 | @Before |
| 22 | public void setUp() throws Exception { |
| 23 | } |
| 24 | |
| 25 | @After |
| 26 | public void tearDown() throws Exception { |
| 27 | } |
| 28 | |
| 29 | @Test |
| 30 | public void test() { |
| 31 | IntentOperationList opList = new IntentOperationList(); |
| 32 | |
| 33 | ConstrainedShortestPathIntent cspIntent1 = |
| 34 | new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0); |
| 35 | |
| 36 | Path path = new Path(); |
| 37 | path.add(new LinkEvent(1L, 2L, 3L, 4L)); |
| 38 | path.add(new LinkEvent(5L, 6L, 7L, 8L)); |
| 39 | path.add(new LinkEvent(9L, 0L, 1L, 2L)); |
| 40 | |
| 41 | PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1); |
| 42 | opList.add(IntentOperation.Operator.ADD, pathIntent1); |
| 43 | opList.add(IntentOperation.Operator.REMOVE, new Intent("22")); |
| 44 | |
| 45 | KryoFactory factory = new KryoFactory(); |
| 46 | Kryo kryo = factory.newKryo(); |
| 47 | Output output = new Output(1024); |
| 48 | kryo.writeObject(output, opList); |
| 49 | output.close(); |
| 50 | |
| 51 | byte[] bytes = output.toBytes(); |
| 52 | |
| 53 | Input input = new Input(bytes); |
| 54 | IntentOperationList rcvOpList = kryo.readObject(input, IntentOperationList.class); |
| 55 | |
| 56 | assertEquals(2, rcvOpList.size()); |
| 57 | |
| 58 | IntentOperation op1 = rcvOpList.get(0); |
| 59 | IntentOperation op2 = rcvOpList.get(1); |
| 60 | |
| 61 | assertEquals(IntentOperation.Operator.ADD, op1.operator); |
| 62 | PathIntent intent1 = (PathIntent) op1.intent; |
| 63 | assertEquals("11", intent1.getId()); |
| 64 | assertEquals(3, intent1.getPath().size()); |
| 65 | |
| 66 | assertEquals(IntentOperation.Operator.REMOVE, op2.operator); |
| 67 | Intent intent2 = op2.intent; |
| 68 | assertEquals("22", intent2.getId()); |
| 69 | } |
| 70 | } |