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
9 package org.opendaylight.openflowjava.protocol.api.keys;
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase;
18 * Unit tests for InstructionSerializerKey.
20 * @author michal.polkorab
22 public class InstructionSerializerKeyTest {
25 * Test InstructionSerializerKey equals and hashCode.
29 InstructionSerializerKey<?> key1 =
30 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
31 InstructionSerializerKey<?> key2 =
32 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
33 Assert.assertTrue("Wrong equals", key1.equals(key2));
34 Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());
35 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, null);
36 Assert.assertFalse("Wrong equals", key1.equals(key2));
37 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
38 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
39 Assert.assertFalse("Wrong equals", key1.equals(key2));
40 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
41 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, WriteActionsCase.class, 42L);
42 Assert.assertFalse("Wrong equals", key1.equals(key2));
43 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
44 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 55L);
45 Assert.assertFalse("Wrong equals", key1.equals(key2));
46 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
47 key2 = new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, ApplyActionsCase.class, 42L);
48 Assert.assertFalse("Wrong equals", key1.equals(key2));
49 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
53 * Test InstructionSerializerKey equals - additional test.
56 public void testEquals() {
57 InstructionSerializerKey<?> key1 =
58 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
60 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
61 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
63 InstructionSerializerKey<?> key2 =
64 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
65 key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, null);
66 Assert.assertFalse("Wrong equal by experimenterId.", key1.equals(key2));
68 key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
69 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
70 Assert.assertTrue("Wrong equal by instructionType.", key1.equals(key2));
74 * Test InstructionSerializerKey toString().
77 public void testToString() {
78 InstructionSerializerKey<?> key1 =
79 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
81 Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn"
82 + ".opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction "
83 + "instructionType type: org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction"
84 + ".rev130731.instruction.grouping.instruction.choice.ApplyActionsCase vendorID: 42", key1.toString());