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