2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.openflowjava.protocol.api.keys;
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;
20 * @author michal.polkorab
22 public class KeysTest {
25 * Testing equals() and hashcode() methods of extension deserializer's keys
28 public void testEqualsAndHashcodeOfDeserializerKeys() {
29 ActionDeserializerKey actionDeserializerKey = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID,
30 EncodeConstants.EXPERIMENTER_VALUE, 1L);
31 ExperimenterActionDeserializerKey experimenterActionDeserializerKey = new ExperimenterActionDeserializerKey(
32 EncodeConstants.OF13_VERSION_ID, 1L);
33 Assert.assertEquals(actionDeserializerKey, experimenterActionDeserializerKey);
34 Assert.assertEquals(actionDeserializerKey.hashCode(), experimenterActionDeserializerKey.hashCode());
36 InstructionDeserializerKey instructionDeserializerKey = new InstructionDeserializerKey(
37 EncodeConstants.OF13_VERSION_ID, EncodeConstants.EXPERIMENTER_VALUE, 1L);
38 ExperimenterInstructionDeserializerKey experimenterInstructionDeserializerKey = new ExperimenterInstructionDeserializerKey(
39 EncodeConstants.OF13_VERSION_ID, 1L);
40 Assert.assertEquals(instructionDeserializerKey, experimenterInstructionDeserializerKey);
41 Assert.assertEquals(instructionDeserializerKey.hashCode(), experimenterInstructionDeserializerKey.hashCode());
43 MatchEntryDeserializerKey matchKey = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
44 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
45 MatchEntryDeserializerKey matchKey2 = new MatchEntryDeserializerKey(EncodeConstants.OF13_VERSION_ID,
46 OxmMatchConstants.OPENFLOW_BASIC_CLASS, OxmMatchConstants.ARP_OP);
47 Assert.assertEquals(matchKey, matchKey2);
48 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
52 * Testing equals() and hashcode() methods of extension serializer's keys
55 public void testEqualsAndHashcodeOfActionDeserializerKeys() {
56 ActionSerializerKey<ExperimenterIdCase> actionSerializerKey = new ActionSerializerKey<>(
57 EncodeConstants.OF13_VERSION_ID, ExperimenterIdCase.class, 1L);
58 ExperimenterActionSerializerKey experimenterActionSerializerKey = new ExperimenterActionSerializerKey(
59 EncodeConstants.OF13_VERSION_ID, 1L, ExpSubType.class);
60 Assert.assertFalse(actionSerializerKey.equals(experimenterActionSerializerKey));
61 Assert.assertFalse(experimenterActionSerializerKey.equals(actionSerializerKey));
63 InstructionSerializerKey<org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev150225
64 .instruction.container.instruction.choice.ExperimenterIdCase> instructionSerializerKey =
65 new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, org.opendaylight.yang.gen.v1.urn
66 .opendaylight.openflow.augments.rev150225.instruction.container.instruction.choice
67 .ExperimenterIdCase.class, 1L);
68 ExperimenterInstructionSerializerKey experimenterInstructionSerializerKey = new ExperimenterInstructionSerializerKey(EncodeConstants.OF13_VERSION_ID, 1L);
69 Assert.assertEquals(instructionSerializerKey, experimenterInstructionSerializerKey);
70 Assert.assertEquals(instructionSerializerKey.hashCode(), experimenterInstructionSerializerKey.hashCode());
72 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey = new MatchEntrySerializerKey<>(
73 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
74 MatchEntrySerializerKey<OpenflowBasicClass, InPort> matchKey2 = new MatchEntrySerializerKey<>(
75 EncodeConstants.OF10_VERSION_ID, OpenflowBasicClass.class, InPort.class);
76 Assert.assertEquals(matchKey, matchKey2);
77 Assert.assertEquals(matchKey.hashCode(), matchKey2.hashCode());
80 private static class ExpSubType extends ExperimenterActionSubType {
81 // empty class - only used in test for comparation