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 * Unit tests for keys.
22 * @author michal.polkorab
24 public class KeysTest {
27 * Testing equals() and hashcode() methods of extension deserializer's keys.
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());
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());
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());
55 * Testing equals() and hashcode() methods of extension serializer's keys.
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));
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());
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());
84 private interface ExpSubType extends ExperimenterActionSubType {
85 // empty class - only used in test for comparation