657a34c3e2bf5de8bb8bcf455712d8ccaf1e8c95
[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      * Test ExperimenterActionSerializerKey equals and hashCode\r
24      */\r
25     @Test\r
26     public void test() {\r
27         ExperimenterActionSerializerKey key1 =\r
28                 new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);\r
29         ExperimenterActionSerializerKey key2 =\r
30                 new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);\r
31         Assert.assertTrue("Wrong equals", key1.equals(key2));\r
32         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
33         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF13_VERSION_ID, 42L, TestSubType.class);\r
34         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
35         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
36         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, null, TestSubType.class);\r
37         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
38         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
39         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, TestSubType.class);\r
40         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
41         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
42         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, null);\r
43         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
44         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
45         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, TestSubType2.class);\r
46         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
47         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());\r
48     }\r
49 \r
50     @Test\r
51     public void testEquals() {\r
52         \r
53         ExperimenterActionSerializerKey key1;\r
54         ExperimenterActionSerializerKey key2;\r
55         \r
56         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, null);\r
57                 \r
58         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
59         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
60                 \r
61         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType2.class);\r
62         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));\r
63         \r
64         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);\r
65         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));\r
66         \r
67     }\r
68     \r
69     \r
70     private static class TestSubType extends ExperimenterActionSubType {\r
71         // empty class - only used in test for comparation\r
72     }\r
73 \r
74     private static class TestSubType2 extends ExperimenterActionSubType {\r
75         // empty class - only used in test for comparation\r
76     }\r
77 }