Bump upstreams for 2022.09 Chlorine
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / util / 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.impl.util;
9
10 import org.junit.Assert;
11 import org.junit.Test;
12 import org.opendaylight.openflowplugin.api.OFConstants;
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 import org.opendaylight.yangtools.yang.common.Uint32;
17 import org.opendaylight.yangtools.yang.common.Uint8;
18
19 public class MessageFactoryTest {
20     @Test
21     public void testCreateHelloInputWoElements() {
22         Uint8 highestVersion = Uint8.valueOf(4);
23         Uint32 xid = Uint32.valueOf(42);
24
25         HelloInput helloMsg = MessageFactory.createHelloInput(highestVersion, xid);
26         Assert.assertEquals(highestVersion, helloMsg.getVersion());
27         Assert.assertEquals(xid, helloMsg.getXid());
28         Assert.assertNull(helloMsg.getElements());
29     }
30
31     @Test
32     public void testCreateHelloInputWithElements() {
33         Uint8 highestVersion = Uint8.valueOf(4);
34         Uint32 xid = Uint32.valueOf(42);
35         Boolean[] expectedVersionBitmap = new Boolean[]{false, true, false, false, true};
36
37         HelloInput helloMsg = MessageFactory.createHelloInput(highestVersion, xid, OFConstants.VERSION_ORDER);
38         Assert.assertEquals(highestVersion, helloMsg.getVersion());
39         Assert.assertEquals(xid, helloMsg.getXid());
40         Assert.assertEquals(1, helloMsg.getElements().size());
41         Elements actualElement = helloMsg.getElements().get(0);
42         Assert.assertEquals(HelloElementType.VERSIONBITMAP, actualElement.getType());
43         Assert.assertArrayEquals(expectedVersionBitmap, actualElement.getVersionBitmap().toArray(new Boolean[0]));
44     }
45 }