Bug 2245 Fixed Avoid cycle between java packages
[openflowjava.git] / openflow-protocol-api / src / test / java / org / opendaylight / openflowjava / protocol / api / extensibility / MessageTypeKeyTest.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.keys.MessageTypeKey;
14 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierInput;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
17
18 /**
19  * @author michal.polkorab
20  *
21  */
22 public class MessageTypeKeyTest {
23
24     /**
25      * Test MessageTypeKey equals and hashCode
26      */
27     @Test
28     public void test() {
29         MessageTypeKey<?> key1 =
30                 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
31         MessageTypeKey<?> key2 =
32                 new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
33         Assert.assertTrue("Wrong equals", key1.equals(key2));
34         Assert.assertTrue("Wrong hashcode", key1.hashCode() == key2.hashCode());
35         key2 = new MessageTypeKey<>(EncodeConstants.OF13_VERSION_ID, BarrierInput.class);
36         Assert.assertFalse("Wrong equals", key1.equals(key2));
37         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
38         key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);
39         Assert.assertFalse("Wrong equals", key1.equals(key2));
40         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
41         key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierOutput.class);
42         Assert.assertFalse("Wrong equals", key1.equals(key2));
43         Assert.assertFalse("Wrong hashcode", key1.hashCode() == key2.hashCode());
44     }
45
46     /**
47      * Test MessageTypeKey equals - additional test
48      */
49     @Test
50     public void testEquals() {
51          MessageTypeKey<?> key1;
52          MessageTypeKey<?> key2;
53          key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
54
55          Assert.assertTrue("Wrong equal to identical object.", key1.equals(key1));
56          Assert.assertFalse("Wrong equal to null.", key1.equals(null));
57          Assert.assertFalse("Wrong equal to different class.", key1.equals(new Object()));
58
59          key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);
60          key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
61          Assert.assertFalse("Wrong equal by msgType.", key1.equals(key2));
62
63          key2 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, null);
64          Assert.assertTrue("Wrong equal by msgType.", key1.equals(key2));
65     }
66
67     /**
68      * Test MessageTypeKey toString()
69      */
70     @Test
71     public void testToString() {
72          MessageTypeKey<?> key1 = new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierInput.class);
73
74          Assert.assertEquals("Wrong toString()", "msgVersion: 1 objectType: org.opendaylight.yang.gen.v1.urn"
75                  + ".opendaylight.openflow.protocol.rev130731.BarrierInput", key1.toString());
76     }
77 }