Bug 2245 Fixed Avoid cycle between java packages
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / extensibility / MessageCodeKeyTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowjava.protocol.api.extensibility;
10
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;
17
18 /**
19  * @author michal.polkorab
20  *
21  */
22 public class MessageCodeKeyTest {
23
24     /**
25      * Test MessageCodeKey equals and hashCode
26      */
27     @Test
28     public void test() {
29         MessageCodeKey key1 =
30                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
31         MessageCodeKey key2 =
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());
47     }
48
49     /**
50      * Test MessageCodeKey equals - additional test
51      */
52     @Test
53     public void testEquals() {
54         MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
55
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()));
59
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));
63
64         key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);
65         Assert.assertTrue("Wrong equal by clazz.", key1.equals(key2));
66     }
67
68     /**
69      * Test MessageCodeKey toString()
70      */
71     @Test
72     public void testToString() {
73         MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);
74
75         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"
76                 + ".opendaylight.openflow.protocol.rev130731.BarrierInput msgType: 4", key1.toString());
77     }
78 }