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.protocol.rev130731.BarrierInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
18 * @author michal.polkorab
21 public class MessageCodeKeyTest {
24 * Test MessageCodeKey equals and hashCode
29 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
31 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
32 Assert.assertTrue("Wrong equals", key1.equals(key2));
33 Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
34 key2 = new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 4, BarrierInput.class);
35 Assert.assertFalse("Wrong equals", key1.equals(key2));
36 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
37 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
38 Assert.assertFalse("Wrong equals", key1.equals(key2));
39 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
40 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierOutput.class);
41 Assert.assertFalse("Wrong equals", key1.equals(key2));
42 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
43 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, BarrierInput.class);
44 Assert.assertFalse("Wrong equals", key1.equals(key2));
45 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
49 * Test MessageCodeKey equals - additional test
52 public void testEquals() {
53 MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, 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 MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
60 MessageCodeKey key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
61 Assert.assertFalse("Wrong equal by clazz.", key1.equals(key2));
63 key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
64 Assert.assertTrue("Wrong equal by clazz.", key1.equals(key2));
68 * Test MessageCodeKey toString()
71 public void testToString() {
72 MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
74 Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"
75 + ".opendaylight.openflow.protocol.rev130731.BarrierInput msgType: 4", key1.toString());