3b3817d126c2db18fc00aa11e3cbafd1ef79b8a2
[openflowplugin.git] / openflowjava / 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  * Unit tests for OF10BarrierReplyMessageFactory.
25  *
26  * @author giuseppex.petralia@intel.com
27  */
28 public class OF10BarrierReplyMessageFactoryTest {
29     private OFSerializer<BarrierOutput> factory;
30     private static final byte MESSAGE_TYPE = 19;
31
32     @Before
33     public void startUp() {
34         SerializerRegistry registry = new SerializerRegistryImpl();
35         registry.init();
36         factory = registry.getSerializer(new MessageTypeKey<>(EncodeConstants.OF10_VERSION_ID, BarrierOutput.class));
37     }
38
39     @Test
40     public void testSerialize() throws Exception {
41         BarrierOutputBuilder builder = new BarrierOutputBuilder();
42         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
43         BarrierOutput message = builder.build();
44
45         ByteBuf serializedBuffer = UnpooledByteBufAllocator.DEFAULT.buffer();
46         factory.serialize(message, serializedBuffer);
47         BufferHelper.checkHeaderV10(serializedBuffer, MESSAGE_TYPE, 8);
48     }
49 }