Add INFO.yaml for openflowplugin
[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
19 /**
20  * Unit tests for keys.
21  *
22  * @author michal.polkorab
23  */
24 public class KeysTest {
25
26     /**
27      * Testing equals() and hashcode() methods of extension deserializer's keys.
28      */
29     @Test
30     public void testEqualsAndHashcodeOfDeserializerKeys() {
31         ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID,
32                 EncodeConstants.EXPERIMENTER_VALUE, 1L);
33         ExperimenterActionDeserializerKey experimenterActionDeserializerKey = new ExperimenterActionDeserializerKey(
34                 EncodeConstants.OF13_VERSION_ID, 1L);
35         Assert.assertEquals(actionDeserializerKey, experimenterActionDeserializerKey);
36         Assert.assertEquals(actionDeserializerKey.hashCode(), experimenterActionDeserializerKey.hashCode());
37
38         InstructionDeserializerKey instructionDeserializerKey = new InstructionDeserializerKey(
39                 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, 1L);
40         ExperimenterInstructionDeserializerKey experimenterInstructionDeserializerKey =
41                 new ExperimenterInstructionDeserializerKey(
42                 EncodeConstants.OF13_VERSION_ID, 1L);
43         Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
44         Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
45
46         MatchEntryDeserializerKey matchKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
47                 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
48         MatchEntryDeserializerKey matchKey2 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
49                 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
50         Assert.assertEquals(matchKey, matchKey2);
51         Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
52     }
53
54     /**
55      * Testing equals() and hashcode() methods of extension serializer's keys.
56      */
57     @Test
58     public void testEqualsAndHashcodeOfActionDeserializerKeys() {
59         ActionSerializerKey<ExperimenterIdCase> actionSerializerKey = new ActionSerializerKey<>(
60                 EncodeConstants.OF13_VERSION_ID, ExperimenterIdCase.class, 1L);
61         ExperimenterActionSerializerKey experimenterActionSerializerKey = new ExperimenterActionSerializerKey(
62                 EncodeConstants.OF13_VERSION_ID, 1L, ExpSubType.class);
63         Assert.assertFalse(actionSerializerKey.equals(experimenterActionSerializerKey));
64         Assert.assertFalse(experimenterActionSerializerKey.equals(actionSerializerKey));
65
66         InstructionSerializerKey<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225
67             .instruction.container.instruction.choice.ExperimenterIdCase> instructionSerializerKey =
68                 new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, org.opendaylight.yang.gen.v1.urn
69                         .opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice
70                         .ExperimenterIdCase.class, 1L);
71         ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey =
72                 new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
73         Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
74         Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
75
76         MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
77                 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
78         MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
79                 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
80         Assert.assertEquals(matchKey, matchKey2);
81         Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
82     }
83
84     private interface ExpSubType extends ExperimenterActionSubType {
85         // empty class - only used in test for comparation
86     }
87
88 }