761698d3bee913ef350cc2319603c1e64749385d
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / experimenter / ExperimenterActionSerializerKeyTest.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.experimenter;\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.ExperimenterActionSubType;\r
15 \r
16 /**\r
17  * @author michal.polkorab\r
18  *\r
19  */\r
20 public class ExperimenterActionSerializerKeyTest {\r
21 \r
22 \r
23     /**\r
24      * Test ExperimenterActionSerializerKey equals and hashCode\r
25      */\r
26     @Test\r
27     public void test() {\r
28         ExperimenterActionSerializerKey key1 =\r
29                 new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);\r
30         ExperimenterActionSerializerKey key2 =\r
31                 new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);\r
32         Assert.assertTrue("Wrong equals", key1.equals(key2));\r
33         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
34         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF13_VERSION_ID, 42L, TestSubType.class);\r
35         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
36         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
37         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, null, TestSubType.class);\r
38         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
39         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
40         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, TestSubType.class);\r
41         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
42         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
43         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, null);\r
44         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
45         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
46         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, TestSubType2.class);\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     @Test\r
52     public void testEquals() {\r
53         ExperimenterActionSerializerKey key1;\r
54         ExperimenterActionSerializerKey key2;\r
55         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, null);\r
56         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
57         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType2.class);\r
58         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));\r
59         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);\r
60         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));\r
61     }\r
62 \r
63  \r
64     private static class TestSubType extends ExperimenterActionSubType {\r
65         // empty class - only used in test for comparation\r
66     }\r
67 \r
68     private static class TestSubType2 extends ExperimenterActionSubType {\r
69         // empty class - only used in test for comparation\r
70     }\r
71     \r
72 \r
73 }