Extend openflow-protocol-impl serialization
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10BarrierReplyMessageFactoryTest.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.serialization.factories;
9
10 import io.netty.buffer.ByteBuf;
11 import io.netty.buffer.UnpooledByteBufAllocator;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.api.extensibility.OFSerializer;
15 import org.opendaylight.openflowjava.protocol.api.extensibility.SerializerRegistry;
16 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
17 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
18 import org.opendaylight.openflowjava.protocol.impl.serialization.SerializerRegistryImpl;
19 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutput;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.BarrierOutputBuilder;
22
23 /**
24  * @author giuseppex.petralia@intel.com
25  *
26  */
27 public class OF10BarrierReplyMessageFactoryTest {
28     private OFSerializer<BarrierOutput> factory;
29     private static final byte MESSAGE_TYPE = 19;
30
31     @Before
32     public void startUp() {
33         SerializerRegistry registry = new SerializerRegistryImpl();
34         registry.init();
35         factory = registry.getSerializer(new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierOutput.class));
36     }
37
38     @Test
39     public void testSerialize() throws Exception {
40         BarrierOutputBuilder builder = new BarrierOutputBuilder();
41         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
42         BarrierOutput message = builder.build();
43
44         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
45         factory.serialize(message, serializedBuffer);
46         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 8);
47     }
48 }