2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.openflowjava.protocol.api.keys.experimenter;
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;
18 * Unit tests for ExperimenterActionSerializerKey.
20 * @author michal.polkorab
22 public class ExperimenterActionSerializerKeyTest {
23 private static final Uint32 FORTY_TWO = Uint32.valueOf(42);
24 private static final Uint32 FIFTY_FIVE = Uint32.valueOf(55);
27 * Test ExperimenterActionSerializerKey equals and hashCode.
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());
55 * Test ExperimenterActionSerializerKey equals.
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));
70 private interface TestSubType extends ExperimenterActionSubType {
71 TestSubType VALUE = () -> TestSubType.class;
74 Class<? extends TestSubType> implementedInterface();
75 // empty class - only used in test for comparation
78 private interface TestSubType2 extends ExperimenterActionSubType {
79 TestSubType2 VALUE = () -> TestSubType2.class;
82 Class<? extends TestSubType2> implementedInterface();