e6be8a8d19528d88c953b12838bb7a4d874a2a70
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / extensibility / EnhancedMessageTypeKeyTest.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.common.action.rev130731.Output;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.SetField;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
18 \r
19 /**\r
20  * @author michal.polkorab\r
21  *\r
22  */\r
23 public class EnhancedMessageTypeKeyTest {\r
24 \r
25     /**\r
26      * Test EnhancedMessageTypeKey equals and hashCode\r
27      */\r
28     @Test\r
29     public void test() {\r
30         EnhancedMessageTypeKey<?,?> key1 =\r
31                 new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
32         EnhancedMessageTypeKey<?,?> key2 =\r
33                 new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
34         Assert.assertTrue("Wrong equals", key1.equals(key2));\r
35         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
36         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class, Output.class);\r
37         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
38         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
39         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null, Output.class);\r
40         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
41         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
42         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Instruction.class, Output.class);\r
43         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
44         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
45         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class, null);\r
46         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
47         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
48         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, Action.class, SetField.class);\r
49         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
50         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
51     }\r
52     \r
53     /**\r
54      * Test EnhancedMessageTypeKey equals - additional test\r
55      */\r
56     @Test\r
57     public void testEquals() {\r
58         EnhancedMessageTypeKey<?,?> key1;\r
59         EnhancedMessageTypeKey<?,?> key2;\r
60         key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
61         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
62         \r
63         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
64         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
65         \r
66         key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, null);\r
67         Assert.assertFalse("Wrong equal by msgType2.", key1.equals(key2));\r
68         key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, Output.class);\r
69         key2 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, Action.class, SetField.class);\r
70         Assert.assertFalse("Wrong equal by msgType2 class name.", key1.equals(key2));\r
71     }\r
72 \r
73     /**\r
74      * Test EnhancedMessageTypeKey toString()\r
75      */\r
76     @Test\r
77     public void testToString() {\r
78         EnhancedMessageTypeKey<?,?> key1 = new EnhancedMessageTypeKey<>(EncodeConstants.OF10_VERSION_ID,\r
79                 Action.class, Output.class);\r
80 \r
81          Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
82                  + ".openflow.common.action.rev130731.actions.grouping.Action msgType2: org.opendaylight.yang.gen.v1.urn"\r
83                  + ".opendaylight.openflow.common.action.rev130731.Output", key1.toString());\r
84     }\r
85 }