09ea63ad5eef147d207e16370e10315b5f5ca007
[openflowjava.git] / third-party / openflow-codec / src / test / java / org / openflow / codec / protocol / instruction / OFPInstructionGoToTableTest.java
1 package org.openflow.codec.protocol.instruction;
2
3 import junit.framework.TestCase;
4
5 import org.openflow.codec.io.DataBuffers;
6 import org.openflow.codec.io.IDataBuffer;
7 import org.openflow.codec.protocol.instruction.OFPInstructionGoToTable;
8 import org.openflow.codec.protocol.instruction.OFPInstructionType;
9
10 /**
11  * test class to verify instruction structure
12  *
13  * @author AnilGujele
14  *
15  */
16 public class OFPInstructionGoToTableTest extends TestCase {
17
18     private IDataBuffer buffer = DataBuffers.allocate(1024);
19
20     protected void tearDown() throws Exception {
21         buffer.clear();
22     }
23
24     public void testOFInstructionGoToTableCreation() {
25         OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
26         assertTrue(instruction.type.equals(OFPInstructionType.GOTO_TABLE));
27
28     }
29
30     public void testClone() throws CloneNotSupportedException {
31         OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
32         instruction.setTableId((byte) 2);
33         OFPInstructionGoToTable instructionCloned = (OFPInstructionGoToTable) instruction.clone();
34         TestCase.assertEquals(instruction, instructionCloned);
35
36         instruction.setTableId((byte) 1);
37         TestCase.assertNotSame(instruction, instructionCloned);
38
39         instruction = (OFPInstructionGoToTable) instructionCloned.clone();
40         TestCase.assertEquals(instruction, instructionCloned);
41     }
42
43     public void testReadWriteSuccess() {
44         OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
45         instruction.setTableId((byte) 2);
46         instruction.writeTo(buffer);
47         buffer.flip();
48
49         OFPInstructionGoToTable instructionTemp = new OFPInstructionGoToTable();
50         instructionTemp.readFrom(buffer);
51         TestCase.assertEquals(instruction, instructionTemp);
52
53     }
54
55     public void testToString() {
56         OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
57         instruction.setTableId((byte) 2);
58         instruction.writeTo(buffer);
59         buffer.flip();
60
61         OFPInstructionGoToTable instructionTemp = new OFPInstructionGoToTable();
62         instructionTemp.readFrom(buffer);
63         TestCase.assertEquals(instruction.toString(), instructionTemp.toString());
64     }
65
66     public void testEqualHashcode() {
67
68         OFPInstructionGoToTable instruction = new OFPInstructionGoToTable();
69         instruction.setTableId((byte) 2);
70         instruction.writeTo(buffer);
71         buffer.flip();
72
73         OFPInstructionGoToTable instructionTemp = new OFPInstructionGoToTable();
74         instructionTemp.readFrom(buffer);
75
76         TestCase.assertTrue(instruction.equals(instructionTemp));
77         TestCase.assertEquals(instruction.hashCode(), instructionTemp.hashCode());
78     }
79
80 }