759cb0e7cea57d4bc93f983ada33ebce40864a8d
[openflowjava.git] / third-party / openflow-codec / src / test / java / org / openflow / codec / protocol / instruction / OFPInstructionExperimenterTest.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.OFPInstructionExperimenter;
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 OFPInstructionExperimenterTest 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 testOFInstructionExperimenterCreation() {
25         OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
26         assertTrue(instruction.type.equals(OFPInstructionType.EXPERIMENTER));
27
28     }
29
30     public void testClone() throws CloneNotSupportedException {
31         OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
32         instruction.setExperimenterId((byte) 2);
33         OFPInstructionExperimenter instructionCloned = (OFPInstructionExperimenter) instruction.clone();
34         TestCase.assertEquals(instruction, instructionCloned);
35
36         instruction.setExperimenterId((byte) 1);
37         TestCase.assertNotSame(instruction, instructionCloned);
38
39         instruction = (OFPInstructionExperimenter) instructionCloned.clone();
40         TestCase.assertEquals(instruction, instructionCloned);
41     }
42
43     public void testReadWriteSuccess() {
44         OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
45         instruction.setExperimenterId((byte) 2);
46         instruction.writeTo(buffer);
47         buffer.flip();
48
49         OFPInstructionExperimenter instructionTemp = new OFPInstructionExperimenter();
50         instructionTemp.readFrom(buffer);
51         TestCase.assertEquals(instruction, instructionTemp);
52
53     }
54
55     public void testToString() {
56         OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
57         instruction.setExperimenterId((byte) 2);
58         instruction.writeTo(buffer);
59         buffer.flip();
60
61         OFPInstructionExperimenter instructionTemp = new OFPInstructionExperimenter();
62         instructionTemp.readFrom(buffer);
63         TestCase.assertEquals(instruction.toString(), instructionTemp.toString());
64     }
65
66     public void testEqualHashcode() {
67
68         OFPInstructionExperimenter instruction = new OFPInstructionExperimenter();
69         instruction.setExperimenterId((byte) 2);
70         instruction.writeTo(buffer);
71         buffer.flip();
72
73         OFPInstructionExperimenter instructionTemp = new OFPInstructionExperimenter();
74         instructionTemp.readFrom(buffer);
75
76         TestCase.assertTrue(instruction.equals(instructionTemp));
77         TestCase.assertEquals(instruction.hashCode(), instructionTemp.hashCode());
78     }
79
80 }