94f0609e4f60d514f6bd66ad4e3ff92d78babf73
[openflowplugin.git] / openflowjava / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / ActionDeserializerKeyTest.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
15 /**
16  * Unit tests for ActionDeserializerKey.
17  *
18  * @author michal.polkorab
19  */
20 public class ActionDeserializerKeyTest {
21
22     /**
23      * Test ActionDeserializerKey equals and hashCode.
24      */
25     @Test
26     public void test() {
27         ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 42L);
28         ActionDeserializerKey key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 42L);
29         Assert.assertTrue("Wrong equals", key1.equals(key2));
30         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
31         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);
32         Assert.assertFalse("Wrong equals", key1.equals(key2));
33         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
34         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 55L);
35         Assert.assertFalse("Wrong equals", key1.equals(key2));
36         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
37         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 0, 42L);
38         Assert.assertFalse("Wrong equals", key1.equals(key2));
39         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
40         key2 = new ActionDeserializerKey(EncodeConstants.OF13_VERSION_ID, 11, 42L);
41         Assert.assertFalse("Wrong equals", key1.equals(key2));
42         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
43     }
44
45     /**
46      * Test ActionDeserializerKey equals - additional test.
47      */
48     @Test
49     public void testEquals() {
50         ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);
51         ActionDeserializerKey key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, 42L);
52
53         Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
54         Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
55         Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));
56         key2 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);
57         Assert.assertTrue("Wrong equal by experimenterId", key1.equals(key2));
58     }
59
60     /**
61      * Test InstructionDeserializerKey toString().
62      */
63     @Test
64     public void testToString() {
65         ActionDeserializerKey key1 = new ActionDeserializerKey(EncodeConstants.OF10_VERSION_ID, 11, null);
66
67         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectClass: org.opendaylight.yang.gen.v1.urn"
68                 + ".opendaylight.openflow.common.action.rev150203.actions.grouping.Action msgType: 11"
69                 + " experimenterID: null", key1.toString());
70     }
71 }