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