Bug 2756 - Action model update
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / experimenter / ExperimenterActionSerializerKeyTest.java
1 /*
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowjava.protocol.api.keys.experimenter;
10
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
16
17 /**
18  * @author michal.polkorab
19  *
20  */
21 public class ExperimenterActionSerializerKeyTest {
22
23
24     /**
25      * Test ExperimenterActionSerializerKey equals and hashCode
26      */
27     @Test
28     public void test() {
29         ExperimenterActionSerializerKey key1 =
30                 new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
31         ExperimenterActionSerializerKey key2 =
32                 new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
33         Assert.assertTrue("Wrong equals", key1.equals(key2));
34         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
35         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF13_VERSION_ID, 42L, TestSubType.class);
36         Assert.assertFalse("Wrong equals", key1.equals(key2));
37         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
38         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, null, TestSubType.class);
39         Assert.assertFalse("Wrong equals", key1.equals(key2));
40         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
41         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, TestSubType.class);
42         Assert.assertFalse("Wrong equals", key1.equals(key2));
43         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
44         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, null);
45         Assert.assertFalse("Wrong equals", key1.equals(key2));
46         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
47         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 55L, TestSubType2.class);
48         Assert.assertFalse("Wrong equals", key1.equals(key2));
49         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
50     }
51
52     /**
53      * Test ExperimenterActionSerializerKey equals
54      */
55     @Test
56     public void testEquals() {
57         ExperimenterActionSerializerKey key1;
58         ExperimenterActionSerializerKey key2;
59         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, null);
60         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
61         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType2.class);
62         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));
63         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
64         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));
65     }
66
67
68     private static class TestSubType extends ExperimenterActionSubType {
69         // empty class - only used in test for comparation
70     }
71
72     private static class TestSubType2 extends ExperimenterActionSubType {
73         // empty class - only used in test for comparation
74     }
75
76
77 }