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.extensibility;
\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.action.rev130731.Output;
\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField;
\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
\r
20 * @author michal.polkorab
\r
23 public class EnhancedMessageTypeKeyTest {
\r
26 * Test EnhancedMessageTypeKey equals and hashCode
\r
29 public void test() {
\r
30 EnhancedMessageTypeKey<?,?> key1 =
\r
31 new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);
\r
32 EnhancedMessageTypeKey<?,?> key2 =
\r
33 new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);
\r
34 Assert.assertTrue("Wrong equals", key1.equals(key2));
\r
35 Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
\r
36 key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class, Output.class);
\r
37 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
38 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
\r
39 key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null, Output.class);
\r
40 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
41 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
\r
42 key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Instruction.class, Output.class);
\r
43 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
44 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
\r
45 key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class, null);
\r
46 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
47 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
\r
48 key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class, SetField.class);
\r
49 Assert.assertFalse("Wrong equals", key1.equals(key2));
\r
50 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
\r
54 * Test EnhancedMessageTypeKey equals - additional test
\r
57 public void testEquals() {
\r
58 EnhancedMessageTypeKey<?,?> key1;
\r
59 EnhancedMessageTypeKey<?,?> key2;
\r
61 key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);
\r
62 key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);
\r
64 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
\r
66 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
\r
68 key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, null);
\r
69 Assert.assertFalse("Wrong equal by msgType2.", key1.equals(key2));
\r
70 key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);
\r
71 key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, SetField.class);
\r
72 Assert.assertFalse("Wrong equal by msgType2 class name.", key1.equals(key2));
\r