8d5be849a034d5a147998d7adcf5099481acb552
[controller.git] / opendaylight / sal / api / src / test / java / org / opendaylight / controller / sal / packet / UDPTest.java
1
2 /*
3  * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
7  * and is available at http://www.eclipse.org/legal/epl-v10.html
8  */
9
10 package org.opendaylight.controller.sal.packet;
11
12 import junit.framework.Assert;
13
14 import org.junit.Test;
15
16 public class UDPTest {
17
18     @Test
19     public void testGetSourcePort() {
20         UDP udp = new UDP();
21         byte[] udpSourcePort = { 0, 118 };
22         udp.hdrFieldsMap.put("SourcePort", udpSourcePort);
23         short sourcePort = udp.getSourcePort();
24         Assert.assertTrue(sourcePort == 118);
25     }
26
27     @Test
28     public void testGetDestinationPort() {
29         UDP udp = new UDP();
30         byte[] udpDestinationPort = { 1, -69 };
31         udp.hdrFieldsMap.put("DestinationPort", udpDestinationPort);
32         short destinationPort = udp.getDestinationPort();
33         Assert.assertTrue(destinationPort == 443);
34     }
35
36     @Test
37     public void testGetLength() {
38         UDP udp = new UDP();
39         byte[] udpLength = { 0, 20 };
40         udp.hdrFieldsMap.put("Length", udpLength);
41         short length = udp.getLength();
42         Assert.assertTrue(length == 20);
43     }
44
45     @Test
46     public void testGetChecksum() {
47         UDP udp = new UDP();
48         byte[] udpChecksum = { 0, -56 };
49         udp.hdrFieldsMap.put("Checksum", udpChecksum);
50         short checksum = udp.getChecksum();
51         Assert.assertTrue(checksum == 200);
52     }
53
54     @Test
55     public void testSetSourcePort() {
56         UDP udp = new UDP();
57         short tcpSourcePort = 118;
58         udp.setSourcePort(tcpSourcePort);
59         byte[] sourcePort = udp.hdrFieldsMap.get("SourcePort");
60         Assert.assertTrue(sourcePort[0] == 0);
61         Assert.assertTrue(sourcePort[1] == 118);
62
63     }
64
65     @Test
66     public void testSetDestinationPort() {
67         UDP udp = new UDP();
68         short tcpDestinationPort = 443;
69         udp.setDestinationPort(tcpDestinationPort);
70         byte[] destinationPort = udp.hdrFieldsMap.get("DestinationPort");
71         Assert.assertTrue(destinationPort[0] == 1);
72         Assert.assertTrue(destinationPort[1] == -69);
73
74     }
75
76     @Test
77     public void testSetLength() {
78         UDP udp = new UDP();
79         short udpLength = 20;
80         udp.setLength(udpLength);
81         byte[] length = udp.hdrFieldsMap.get("Length");
82         Assert.assertTrue(length[0] == 0);
83         Assert.assertTrue(length[1] == 20);
84
85     }
86
87     @Test
88     public void testSetChecksum() {
89         UDP udp = new UDP();
90         short udpChecksum = 200;
91         udp.setChecksum(udpChecksum);
92         byte[] checksum = udp.hdrFieldsMap.get("Checksum");
93         Assert.assertTrue(checksum[0] == 0);
94         Assert.assertTrue(checksum[1] == -56);
95
96     }
97
98 }