blob: f3ada977b3806e16bca1cf0371ab66bb3b3a3930 [file] [log] [blame]
Jonathan Hartaa380972014-04-03 10:24:46 -07001package net.onrc.onos.core.intent;
Toshio Koideebdbb622014-02-12 20:28:38 -08002
Toshio Koidefe1d5d92014-02-26 20:09:48 -08003import static org.junit.Assert.assertEquals;
Ray Milkey269ffb92014-04-03 14:43:30 -07004
Jonathan Hart23701d12014-04-03 10:45:48 -07005import net.onrc.onos.core.util.serializers.KryoFactory;
Toshio Koide0e4d8d22014-02-14 10:56:10 -08006
Toshio Koideebdbb622014-02-12 20:28:38 -08007import org.junit.After;
8import org.junit.Before;
9import org.junit.Test;
10
Toshio Koide0e4d8d22014-02-14 10:56:10 -080011import 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/**
Yuta HIGUCHId4acc802014-06-19 22:30:31 -070016 * Unit tests for ConstrainedShortestPathIntent class.
Toshio Koide066506e2014-02-20 19:52:09 -080017 */
Toshio Koideebdbb622014-02-12 20:28:38 -080018public class ConstrainedShortestPathIntentTest {
Ray Milkey269ffb92014-04-03 14:43:30 -070019 @Before
20 public void setUp() throws Exception {
21 }
Toshio Koideebdbb622014-02-12 20:28:38 -080022
Ray Milkey269ffb92014-04-03 14:43:30 -070023 @After
24 public void tearDown() throws Exception {
25 }
Toshio Koideebdbb622014-02-12 20:28:38 -080026
Ray Milkey269ffb92014-04-03 14:43:30 -070027 @Test
28 public void testCreate() {
29 ConstrainedShortestPathIntent intent1 =
30 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
Toshio Koideebdbb622014-02-12 20:28:38 -080031
Ray Milkey269ffb92014-04-03 14:43:30 -070032 assertEquals("1", intent1.getId());
33 assertEquals(2L, intent1.getSrcSwitchDpid());
34 assertEquals(3L, intent1.getSrcPortNumber());
35 assertEquals(4L, intent1.getSrcMac());
36 assertEquals(5L, intent1.getDstSwitchDpid());
37 assertEquals(6L, intent1.getDstPortNumber());
38 assertEquals(7L, intent1.getDstMac());
39 assertEquals(1000.0, intent1.getBandwidth(), 0.0);
40 }
Toshio Koidefe1d5d92014-02-26 20:09:48 -080041
Ray Milkey269ffb92014-04-03 14:43:30 -070042 @Test
43 public void testKryo() {
44 KryoFactory factory = new KryoFactory();
45 Kryo kryo = factory.newKryo();
46 Output output = new Output(1000);
Toshio Koidefe1d5d92014-02-26 20:09:48 -080047
Ray Milkey269ffb92014-04-03 14:43:30 -070048 ConstrainedShortestPathIntent intent1 =
49 new ConstrainedShortestPathIntent("1", 2L, 3L, 4L, 5L, 6L, 7L, 1000.0);
50 kryo.writeObject(output, intent1);
Toshio Koidefe1d5d92014-02-26 20:09:48 -080051
Ray Milkey269ffb92014-04-03 14:43:30 -070052 output.close();
Yuta HIGUCHI44a0b352014-05-14 21:32:48 -070053 byte[] bytes = output.toBytes();
Toshio Koideebdbb622014-02-12 20:28:38 -080054
Ray Milkey269ffb92014-04-03 14:43:30 -070055 Input input = new Input(bytes);
56 ConstrainedShortestPathIntent intent2 = kryo.readObject(input, ConstrainedShortestPathIntent.class);
57 input.close();
58 assertEquals("1", intent2.getId());
59 assertEquals(2L, intent2.getSrcSwitchDpid());
60 assertEquals(3L, intent2.getSrcPortNumber());
61 assertEquals(4L, intent2.getSrcMac());
62 assertEquals(5L, intent2.getDstSwitchDpid());
63 assertEquals(6L, intent2.getDstPortNumber());
64 assertEquals(7L, intent2.getDstMac());
65 assertEquals(1000.0, intent2.getBandwidth(), 0.0);
66 }
Toshio Koideebdbb622014-02-12 20:28:38 -080067}