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