0ab67a9ae871efd5cf5bcbd7648a4c5ae3d68c44
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / HelloMessageFactoryTest.java
1 /*
2  * Copyright (c) 2013 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.impl.deserialization.factories;
10
11 import java.util.ArrayList;
12 import java.util.List;
13
14 import io.netty.buffer.ByteBuf;
15
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.HelloElementType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.HelloMessage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.Elements;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.hello.ElementsBuilder;
23
24 /**
25  * @author michal.polkorab
26  * @author timotej.kubas
27  */
28 public class HelloMessageFactoryTest {
29
30     /** Number of currently supported version / codec */
31     public static final Short VERSION_YET_SUPPORTED = 0x04;
32
33     /**
34      * Testing {@link HelloMessageFactory} for correct translation into POJO
35      */
36     @Test
37     public void test() {
38         ByteBuf bb = BufferHelper.buildBuffer("00 01 " // type
39                                             + "00 0c " // length
40                                             + "00 00 00 11 " // bitmap 1
41                                             + "00 00 00 00 " // bitmap 2
42                                             + "00 00 00 00"  // padding
43                 );
44         HelloMessage builtByFactory = BufferHelper.decodeV13(
45                 HelloMessageFactory.getInstance(), bb);
46
47         BufferHelper.checkHeaderV13(builtByFactory);
48         List<Elements> element = createElement();
49         Assert.assertEquals("Wrong type", element.get(0).getType(), builtByFactory.getElements().get(0).getType());
50         Assert.assertEquals("Wrong versionBitmap", element.get(0).getVersionBitmap(), builtByFactory.getElements().get(0).getVersionBitmap());
51     }
52     
53     private static List<Elements> createElement() {
54         ElementsBuilder elementsBuilder = new ElementsBuilder();
55         List<Elements> elementsList = new ArrayList<>();
56         List<Boolean> booleanList = new ArrayList<>();
57         booleanList.add(true);
58         booleanList.add(false);
59         booleanList.add(false);
60         booleanList.add(false);
61         booleanList.add(true);
62         for (int i = 1; i < 60; i++) {
63             booleanList.add(false);
64         }
65         elementsBuilder.setType(HelloElementType.forValue(1));
66         elementsBuilder.setVersionBitmap(booleanList);
67         elementsList.add(elementsBuilder.build());
68         
69         return elementsList;
70     }
71 }