sending hello upon connection established
[openflowplugin.git] / openflowplugin / src / test / java / org / opendaylight / openflowplugin / openflow / md / core / MessageFactoryTest.java
1 /**
2  * Copyright (c) 2013 Cisco Systems, Inc. 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 package org.opendaylight.openflowplugin.openflow.md.core;
9
10
11 import org.junit.Assert;
12 import org.junit.Test;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloInput;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;
16
17 /**
18  * @author mirehak
19  *
20  */
21 public class MessageFactoryTest {
22
23     /**
24      * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.MessageFactory#createHelloInputWoElements(java.lang.Short, java.lang.Long)}.
25      */
26     @Test
27     public void testCreateHelloInputWoElements() {
28         short highestVersion = (short) 0x04;
29         long xid = 42L;
30         
31         HelloInput helloMsg = MessageFactory.createHelloInput(highestVersion, xid);
32         Assert.assertEquals(highestVersion, helloMsg.getVersion().shortValue());
33         Assert.assertEquals(xid, helloMsg.getXid().longValue());
34         Assert.assertNull(helloMsg.getElements());
35     }
36
37     /**
38      * Test method for {@link org.opendaylight.openflowplugin.openflow.md.core.MessageFactory#createHelloInputWithElements(java.lang.Short, java.lang.Long, java.util.List)}.
39      */
40     @Test
41     public void testCreateHelloInputWithElements() {
42         short highestVersion = (short) 0x04;
43         long xid = 42L;
44         Boolean[] expectedVersionBitmap = new Boolean[]{
45                 false, true, false, false, true};
46         
47         HelloInput helloMsg = MessageFactory.createHelloInput(highestVersion, xid, 
48                 ConnectionConductor.versionOrder);
49         Assert.assertEquals(highestVersion, helloMsg.getVersion().shortValue());
50         Assert.assertEquals(xid, helloMsg.getXid().longValue());
51         Assert.assertEquals(1, helloMsg.getElements().size());
52         Elements actualElement = helloMsg.getElements().get(0);
53         Assert.assertEquals(HelloElementType.VERSIONBITMAP, actualElement.getType());
54         Assert.assertArrayEquals(expectedVersionBitmap, actualElement.getVersionBitmap().toArray(new Boolean[0]));
55     }
56
57 }