09ecbda47ec49f73fd54040a58483fe9b9e8d53f
[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.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;
11
12 /**
13  * @author michal.polkorab
14  */
15 public class KeysTest {
16
17     /**
18      * Testing equals() and hashcode() methods of extension deserializer's keys
19      */
20     @Test
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());
28
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());
35
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());
42     }
43
44     /**
45      * Testing equals() and hashcode() methods of extension serializer's keys
46      */
47     @Test
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));
55
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,
59                 1L);
60         ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
61         Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
62         Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
63
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());
70     }
71
72     private static class ExpSubType extends ExperimenterActionSubType {
73         // empty class - only used in test for comparation
74     }
75
76 }