1 package org.opendaylight.openflowjava.protocol.api.keys;
3 import org.junit.Assert;
5 import org.opendaylight.openflowjava.protocol.api.keys.ActionDeserializerKey;
6 import org.opendaylight.openflowjava.protocol.api.keys.ActionSerializerKey;
7 import org.opendaylight.openflowjava.protocol.api.keys.InstructionDeserializerKey;
8 import org.opendaylight.openflowjava.protocol.api.keys.InstructionSerializerKey;
9 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntryDeserializerKey;
10 import org.opendaylight.openflowjava.protocol.api.keys.MatchEntrySerializerKey;
11 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
12 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.ExperimenterActionSubType;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
19 * @author michal.polkorab
21 public class KeysTest {
24 * Testing equals() and hashcode() methods of extension deserializer's keys
27 public void testEqualsAndHashcodeOfDeserializerKeys() {
28 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID,
29 EncodeConstants.EXPERIMENTER_VALUE, 1L);
30 ExperimenterActionDeserializerKey experimenterActionDeserializerKey = new ExperimenterActionDeserializerKey(
31 EncodeConstants.OF13_VERSION_ID, 1L);
32 Assert.assertEquals(actionDeserializerKey, experimenterActionDeserializerKey);
33 Assert.assertEquals(actionDeserializerKey.hashCode(), experimenterActionDeserializerKey.hashCode());
35 InstructionDeserializerKey instructionDeserializerKey = new InstructionDeserializerKey(
36 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, 1L);
37 ExperimenterInstructionDeserializerKey experimenterInstructionDeserializerKey = new ExperimenterInstructionDeserializerKey(
38 EncodeConstants.OF13_VERSION_ID, 1L);
39 Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
40 Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
42 MatchEntryDeserializerKey matchKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
43 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
44 MatchEntryDeserializerKey matchKey2 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
45 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
46 Assert.assertEquals(matchKey, matchKey2);
47 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
51 * Testing equals() and hashcode() methods of extension serializer's keys
54 public void testEqualsAndHashcodeOfActionDeserializerKeys() {
55 ActionSerializerKey<Experimenter> actionSerializerKey = new ActionSerializerKey<>(
56 EncodeConstants.OF13_VERSION_ID, Experimenter.class, 1L);
57 ExperimenterActionSerializerKey experimenterActionSerializerKey = new ExperimenterActionSerializerKey(
58 EncodeConstants.OF13_VERSION_ID, 1L, ExpSubType.class);
59 Assert.assertFalse(actionSerializerKey.equals(experimenterActionSerializerKey));
60 Assert.assertFalse(experimenterActionSerializerKey.equals(actionSerializerKey));
62 InstructionSerializerKey<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter> instructionSerializerKey = new InstructionSerializerKey<>(
63 EncodeConstants.OF13_VERSION_ID,
64 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter.class,
66 ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
67 Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
68 Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
70 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
71 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
72 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
73 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
74 Assert.assertEquals(matchKey, matchKey2);
75 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
78 private static class ExpSubType extends ExperimenterActionSubType {
79 // empty class - only used in test for comparation