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;
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlInCase;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase;
15 import org.opendaylight.yangtools.yang.common.Uint32;
18 * Unit tests for ActionSerializerKey.
20 * @author michal.polkorab
22 public class ActionSerializerKeyTest {
23 private static final Uint32 FORTY_TWO = Uint32.valueOf(42);
24 private static final Uint32 FIFTY_FIVE = Uint32.valueOf(55);
27 * Test ActionSerializerKey equals and hashCode.
31 ActionSerializerKey<CopyTtlInCase> key1 =
32 new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, FORTY_TWO);
33 ActionSerializerKey<?> key2 =
34 new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, FORTY_TWO);
35 Assert.assertTrue("Wrong equals", key1.equals(key2));
36 Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());
37 key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, (Uint32) null);
38 Assert.assertFalse("Wrong equals", key1.equals(key2));
39 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
40 key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, (Uint32) null);
41 Assert.assertFalse("Wrong equals", key1.equals(key2));
42 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
43 key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlOutCase.class, FORTY_TWO);
44 Assert.assertFalse("Wrong equals", key1.equals(key2));
45 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
46 key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, FIFTY_FIVE);
47 Assert.assertFalse("Wrong equals", key1.equals(key2));
48 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
49 key2 = new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, CopyTtlInCase.class, FIFTY_FIVE);
50 Assert.assertFalse("Wrong equals", key1.equals(key2));
51 Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
55 * Test ActionSerializerKey equals - additional test.
58 public void testEquals() {
59 ActionSerializerKey<?> key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, FORTY_TWO);
60 ActionSerializerKey<?> key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
61 CopyTtlInCase.class, FORTY_TWO);
63 Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
64 Assert.assertFalse("Wrong equal by actionType", key1.equals(key2));
66 key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, FORTY_TWO);
67 Assert.assertTrue("Wrong equal by action type", key1.equals(key2));
68 key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, (Uint32) null);
69 Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));
70 key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, (Uint32) null);
71 Assert.assertTrue("Wrong equal by experimenterId", key1.equals(key2));
75 * Test ActionSerializerKey toString().
78 public void testToString() {
79 ActionSerializerKey<CopyTtlInCase> key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
80 CopyTtlInCase.class, FORTY_TWO);
82 Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn"
83 + ".opendaylight.openflow.common.action.rev150203.actions.grouping.Action action type:"
84 + " org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action"
85 + ".grouping.action.choice.CopyTtlInCase experimenterID: 42", key1.toString());