changes for config subsystem - BUG 754
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / serialization / factories / ExperimenterInputMessageFactoryTest.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.deserialization.factories.HelloMessageFactoryTest;
17 import org.opendaylight.openflowjava.protocol.impl.util.BufferHelper;
18 import org.opendaylight.openflowjava.protocol.impl.util.EncodeConstants;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInput;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder;
21
22 /**
23  * @author michal.polkorab
24  * @author timotej.kubas
25  */
26 public class ExperimenterInputMessageFactoryTest {
27
28     private static final byte EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE = ExperimenterInputMessageFactory.MESSAGE_TYPE;
29     
30     /**
31      * Testing of {@link ExperimenterInputMessageFactory} for correct translation from POJO
32      * @throws Exception 
33      */
34     @Test
35     public void test() throws Exception {
36         ExperimenterInputBuilder builder = new ExperimenterInputBuilder();
37         BufferHelper.setupHeader(builder, EncodeConstants.OF13_VERSION_ID);
38         builder.setExperimenter(0x0001020304L);
39         builder.setExpType(0x0001020304L);
40         builder.setData(new byte[] {0x01, 0x02, 0x03});
41         ExperimenterInput message = builder.build();
42         
43         ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
44         ExperimenterInputMessageFactory factory = ExperimenterInputMessageFactory.getInstance();
45         factory.messageToBuffer(HelloMessageFactoryTest.VERSION_YET_SUPPORTED, out, message);
46         
47         BufferHelper.checkHeaderV13(out, EXPERIMENTER_REQUEST_MESSAGE_CODE_TYPE, factory.computeLength(message));
48         Assert.assertEquals("Wrong experimenter", 0x0001020304L, out.readUnsignedInt());
49         Assert.assertEquals("Wrong expType", 0x0001020304L, out.readUnsignedInt());
50         Assert.assertArrayEquals("Wrong data", message.getData(), readData(out));
51     }
52     
53     private static byte[] readData(ByteBuf input) {
54         byte[] data = new byte[input.readableBytes()]; 
55         input.readBytes(data);
56         return data;
57     }
58 }