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.keys.experimenter.ExperimenterActionDeserializerKey;
12 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterActionSerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterInstructionDeserializerKey;
14 import org.opendaylight.openflowjava.protocol.api.keys.experimenter.ExperimenterInstructionSerializerKey;
15 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
16 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.ExperimenterActionSubType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;
23 * @author michal.polkorab
25 public class KeysTest {
28 * Testing equals() and hashcode() methods of extension deserializer's keys
31 public void testEqualsAndHashcodeOfDeserializerKeys() {
32 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID,
33 EncodeConstants.EXPERIMENTER_VALUE, 1L);
34 ExperimenterActionDeserializerKey experimenterActionDeserializerKey = new ExperimenterActionDeserializerKey(
35 EncodeConstants.OF13_VERSION_ID, 1L);
36 Assert.assertEquals(actionDeserializerKey, experimenterActionDeserializerKey);
37 Assert.assertEquals(actionDeserializerKey.hashCode(), experimenterActionDeserializerKey.hashCode());
39 InstructionDeserializerKey instructionDeserializerKey = new InstructionDeserializerKey(
40 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, 1L);
41 ExperimenterInstructionDeserializerKey experimenterInstructionDeserializerKey = new ExperimenterInstructionDeserializerKey(
42 EncodeConstants.OF13_VERSION_ID, 1L);
43 Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
44 Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
46 MatchEntryDeserializerKey matchKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
47 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
48 MatchEntryDeserializerKey matchKey2 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
49 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
50 Assert.assertEquals(matchKey, matchKey2);
51 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
55 * Testing equals() and hashcode() methods of extension serializer's keys
58 public void testEqualsAndHashcodeOfActionDeserializerKeys() {
59 ActionSerializerKey<Experimenter> actionSerializerKey = new ActionSerializerKey<>(
60 EncodeConstants.OF13_VERSION_ID, Experimenter.class, 1L);
61 ExperimenterActionSerializerKey experimenterActionSerializerKey = new ExperimenterActionSerializerKey(
62 EncodeConstants.OF13_VERSION_ID, 1L, ExpSubType.class);
63 Assert.assertFalse(actionSerializerKey.equals(experimenterActionSerializerKey));
64 Assert.assertFalse(experimenterActionSerializerKey.equals(actionSerializerKey));
66 InstructionSerializerKey<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter> instructionSerializerKey = new InstructionSerializerKey<>(
67 EncodeConstants.OF13_VERSION_ID,
68 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter.class,
70 ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
71 Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
72 Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
74 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
75 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
76 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
77 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
78 Assert.assertEquals(matchKey, matchKey2);
79 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
82 private static class ExpSubType extends ExperimenterActionSubType {
83 // empty class - only used in test for comparation