66a09fe9bef05361047549d17825f76c6bc285b9
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / ActionDeserializerKeyTest.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.keys;\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 \r
15 /**\r
16  * @author michal.polkorab\r
17  *\r
18  */\r
19 public class ActionDeserializerKeyTest {\r
20 \r
21     /**\r
22      * Test ActionDeserializerKey equals and hashCode\r
23      */\r
24     @Test\r
25     public void test() {\r
26         ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 42L);\r
27         ActionDeserializerKey key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 42L);\r
28         Assert.assertTrue("Wrong equals", key1.equals(key2));\r
29         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
30         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
31         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
32         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
33         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 55L);\r
34         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
35         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
36         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0, 42L);\r
37         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
38         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
39         key2 = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 11, 42L);\r
40         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
41         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
42     }\r
43     \r
44     /**\r
45      * Test ActionDeserializerKey equals - additional test\r
46      */\r
47     @Test\r
48     public void testEquals(){\r
49         ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
50         ActionDeserializerKey key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 42L);\r
51 \r
52         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
53         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
54         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
55         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
56         Assert.assertTrue("Wrong equal by experimenterId", key1.equals(key2));\r
57     }\r
58 \r
59     /**\r
60      * Test InstructionDeserializerKey toString()\r
61      */\r
62     @Test\r
63     public void testToString(){\r
64         ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);\r
65 \r
66         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"\r
67                 + ".opendaylight.openflow.common.action.rev130731.actions.grouping.Action msgType: 11"\r
68                 + " experimenterID: null", key1.toString());\r
69     }\r
70 }