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
8 package org.opendaylight.openflowjava.protocol.api.extensibility;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
17 * Unit tests for EnhancedMessageCodeKey.
19 * @author michal.polkorab
21 public class EnhancedMessageCodeKeyTest {
23 * Test EnhancedMessageCodeKey equals and hashCode.
27 EnhancedMessageCodeKey key1 =
28 new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 4, 8, BarrierInput.class);
29 EnhancedMessageCodeKey key2 =
30 new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 4, 8, BarrierInput.class);
31 Assert.assertTrue("Wrong equals", key1.equals(key2));
32 Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
33 key2 = new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_3, 4, 8, BarrierInput.class);
34 Assert.assertFalse("Wrong equals", key1.equals(key2));
35 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
36 key2 = new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 4, 8, null);
37 Assert.assertFalse("Wrong equals", key1.equals(key2));
38 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
39 key2 = new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 4, 8, BarrierOutput.class);
40 Assert.assertFalse("Wrong equals", key1.equals(key2));
41 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
42 key2 = new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 6, 8, BarrierInput.class);
43 Assert.assertFalse("Wrong equals", key1.equals(key2));
44 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
45 key2 = new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 4, 16, BarrierInput.class);
46 Assert.assertFalse("Wrong equals", key1.equals(key2));
47 Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
51 * Test EnhancedMessageTypeKey equals - additional test.
54 public void testEquals() {
55 EnhancedMessageCodeKey key1 =
56 new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 4, 8, BarrierInput.class);
58 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
59 Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
63 * Test EnhancedMessageCodeKey toString().
66 public void testToString() {
67 EnhancedMessageCodeKey key1 =
68 new EnhancedMessageCodeKey(EncodeConstants.OF_VERSION_1_0, 4, 8, BarrierInput.class);
70 Assert.assertEquals("Wrong toString()",
71 "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn.opendaylight"
72 + ".openflow.protocol.rev130731.BarrierInput msgType: 4 msgType2: 8", key1.toString());