769bfc921e9ff20673d5b5bcb5cac3d0b4b3150e
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / KeysTest.java
1 package org.opendaylight.openflowjava.protocol.api.keys;
2
3 import org.junit.Assert;
4 import org.junit.Test;
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;
17
18 /**
19  * @author michal.polkorab
20  */
21 public class KeysTest {
22
23     /**
24      * Testing equals() and hashcode() methods of extension deserializer's keys
25      */
26     @Test
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());
34
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());
41
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());
48     }
49
50     /**
51      * Testing equals() and hashcode() methods of extension serializer's keys
52      */
53     @Test
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));
61
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,
65                 1L);
66         ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
67         Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
68         Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
69
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());
76     }
77
78     private static class ExpSubType extends ExperimenterActionSubType {
79         // empty class - only used in test for comparation
80     }
81
82 }