Copyright update
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / OF10VendorInputMessageFactoryTest.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.serialization.factories;
10
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.UnpooledByteBufAllocator;
13
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
17 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;
20
21 /**
22  * @author michal.polkorab
23  *
24  */
25 public class OF10VendorInputMessageFactoryTest {
26
27     /**
28      * Testing of {@link OF10VendorInputMessageFactory} for correct translation from POJO
29      * @throws Exception 
30      */
31     @Test
32     public void test() throws Exception {
33         ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
34         BufferHelper.setupHeader(builder, EncodeConstants.OF10_VERSION_ID);
35         builder.setExperimenter(0x0001020304L);
36         builder.setData(new byte[] {0x01, 0x02, 0x03, 0x04});
37         ExperimenterInput message = builder.build();
38         
39         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
40         OF10VendorInputMessageFactory factory = OF10VendorInputMessageFactory.getInstance();
41         factory.messageToBuffer(EncodeConstants.OF10_VERSION_ID, out, message);
42         
43         BufferHelper.checkHeaderV10(out, (byte) 4, factory.computeLength(message));
44         Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());
45         byte[] data = new byte[4];
46         out.readBytes(data);
47         Assert.assertArrayEquals("Wrong data", message.getData(), data);
48     }
49
50 }