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