blob: a5ce194f4df66df871f817857f74842526fbdb6f [file] [log] [blame]
Charles M.C. Chanea5aa472015-01-03 13:40:39 +08001/*
2 * Copyright 2014 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19package org.onlab.packet.ndp;
20
21import org.junit.BeforeClass;
22import org.junit.Test;
23import org.onlab.packet.Data;
24
25import static org.junit.Assert.assertArrayEquals;
26import static org.junit.Assert.assertTrue;
27
28/**
29 * Tests for class {@link RouterSolicitation}.
30 */
31public class RouterSolicitationTest {
32 private static final byte[] OPTION = {
33 (byte) 0x01, (byte) 0x08, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01
34 };
35 private static Data data;
36 private static byte[] bytePacket;
37
38 @BeforeClass
39 public static void setUpBeforeClass() throws Exception {
40 data = new Data();
41 data.setData(OPTION);
42
43 byte[] bytePayload = data.serialize();
44 byte[] byteHeader = {(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
45 bytePacket = new byte[byteHeader.length + bytePayload.length];
46 System.arraycopy(byteHeader, 0, bytePacket, 0, byteHeader.length);
47 System.arraycopy(bytePayload, 0, bytePacket, byteHeader.length, bytePayload.length);
48 }
49
50 /**
51 * Tests serialize and setters.
52 */
53 @Test
54 public void testSerialize() {
55 RouterSolicitation rs = new RouterSolicitation();
56 rs.setPayload(data);
57
58 assertArrayEquals(rs.serialize(), bytePacket);
59 }
60
61 /**
62 * Tests deserialize and getters.
63 */
64 @Test
65 public void testDeserialize() {
66 RouterSolicitation rs = new RouterSolicitation();
67 rs.deserialize(bytePacket, 0, bytePacket.length);
68 }
69
70 /**
71 * Tests comparator.
72 */
73 @Test
74 public void testEqual() {
75 RouterSolicitation rs1 = new RouterSolicitation();
76
77 assertTrue(rs1.equals(rs1));
78 }
79}