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