Fix checkstyle violations in openflow-protocol-api
[openflowplugin.git] / openflowjava / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / InstructionSerializerKeyTest.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;
10
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase;
16
17 /**
18  * Unit tests for InstructionSerializerKey.
19  *
20  * @author michal.polkorab
21  */
22 public class InstructionSerializerKeyTest {
23
24     /**
25      * Test InstructionSerializerKey equals and hashCode.
26      */
27     @Test
28     public void test() {
29         InstructionSerializerKey<?> key1 =
30                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
31         InstructionSerializerKey<?> key2 =
32                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
33         Assert.assertTrue("Wrong equals", key1.equals(key2));
34         Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());
35         key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, null);
36         Assert.assertFalse("Wrong equals", key1.equals(key2));
37         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
38         key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
39         Assert.assertFalse("Wrong equals", key1.equals(key2));
40         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
41         key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, WriteActionsCase.class, 42L);
42         Assert.assertFalse("Wrong equals", key1.equals(key2));
43         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
44         key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 55L);
45         Assert.assertFalse("Wrong equals", key1.equals(key2));
46         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
47         key2 = new InstructionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, ApplyActionsCase.class, 42L);
48         Assert.assertFalse("Wrong equals", key1.equals(key2));
49         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
50     }
51
52     /**
53      * Test InstructionSerializerKey equals  - additional test.
54      */
55     @Test
56     public void testEquals() {
57         InstructionSerializerKey<?> key1 =
58                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
59
60         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
61         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
62
63         InstructionSerializerKey<?> key2 =
64                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
65         key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, null);
66         Assert.assertFalse("Wrong equal by experimenterId.", key1.equals(key2));
67
68         key1 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
69         key2 = new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
70         Assert.assertTrue("Wrong equal by instructionType.", key1.equals(key2));
71     }
72
73     /**
74      * Test InstructionSerializerKey toString().
75      */
76     @Test
77     public void testToString() {
78         InstructionSerializerKey<?> key1 =
79                 new InstructionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, ApplyActionsCase.class, 42L);
80
81         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn"
82                 + ".opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction "
83                 + "instructionType type: org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction"
84                 + ".rev130731.instruction.grouping.instruction.choice.ApplyActionsCase vendorID: 42", key1.toString());
85     }
86 }