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