blob: 273fa07b5de500472384689be9fec6acc659f35d [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 Hartaa380972014-04-03 10:24:46 -07004import net.onrc.onos.core.intent.ConstrainedShortestPathIntent;
5import net.onrc.onos.core.intent.Intent;
6import net.onrc.onos.core.intent.IntentOperation;
7import net.onrc.onos.core.intent.IntentOperationList;
8import net.onrc.onos.core.intent.PathIntent;
Jonathan Hart472062d2014-04-03 10:56:48 -07009import net.onrc.onos.core.topology.LinkEvent;
10import net.onrc.onos.core.topology.Path;
Jonathan Hart23701d12014-04-03 10:45:48 -070011import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koideb39c9d32014-02-20 01:21:47 -080012
13import org.junit.After;
14import org.junit.Before;
15import org.junit.Test;
16
17import com.esotericsoftware.kryo.Kryo;
18import com.esotericsoftware.kryo.io.Input;
19import com.esotericsoftware.kryo.io.Output;
20
Toshio Koide066506e2014-02-20 19:52:09 -080021/**
22 * @author Toshio Koide (t-koide@onlab.us)
23 */
Toshio Koideb39c9d32014-02-20 01:21:47 -080024public class IntentOperationListTest {
25
26 @Before
27 public void setUp() throws Exception {
28 }
29
30 @After
31 public void tearDown() throws Exception {
32 }
33
34 @Test
35 public void test() {
36 IntentOperationList opList = new IntentOperationList();
37
38 ConstrainedShortestPathIntent cspIntent1 =
39 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
40
41 Path path = new Path();
42 path.add(new LinkEvent(1L, 2L, 3L, 4L));
43 path.add(new LinkEvent(5L, 6L, 7L, 8L));
44 path.add(new LinkEvent(9L, 0L, 1L, 2L));
45
46 PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1);
47 opList.add(IntentOperation.Operator.ADD, pathIntent1);
48 opList.add(IntentOperation.Operator.REMOVE, new Intent("22"));
49
50 KryoFactory factory = new KryoFactory();
51 Kryo kryo = factory.newKryo();
52 Output output = new Output(1024);
53 kryo.writeObject(output, opList);
54 output.close();
55
56 byte[] bytes = output.toBytes();
57
58 Input input = new Input(bytes);
59 IntentOperationList rcvOpList = kryo.readObject(input, IntentOperationList.class);
60
61 assertEquals(2, rcvOpList.size());
62
63 IntentOperation op1 = rcvOpList.get(0);
64 IntentOperation op2 = rcvOpList.get(1);
65
66 assertEquals(IntentOperation.Operator.ADD, op1.operator);
67 PathIntent intent1 = (PathIntent) op1.intent;
68 assertEquals("11", intent1.getId());
69 assertEquals(3, intent1.getPath().size());
70
71 assertEquals(IntentOperation.Operator.REMOVE, op2.operator);
72 Intent intent2 = op2.intent;
73 assertEquals("22", intent2.getId());
74 }
75}