blob: 876d2b16f4b533e3ee716e0a86646ab410c6522a [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Toshio Koideb39c9d32014-02-20 01:21:47 -08002
3import static org.junit.Assert.assertEquals;
Jonathan Hart472062d2014-04-03 10:56:48 -07004import net.onrc.onos.core.topology.LinkEvent;
Jonathan Hart23701d12014-04-03 10:45:48 -07005import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koideb39c9d32014-02-20 01:21:47 -08006
7import org.junit.After;
8import org.junit.Before;
9import org.junit.Test;
10
11import com.esotericsoftware.kryo.Kryo;
12import com.esotericsoftware.kryo.io.Input;
13import com.esotericsoftware.kryo.io.Output;
14
Toshio Koide066506e2014-02-20 19:52:09 -080015/**
16 * @author Toshio Koide (t-koide@onlab.us)
17 */
Toshio Koideb39c9d32014-02-20 01:21:47 -080018public class IntentOperationListTest {
19
Ray Milkey269ffb92014-04-03 14:43:30 -070020 @Before
21 public void setUp() throws Exception {
22 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080023
Ray Milkey269ffb92014-04-03 14:43:30 -070024 @After
25 public void tearDown() throws Exception {
26 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080027
Ray Milkey269ffb92014-04-03 14:43:30 -070028 @Test
29 public void test() {
30 IntentOperationList opList = new IntentOperationList();
Toshio Koideb39c9d32014-02-20 01:21:47 -080031
Ray Milkey269ffb92014-04-03 14:43:30 -070032 ConstrainedShortestPathIntent cspIntent1 =
33 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
Toshio Koideb39c9d32014-02-20 01:21:47 -080034
Ray Milkey269ffb92014-04-03 14:43:30 -070035 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 Koideb39c9d32014-02-20 01:21:47 -080039
Ray Milkey269ffb92014-04-03 14:43:30 -070040 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 Koideb39c9d32014-02-20 01:21:47 -080043
Ray Milkey269ffb92014-04-03 14:43:30 -070044 KryoFactory factory = new KryoFactory();
45 Kryo kryo = factory.newKryo();
46 Output output = new Output(1024);
47 kryo.writeObject(output, opList);
48 output.close();
Toshio Koideb39c9d32014-02-20 01:21:47 -080049
Ray Milkey269ffb92014-04-03 14:43:30 -070050 byte[] bytes = output.toBytes();
Toshio Koideb39c9d32014-02-20 01:21:47 -080051
Ray Milkey269ffb92014-04-03 14:43:30 -070052 Input input = new Input(bytes);
53 IntentOperationList rcvOpList = kryo.readObject(input, IntentOperationList.class);
Toshio Koideb39c9d32014-02-20 01:21:47 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 assertEquals(2, rcvOpList.size());
Toshio Koideb39c9d32014-02-20 01:21:47 -080056
Ray Milkey269ffb92014-04-03 14:43:30 -070057 IntentOperation op1 = rcvOpList.get(0);
58 IntentOperation op2 = rcvOpList.get(1);
Toshio Koideb39c9d32014-02-20 01:21:47 -080059
Ray Milkey269ffb92014-04-03 14:43:30 -070060 assertEquals(IntentOperation.Operator.ADD, op1.operator);
61 PathIntent intent1 = (PathIntent) op1.intent;
62 assertEquals("11", intent1.getId());
63 assertEquals(3, intent1.getPath().size());
Toshio Koideb39c9d32014-02-20 01:21:47 -080064
Ray Milkey269ffb92014-04-03 14:43:30 -070065 assertEquals(IntentOperation.Operator.REMOVE, op2.operator);
66 Intent intent2 = op2.intent;
67 assertEquals("22", intent2.getId());
68 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080069}