Update MRI upstreams for Phosphorus
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / multipart / MultipartRequestMeterConfigSerializerTest.java
1 /*
2  * Copyright (c) 2017 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 package org.opendaylight.openflowplugin.impl.protocol.serialization.multipart;
9
10 import static org.junit.Assert.assertEquals;
11
12 import io.netty.buffer.ByteBuf;
13 import io.netty.buffer.UnpooledByteBufAllocator;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey;
16 import org.opendaylight.openflowjava.protocol.api.util.EncodeConstants;
17 import org.opendaylight.openflowplugin.impl.protocol.serialization.AbstractSerializerTest;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterConfig;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.multipart.request.multipart.request.body.MultipartRequestMeterConfigBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
21 import org.opendaylight.yangtools.yang.common.Uint32;
22
23 public class MultipartRequestMeterConfigSerializerTest extends AbstractSerializerTest {
24     private static final byte PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY = 4;
25     private static final MultipartRequestMeterConfig BODY = new MultipartRequestMeterConfigBuilder()
26             .setMeterId(new MeterId(Uint32.valueOf(42)))
27             .build();
28
29     private MultipartRequestMeterConfigSerializer serializer;
30
31     @Override
32     protected void init() {
33         serializer = getRegistry().getSerializer(new MessageTypeKey<>(EncodeConstants.OF_VERSION_1_3,
34                 MultipartRequestMeterConfig.class));
35     }
36
37     @Test
38     public void testSerialize() {
39         final ByteBuf out = UnpooledByteBufAllocator.DEFAULT.buffer();
40         serializer.serialize(BODY, out);
41
42         assertEquals(out.readUnsignedInt(), 42);
43         out.skipBytes(PADDING_IN_MULTIPART_REQUEST_METER_CONFIG_BODY);
44         assertEquals(out.readableBytes(), 0);
45     }
46 }