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