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