2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.api.keys;
\r
11 import org.junit.Assert;
\r
12 import org.junit.Test;
\r
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;
\r
18 * @author michal.polkorab
\r
21 public class InstructionSerializerKeyTest {
\r
24 * Test InstructionSerializerKey equals and hashCode
\r
27 public void test() {
\r
28 InstructionSerializerKey<?> key1 =
\r
29 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);
\r
30 InstructionSerializerKey<?> key2 =
\r
31 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);
\r
32 Assert.assertTrue("Wrong equals", key1.equals(key2));
\r
33 Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
34 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, null);
\r
35 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
36 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
37 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
\r
38 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
39 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
40 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, WriteActions.class, 42L);
\r
41 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
42 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
43 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 55L);
\r
44 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
45 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
46 key2 = new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, ApplyActions.class, 42L);
\r
47 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
48 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
\r
52 * Test InstructionSerializerKey equals - additional test
\r
55 public void testEquals(){
\r
56 InstructionSerializerKey<?> key1 =
\r
57 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);
\r
58 InstructionSerializerKey<?> key2 =
\r
59 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);
\r
61 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
\r
62 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
\r
64 key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, null);
\r
65 Assert.assertFalse("Wrong equal by experimenterId.", key1.equals(key2));
\r
67 key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
\r
68 key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
\r
69 Assert.assertTrue("Wrong equal by instructionType.", key1.equals(key2));
\r
73 * Test InstructionSerializerKey toString()
\r
76 public void testToString(){
\r
77 InstructionSerializerKey<?> key1 =
\r
78 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);
\r
80 Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"
\r
81 + ".openflow.common.instruction.rev130731.instructions.grouping.Instruction"
\r
82 + " instructionType type: org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"
\r
83 + ".instruction.rev130731.ApplyActions vendorID: 42", key1.toString());
\r