5e79712df9515680487733b492d89b89cdb93792
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / MatchEntrySerializerKeyTest.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.oxm.rev130731.InPhyPort;\r
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.InPort;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.Nxm0Class;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.oxm.rev130731.OpenflowBasicClass;\r
18 \r
19 /**\r
20  * @author michal.polkorab\r
21  *\r
22  */\r
23 public class MatchEntrySerializerKeyTest {\r
24 \r
25     /**\r
26      * Test MatchEntrySerializerKey equals and hashCode\r
27      */\r
28     @Test\r
29     public void test() {\r
30         MatchEntrySerializerKey<?, ?> key1 = new MatchEntrySerializerKey<>\r
31                 (EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);\r
32         MatchEntrySerializerKey<?, ?> key2 = new MatchEntrySerializerKey<>\r
33                 (EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);\r
34         Assert.assertTrue("Wrong equals", key1.equals(key2));\r
35         Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
36         key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,\r
37                 OpenflowBasicClass.class, InPhyPort.class);\r
38         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
39         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
40         key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,\r
41                 Nxm0Class.class, InPort.class);\r
42         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
43         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
44         key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF10_VERSION_ID,\r
45                 OpenflowBasicClass.class, InPhyPort.class);\r
46         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
47         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
48         key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,\r
49                 OpenflowBasicClass.class, null);\r
50         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
51         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
52         key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID,\r
53                 null, InPhyPort.class);\r
54         Assert.assertFalse("Wrong equals", key1.equals(key2));\r
55         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());\r
56     }\r
57     \r
58     /**\r
59      * Test MatchEntrySerializerKey equals - additional test \r
60      */\r
61     @Test\r
62     public void testEquals(){\r
63         MatchEntrySerializerKey<?, ?> key1;\r
64         MatchEntrySerializerKey<?, ?> key2;\r
65         key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);\r
66         key2 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, InPort.class);\r
67         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));\r
68         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));\r
69         \r
70         Long expId1 = 987654331L;\r
71         Long expId2 = 123456789L;\r
72         \r
73         key1.setExperimenterId(null);\r
74         key2.setExperimenterId(expId2);\r
75         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
76         key1.setExperimenterId(expId1);\r
77         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));\r
78         key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, null, InPort.class);\r
79         key1.setExperimenterId(expId2);\r
80         Assert.assertFalse("Wrong equal by oxmClass", key1.equals(key2));\r
81         key1 = new MatchEntrySerializerKey<>(EncodeConstants.OF13_VERSION_ID, OpenflowBasicClass.class, null);\r
82         key1.setExperimenterId(expId2);\r
83         Assert.assertFalse("Wrong equal by oxmField", key1.equals(key2));\r
84     }\r
85 }