Initial opendaylight infrastructure commit!!
[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 import org.opendaylight.controller.sal.packet.UDP;
16
17 public class UDPTest {
18
19     @Test
20     public void testGetSourcePort() {
21         UDP udp = new UDP();
22         byte[] udpSourcePort = { 0, 118 };
23         udp.hdrFieldsMap.put("SourcePort", udpSourcePort);
24         short sourcePort = udp.getSourcePort();
25         Assert.assertTrue(sourcePort == 118);
26     }
27
28     @Test
29     public void testGetDestinationPort() {
30         UDP udp = new UDP();
31         byte[] udpDestinationPort = { 1, -69 };
32         udp.hdrFieldsMap.put("DestinationPort", udpDestinationPort);
33         short destinationPort = udp.getDestinationPort();
34         Assert.assertTrue(destinationPort == 443);
35     }
36
37     @Test
38     public void testGetLength() {
39         UDP udp = new UDP();
40         byte[] udpLength = { 0, 20 };
41         udp.hdrFieldsMap.put("Length", udpLength);
42         short length = udp.getLength();
43         Assert.assertTrue(length == 20);
44     }
45
46     @Test
47     public void testGetChecksum() {
48         UDP udp = new UDP();
49         byte[] udpChecksum = { 0, -56 };
50         udp.hdrFieldsMap.put("Checksum", udpChecksum);
51         short checksum = udp.getChecksum();
52         Assert.assertTrue(checksum == 200);
53     }
54
55     @Test
56     public void testSetSourcePort() {
57         UDP udp = new UDP();
58         short tcpSourcePort = 118;
59         udp.setSourcePort(tcpSourcePort);
60         byte[] sourcePort = udp.hdrFieldsMap.get("SourcePort");
61         Assert.assertTrue(sourcePort[0] == 0);
62         Assert.assertTrue(sourcePort[1] == 118);
63
64     }
65
66     @Test
67     public void testSetDestinationPort() {
68         UDP udp = new UDP();
69         short tcpDestinationPort = 443;
70         udp.setDestinationPort(tcpDestinationPort);
71         byte[] destinationPort = udp.hdrFieldsMap.get("DestinationPort");
72         Assert.assertTrue(destinationPort[0] == 1);
73         Assert.assertTrue(destinationPort[1] == -69);
74
75     }
76
77     @Test
78     public void testSetLength() {
79         UDP udp = new UDP();
80         short udpLength = 20;
81         udp.setLength(udpLength);
82         byte[] length = udp.hdrFieldsMap.get("Length");
83         Assert.assertTrue(length[0] == 0);
84         Assert.assertTrue(length[1] == 20);
85
86     }
87
88     @Test
89     public void testSetChecksum() {
90         UDP udp = new UDP();
91         short udpChecksum = 200;
92         udp.setChecksum(udpChecksum);
93         byte[] checksum = udp.hdrFieldsMap.get("Checksum");
94         Assert.assertTrue(checksum[0] == 0);
95         Assert.assertTrue(checksum[1] == -56);
96
97     }
98
99 }