Extend openflow-protocol-impl serialization
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / factories / RoleRequestInputMessageFactoryTest.java
1 /*
2  * Copyright (c) 2015 NetIDE Consortium 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.openflowjava.protocol.impl.deserialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import java.math.BigInteger;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.DeserializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.extensibility.OFDeserializer;
17 import org.opendaylight.openflowjava.protocol.api.keys.MessageCodeKey;
18 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
19 import org.opendaylight.openflowjava.protocol.impl.deserialization.DeserializerRegistryImpl;
20 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.ControllerRole;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.RoleRequestInput;
23
24 /**
25  * @author giuseppex.petralia@intel.com
26  *
27  */
28 public class RoleRequestInputMessageFactoryTest {
29     private OFDeserializer<RoleRequestInput> factory;
30
31     @Before
32     public void startUp() {
33         DeserializerRegistry desRegistry = new DeserializerRegistryImpl();
34         desRegistry.init();
35         factory = desRegistry
36                 .getDeserializer(new MessageCodeKey(EncodeConstants.OF13_VERSION_ID, 24, RoleRequestInput.class));
37
38     }
39
40     @Test
41     public void test() {
42         ByteBuf bb = BufferHelper.buildBuffer("00 00 00 02 00 00 00 00 ff 01 01 01 01 01 01 01");
43         RoleRequestInput deserializedMessage = BufferHelper.deserialize(factory, bb);
44         BufferHelper.checkHeaderV13(deserializedMessage);
45         Assert.assertEquals("Wrong role", ControllerRole.forValue(2), deserializedMessage.getRole());
46         byte[] generationId = new byte[] { (byte) 0xFF, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01 };
47         Assert.assertEquals("Wrong generation Id", new BigInteger(1, generationId),
48                 deserializedMessage.getGenerationId());
49     }
50
51 }