8e7d1f5fd53676c836b488dfad182af981ae29ca
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / InstructionSerializerKeyTest.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.instruction.rev130731.ApplyActions;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;\r
16 \r
17 /**\r
18  * @author michal.polkorab\r
19  *\r
20  */\r
21 public class InstructionSerializerKeyTest {\r
22 \r
23     /**\r
24      * Test InstructionSerializerKey equals and hashCode\r
25      */\r
26     @Test\r
27     public void test() {\r
28         InstructionSerializerKey<?> key1 =\r
29                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);\r
30                 InstructionSerializerKey<?> key2 =\r
31                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.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 InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.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 InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
38         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
39         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
40         key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, WriteActions.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 InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.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 InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, ApplyActions.class, 42L);\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 InstructionSerializerKey equals  - additional test\r
53      */\r
54     @Test\r
55     public void testEquals(){\r
56         InstructionSerializerKey<?> key1 =\r
57                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);\r
58         InstructionSerializerKey<?> key2 =\r
59                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);\r
60 \r
61         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
62         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
63 \r
64         key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, null);\r
65         Assert.assertFalse("Wrong equal by experimenterId.", key1.equals(key2));\r
66 \r
67         key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
68         key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);\r
69         Assert.assertTrue("Wrong equal by instructionType.", key1.equals(key2));\r
70     }\r
71 \r
72     /**\r
73      * Test InstructionSerializerKey toString()\r
74      */\r
75     @Test\r
76     public void testToString(){\r
77         InstructionSerializerKey<?> key1 =\r
78                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActions.class, 42L);\r
79 \r
80         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn.opendaylight"\r
81                 + ".openflow.common.instruction.rev130731.instructions.grouping.Instruction"\r
82                 + " instructionType type: org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common"\r
83                 + ".instruction.rev130731.ApplyActions vendorID: 42", key1.toString());\r
84     }\r
85 }