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