blob: 30cdfb8c10b19a3e0820a1a2db2ea9b9cb3d49b6 [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;
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -07005import net.onrc.onos.core.util.SwitchPort;
Jonathan Hart23701d12014-04-03 10:45:48 -07006import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koideb39c9d32014-02-20 01:21:47 -08007
8import org.junit.After;
9import org.junit.Before;
10import org.junit.Test;
11
12import com.esotericsoftware.kryo.Kryo;
13import com.esotericsoftware.kryo.io.Input;
14import com.esotericsoftware.kryo.io.Output;
15
Toshio Koide066506e2014-02-20 19:52:09 -080016/**
Yuta HIGUCHId4acc802014-06-19 22:30:31 -070017 * Unit tests for IntentOperationList.
Toshio Koide066506e2014-02-20 19:52:09 -080018 */
Toshio Koideb39c9d32014-02-20 01:21:47 -080019public class IntentOperationListTest {
20
Ray Milkey269ffb92014-04-03 14:43:30 -070021 @Before
22 public void setUp() throws Exception {
23 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080024
Ray Milkey269ffb92014-04-03 14:43:30 -070025 @After
26 public void tearDown() throws Exception {
27 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080028
Ray Milkey269ffb92014-04-03 14:43:30 -070029 @Test
30 public void test() {
31 IntentOperationList opList = new IntentOperationList();
Toshio Koideb39c9d32014-02-20 01:21:47 -080032
Ray Milkey269ffb92014-04-03 14:43:30 -070033 ConstrainedShortestPathIntent cspIntent1 =
34 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
Toshio Koideb39c9d32014-02-20 01:21:47 -080035
Ray Milkey269ffb92014-04-03 14:43:30 -070036 Path path = new Path();
Yuta HIGUCHIe2a4e172014-07-03 10:50:39 -070037 path.add(new LinkEvent(new SwitchPort(1L, 2L), new SwitchPort(3L, 4L)));
38 path.add(new LinkEvent(new SwitchPort(5L, 6L), new SwitchPort(7L, 8L)));
39 path.add(new LinkEvent(new SwitchPort(9L, 0L), new SwitchPort(1L, 2L)));
Toshio Koideb39c9d32014-02-20 01:21:47 -080040
Ray Milkey269ffb92014-04-03 14:43:30 -070041 PathIntent pathIntent1 = new PathIntent("11", path, 123.45, cspIntent1);
42 opList.add(IntentOperation.Operator.ADD, pathIntent1);
43 opList.add(IntentOperation.Operator.REMOVE, new Intent("22"));
Toshio Koideb39c9d32014-02-20 01:21:47 -080044
Ray Milkey269ffb92014-04-03 14:43:30 -070045 KryoFactory factory = new KryoFactory();
46 Kryo kryo = factory.newKryo();
47 Output output = new Output(1024);
48 kryo.writeObject(output, opList);
49 output.close();
Toshio Koideb39c9d32014-02-20 01:21:47 -080050
Ray Milkey269ffb92014-04-03 14:43:30 -070051 byte[] bytes = output.toBytes();
Toshio Koideb39c9d32014-02-20 01:21:47 -080052
Ray Milkey269ffb92014-04-03 14:43:30 -070053 Input input = new Input(bytes);
54 IntentOperationList rcvOpList = kryo.readObject(input, IntentOperationList.class);
Toshio Koideb39c9d32014-02-20 01:21:47 -080055
Ray Milkey269ffb92014-04-03 14:43:30 -070056 assertEquals(2, rcvOpList.size());
Toshio Koideb39c9d32014-02-20 01:21:47 -080057
Ray Milkey269ffb92014-04-03 14:43:30 -070058 IntentOperation op1 = rcvOpList.get(0);
59 IntentOperation op2 = rcvOpList.get(1);
Toshio Koideb39c9d32014-02-20 01:21:47 -080060
Ray Milkey269ffb92014-04-03 14:43:30 -070061 assertEquals(IntentOperation.Operator.ADD, op1.operator);
62 PathIntent intent1 = (PathIntent) op1.intent;
63 assertEquals("11", intent1.getId());
64 assertEquals(3, intent1.getPath().size());
Toshio Koideb39c9d32014-02-20 01:21:47 -080065
Ray Milkey269ffb92014-04-03 14:43:30 -070066 assertEquals(IntentOperation.Operator.REMOVE, op2.operator);
67 Intent intent2 = op2.intent;
68 assertEquals("22", intent2.getId());
69 }
Toshio Koideb39c9d32014-02-20 01:21:47 -080070}