Merge "Added JSON and XML payloads tabs with RFC 8040 URL"
[openflowplugin.git] / openflowjava / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / KeysTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.openflowjava.protocol.api.keys;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.openflowjava.protocol.api.util.OxmMatchConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225.action.container.action.choice.ExperimenterIdCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.InPort;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev150225.OpenflowBasicClass;
18 import org.opendaylight.yangtools.yang.common.Uint32;
19
20 /**
21  * Unit tests for keys.
22  *
23  * @author michal.polkorab
24  */
25 public class KeysTest {
26
27     /**
28      * Testing equals() and hashcode() methods of extension deserializer's keys.
29      */
30     @Test
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());
38
39         InstructionDeserializerKey instructionDeserializerKey = new InstructionDeserializerKey(
40                 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, 1L);
41         ExperimenterInstructionDeserializerKey experimenterInstructionDeserializerKey =
42                 new ExperimenterInstructionDeserializerKey(
43                 EncodeConstants.OF13_VERSION_ID, 1L);
44         Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
45         Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
46
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());
53     }
54
55     /**
56      * Testing equals() and hashcode() methods of extension serializer's keys.
57      */
58     @Test
59     public void testEqualsAndHashcodeOfActionDeserializerKeys() {
60         ActionSerializerKey<ExperimenterIdCase> actionSerializerKey = new ActionSerializerKey<>(
61                 EncodeConstants.OF13_VERSION_ID, ExperimenterIdCase.class, Uint32.ONE);
62         ExperimenterActionSerializerKey experimenterActionSerializerKey = new ExperimenterActionSerializerKey(
63                 EncodeConstants.OF13_VERSION_ID,  Uint32.ONE, ExpSubType.class);
64         Assert.assertFalse(actionSerializerKey.equals(experimenterActionSerializerKey));
65         Assert.assertFalse(experimenterActionSerializerKey.equals(actionSerializerKey));
66
67         InstructionSerializerKey<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225
68             .instruction.container.instruction.choice.ExperimenterIdCase> instructionSerializerKey =
69                 new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, org.opendaylight.yang.gen.v1.urn
70                         .opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice
71                         .ExperimenterIdCase.class, 1L);
72         ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey =
73                 new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
74         Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
75         Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
76
77         MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
78                 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
79         MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
80                 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
81         Assert.assertEquals(matchKey, matchKey2);
82         Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
83     }
84
85     private interface ExpSubType extends ExperimenterActionSubType {
86         // empty class - only used in test for comparation
87     }
88
89 }