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.MessageCodeKey;
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 MessageCodeKeyTest {
25 * Test MessageCodeKey equals and hashCode
30 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
32 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
33 Assert.assertTrue("Wrong equals", key1.equals(key2));
34 Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
35 key2 = new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 4, BarrierInput.class);
36 Assert.assertFalse("Wrong equals", key1.equals(key2));
37 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
38 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
39 Assert.assertFalse("Wrong equals", key1.equals(key2));
40 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
41 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierOutput.class);
42 Assert.assertFalse("Wrong equals", key1.equals(key2));
43 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
44 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, BarrierInput.class);
45 Assert.assertFalse("Wrong equals", key1.equals(key2));
46 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
50 * Test MessageCodeKey equals - additional test
53 public void testEquals() {
54 MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
56 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
57 Assert.assertFalse("Wrong equal to null.", key1.equals(null));
58 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
60 key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
61 MessageCodeKey key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
62 Assert.assertFalse("Wrong equal by clazz.", key1.equals(key2));
64 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
65 Assert.assertTrue("Wrong equal by clazz.", key1.equals(key2));
69 * Test MessageCodeKey toString()
72 public void testToString() {
73 MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
75 Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"
76 + ".opendaylight.openflow.protocol.rev130731.BarrierInput msgType: 4", key1.toString());