Bug 2756 - Action model update
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / keys / ActionSerializerKeyTest.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.action.rev150203.action.grouping.action.choice.CopyTtlInCase;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action.grouping.action.choice.CopyTtlOutCase;
16
17 /**
18  * @author michal.polkorab
19  *
20  */
21 public class ActionSerializerKeyTest {
22
23     /**
24      * Test ActionSerializerKey equals and hashCode
25      */
26     @Test
27     public void test() {
28         ActionSerializerKey<CopyTtlInCase> key1 =
29                 new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, 42L);
30         ActionSerializerKey<?> key2 =
31                 new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, 42L);
32         Assert.assertTrue("Wrong equals", key1.equals(key2));
33         Assert.assertTrue("Wrong hashCode", key1.hashCode() == key2.hashCode());
34         key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, null);
35         Assert.assertFalse("Wrong equals", key1.equals(key2));
36         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
37         key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 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, CopyTtlOutCase.class, 42L);
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, CopyTtlInCase.class, 55L);
44         Assert.assertFalse("Wrong equals", key1.equals(key2));
45         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
46         key2 = new ActionSerializerKey<>(EncodeConstants.OF13_VERSION_ID, CopyTtlInCase.class, 55L);
47         Assert.assertFalse("Wrong equals", key1.equals(key2));
48         Assert.assertFalse("Wrong hashCode", key1.hashCode() == key2.hashCode());
49     }
50
51     /**
52      * Test ActionSerializerKey equals - additional test
53      */
54     @Test
55     public void testEquals(){
56          ActionSerializerKey<?> key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
57          ActionSerializerKey<?> key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
58                  CopyTtlInCase.class, 42L);
59
60          Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
61          Assert.assertFalse("Wrong equal by actionType", key1.equals(key2));
62
63          key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, null, 42L);
64          Assert.assertTrue("Wrong equal by action type", key1.equals(key2));
65          key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID,  CopyTtlInCase.class, null);
66          Assert.assertFalse("Wrong equal by experimenterId", key1.equals(key2));
67          key2 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID, CopyTtlInCase.class, null);
68          Assert.assertTrue("Wrong equal by experimenterId", key1.equals(key2));
69     }
70
71     /**
72      * Test ActionSerializerKey toString()
73      */
74     @Test
75     public void testToString(){
76         ActionSerializerKey<CopyTtlInCase> key1 = new ActionSerializerKey<>(EncodeConstants.OF10_VERSION_ID,
77                 CopyTtlInCase.class, 42L);
78
79         Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn"
80                 + ".opendaylight.openflow.common.action.rev150203.actions.grouping.Action action type:"
81                 + " org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev150203.action"
82                 + ".grouping.action.choice.CopyTtlInCase experimenterID: 42", key1.toString());
83     }
84 }