1 package org.opendaylight.openflowjava.protocol.api.keys;
3 import org.junit.Assert;
5 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
6 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice.ExperimenterIdCase;
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
13 * @author michal.polkorab
15 public class KeysTest {
18 * Testing equals() and hashcode() methods of extension deserializer's keys
21 public void testEqualsAndHashcodeOfDeserializerKeys() {
22 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID,
23 EncodeConstants.EXPERIMENTER_VALUE, 1L);
24 ExperimenterActionDeserializerKey experimenterActionDeserializerKey = new ExperimenterActionDeserializerKey(
25 EncodeConstants.OF13_VERSION_ID, 1L);
26 Assert.assertEquals(actionDeserializerKey, experimenterActionDeserializerKey);
27 Assert.assertEquals(actionDeserializerKey.hashCode(), experimenterActionDeserializerKey.hashCode());
29 InstructionDeserializerKey instructionDeserializerKey = new InstructionDeserializerKey(
30 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, 1L);
31 ExperimenterInstructionDeserializerKey experimenterInstructionDeserializerKey = new ExperimenterInstructionDeserializerKey(
32 EncodeConstants.OF13_VERSION_ID, 1L);
33 Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
34 Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
36 MatchEntryDeserializerKey matchKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
37 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
38 MatchEntryDeserializerKey matchKey2 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
39 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
40 Assert.assertEquals(matchKey, matchKey2);
41 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
45 * Testing equals() and hashcode() methods of extension serializer's keys
48 public void testEqualsAndHashcodeOfActionDeserializerKeys() {
49 ActionSerializerKey<ExperimenterIdCase> actionSerializerKey = new ActionSerializerKey<>(
50 EncodeConstants.OF13_VERSION_ID, ExperimenterIdCase.class, 1L);
51 ExperimenterActionSerializerKey experimenterActionSerializerKey = new ExperimenterActionSerializerKey(
52 EncodeConstants.OF13_VERSION_ID, 1L, ExpSubType.class);
53 Assert.assertFalse(actionSerializerKey.equals(experimenterActionSerializerKey));
54 Assert.assertFalse(experimenterActionSerializerKey.equals(actionSerializerKey));
56 InstructionSerializerKey<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter> instructionSerializerKey = new InstructionSerializerKey<>(
57 EncodeConstants.OF13_VERSION_ID,
58 org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Experimenter.class,
60 ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
61 Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
62 Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
64 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
65 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
66 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
67 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
68 Assert.assertEquals(matchKey, matchKey2);
69 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
72 private static class ExpSubType extends ExperimenterActionSubType {
73 // empty class - only used in test for comparation