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.keys.MessageTypeKey;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
19 * @author michal.polkorab
22 public class MessageTypeKeyTest {
25 * Test MessageTypeKey equals and hashCode
29 MessageTypeKey<?> key1 =
30 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
31 MessageTypeKey<?> key2 =
32 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
33 Assert.assertTrue("Wrong equals", key1.equals(key2));
34 Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
35 key2 = new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, BarrierInput.class);
36 Assert.assertFalse("Wrong equals", key1.equals(key2));
37 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
38 key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);
39 Assert.assertFalse("Wrong equals", key1.equals(key2));
40 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
41 key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierOutput.class);
42 Assert.assertFalse("Wrong equals", key1.equals(key2));
43 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
47 * Test MessageTypeKey equals - additional test
50 public void testEquals() {
51 MessageTypeKey<?> key1;
52 MessageTypeKey<?> key2;
53 key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
55 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
56 Assert.assertFalse("Wrong equal to null.", key1.equals(null));
57 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
59 key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);
60 key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
61 Assert.assertFalse("Wrong equal by msgType.", key1.equals(key2));
63 key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);
64 Assert.assertTrue("Wrong equal by msgType.", key1.equals(key2));
68 * Test MessageTypeKey toString()
71 public void testToString() {
72 MessageTypeKey<?> key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
74 Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn"
75 + ".opendaylight.openflow.protocol.rev130731.BarrierInput", key1.toString());