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
9 package org.opendaylight.openflowjava.protocol.api.keys.experimenter;
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.rev130731.ExperimenterActionSubType;
18 * @author michal.polkorab
21 public class ExperimenterActionSerializerKeyTest {
25 * Test ExperimenterActionSerializerKey equals and hashCode
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());
53 public void testEquals() {
54 ExperimenterActionSerializerKey key1;
55 ExperimenterActionSerializerKey key2;
56 key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, null);
57 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
58 key2 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType2.class);
59 Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));
60 key1 = new ExperimenterActionSerializerKey(EncodeConstants.OF10_VERSION_ID, 42L, TestSubType.class);
61 Assert.assertFalse("Wrong equal by actionSubType.", key1.equals(key2));
65 private static class TestSubType extends ExperimenterActionSubType {
66 // empty class - only used in test for comparation
69 private static class TestSubType2 extends ExperimenterActionSubType {
70 // empty class - only used in test for comparation