blob: 2d09a8d0c61667c3e656ad29ad042e6c955c28b4 [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;
Ray Milkey269ffb92014-04-03 14:43:30 -07004
Jonathan Hart472062d2014-04-03 10:56:48 -07005import net.onrc.onos.core.topology.LinkEvent;
6import net.onrc.onos.core.topology.Path;
Jonathan Hart23701d12014-04-03 10:45:48 -07007import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koideb39c9d32014-02-20 01:21:47 -08008
9import org.junit.After;
10import org.junit.Before;
11import org.junit.Test;
12
13import com.esotericsoftware.kryo.Kryo;
14import com.esotericsoftware.kryo.io.Input;
15import com.esotericsoftware.kryo.io.Output;
16
Toshio Koide066506e2014-02-20 19:52:09 -080017/**
18 * @author Toshio Koide (t-koide@onlab.us)
19 */
Toshio Koideb39c9d32014-02-20 01:21:47 -080020public class IntentOperationListTest {
21
Ray Milkey269ffb92014-04-03 14:43:30 -070022 @Before
23 public void setUp() throws Exception {
24 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080025
Ray Milkey269ffb92014-04-03 14:43:30 -070026 @After
27 public void tearDown() throws Exception {
28 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080029
Ray Milkey269ffb92014-04-03 14:43:30 -070030 @Test
31 public void test() {
32 IntentOperationList opList = new IntentOperationList();
Toshio Koideb39c9d32014-02-20 01:21:47 -080033
Ray Milkey269ffb92014-04-03 14:43:30 -070034 ConstrainedShortestPathIntent cspIntent1 =
35 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
Toshio Koideb39c9d32014-02-20 01:21:47 -080036
Ray Milkey269ffb92014-04-03 14:43:30 -070037 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 Koideb39c9d32014-02-20 01:21:47 -080041
Ray Milkey269ffb92014-04-03 14:43:30 -070042 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 Koideb39c9d32014-02-20 01:21:47 -080045
Ray Milkey269ffb92014-04-03 14:43:30 -070046 KryoFactory factory = new KryoFactory();
47 Kryo kryo = factory.newKryo();
48 Output output = new Output(1024);
49 kryo.writeObject(output, opList);
50 output.close();
Toshio Koideb39c9d32014-02-20 01:21:47 -080051
Ray Milkey269ffb92014-04-03 14:43:30 -070052 byte[] bytes = output.toBytes();
Toshio Koideb39c9d32014-02-20 01:21:47 -080053
Ray Milkey269ffb92014-04-03 14:43:30 -070054 Input input = new Input(bytes);
55 IntentOperationList rcvOpList = kryo.readObject(input, IntentOperationList.class);
Toshio Koideb39c9d32014-02-20 01:21:47 -080056
Ray Milkey269ffb92014-04-03 14:43:30 -070057 assertEquals(2, rcvOpList.size());
Toshio Koideb39c9d32014-02-20 01:21:47 -080058
Ray Milkey269ffb92014-04-03 14:43:30 -070059 IntentOperation op1 = rcvOpList.get(0);
60 IntentOperation op2 = rcvOpList.get(1);
Toshio Koideb39c9d32014-02-20 01:21:47 -080061
Ray Milkey269ffb92014-04-03 14:43:30 -070062 assertEquals(IntentOperation.Operator.ADD, op1.operator);
63 PathIntent intent1 = (PathIntent) op1.intent;
64 assertEquals("11", intent1.getId());
65 assertEquals(3, intent1.getPath().size());
Toshio Koideb39c9d32014-02-20 01:21:47 -080066
Ray Milkey269ffb92014-04-03 14:43:30 -070067 assertEquals(IntentOperation.Operator.REMOVE, op2.operator);
68 Intent intent2 = op2.intent;
69 assertEquals("22", intent2.getId());
70 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080071}