4087a55bd744af0c9c0725923d5bd5e65fcdcf77
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / extensibility / MessageCodeKeyTest.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\r
4  * This program and the accompanying materials are made available under the\r
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
6  * and is available at http://www.eclipse.org/legal/epl-v10.html\r
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.api.extensibility;\r
10 \r
11 import org.junit.Assert;\r
12 import org.junit.Test;\r
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;\r
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;\r
16 \r
17 /**\r
18  * @author michal.polkorab\r
19  *\r
20  */\r
21 public class MessageCodeKeyTest {\r
22 \r
23     /**\r
24      * Test MessageCodeKey equals and hashCode\r
25      */\r
26     @Test\r
27     public void test() {\r
28         MessageCodeKey key1 =\r
29                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
30         MessageCodeKey key2 =\r
31                 new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
32         Assert.assertTrue("Wrong equals", key1.equals(key2));\r
33         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
34         key2 = new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 4, BarrierInput.class);\r
35         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
36         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
37         key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);\r
38         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
39         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
40         key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierOutput.class);\r
41         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
42         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
43         key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 6, BarrierInput.class);\r
44         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
45         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
46     }\r
47 \r
48     /**\r
49      * Test MessageCodeKey equals - additional test\r
50      */\r
51     @Test\r
52     public void testEquals() {\r
53         MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
54 \r
55         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
56         Assert.assertFalse("Wrong equal to null.", key1.equals(null));\r
57         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
58 \r
59         key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);\r
60         MessageCodeKey key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
61         Assert.assertFalse("Wrong equal by clazz.", key1.equals(key2));\r
62 \r
63         key2 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, null);\r
64         Assert.assertTrue("Wrong equal by clazz.", key1.equals(key2));\r
65     }\r
66 \r
67     /**\r
68      * Test MessageCodeKey toString()\r
69      */\r
70     @Test\r
71     public void testToString() {\r
72         MessageCodeKey key1 = new MessageCodeKey(EncodeConstants.OF10_VERSION_ID, 4, BarrierInput.class);\r
73 \r
74         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"\r
75                 + ".opendaylight.openflow.protocol.rev130731.BarrierInput msgType: 4", key1.toString());\r
76     }\r
77 }