Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / openflowjava / 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 package org.opendaylight.openflowjava.protocol.api.keys.experimenter;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.keys.ExperimenterActionSerializerKey;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.ExperimenterActionSubType;
15 import org.opendaylight.yangtools.yang.common.Uint32;
16
17 /**
18  * Unit tests for ExperimenterActionSerializerKey.
19  *
20  * @author michal.polkorab
21  */
22 public class ExperimenterActionSerializerKeyTest {
23     private static final Uint32 FORTY_TWO = Uint32.valueOf(42);
24     private static final Uint32 FIFTY_FIVE = Uint32.valueOf(55);
25
26     /**
27      * Test ExperimenterActionSerializerKey equals and hashCode.
28      */
29     @Test
30     public void test() {
31         ExperimenterActionSerializerKey key1 =
32                 new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FORTY_TWO, TestSubType.VALUE);
33         ExperimenterActionSerializerKey key2 =
34                 new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FORTY_TWO, TestSubType.VALUE);
35         Assert.assertTrue("Wrong equals", key1.equals(key2));
36         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
37         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_3, FORTY_TWO, TestSubType.VALUE);
38         Assert.assertFalse("Wrong equals", key1.equals(key2));
39         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
40         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, (Uint32) null, TestSubType.VALUE);
41         Assert.assertFalse("Wrong equals", key1.equals(key2));
42         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
43         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FIFTY_FIVE, TestSubType.VALUE);
44         Assert.assertFalse("Wrong equals", key1.equals(key2));
45         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
46         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FIFTY_FIVE, null);
47         Assert.assertFalse("Wrong equals", key1.equals(key2));
48         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
49         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FIFTY_FIVE, TestSubType2.VALUE);
50         Assert.assertFalse("Wrong equals", key1.equals(key2));
51         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
52     }
53
54     /**
55      * Test ExperimenterActionSerializerKey equals.
56      */
57     @Test
58     public void testEquals() {
59         ExperimenterActionSerializerKey key1;
60         ExperimenterActionSerializerKey key2;
61         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FORTY_TWO, null);
62         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
63         key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FORTY_TWO, TestSubType2.VALUE);
64         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));
65         key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF_VERSION_1_0, FORTY_TWO, TestSubType.VALUE);
66         Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));
67     }
68
69
70     private interface TestSubType extends ExperimenterActionSubType {
71         TestSubType VALUE = () -> TestSubType.class;
72
73         @Override
74         Class<? extends TestSubType> implementedInterface();
75         // empty class - only used in test for comparation
76     }
77
78     private interface TestSubType2 extends ExperimenterActionSubType {
79         TestSubType2 VALUE = () -> TestSubType2.class;
80
81         @Override
82         Class<? extends TestSubType2> implementedInterface();
83     }
84 }