Remove EncodeConstants.SIZE_OF_{BYTE,SHORT,INT,LONG}_IN_BYTES
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / multipart / MultipartReplyDescDeserializerTest.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
9 package org.opendaylight.openflowplugin.impl.protocol.deserialization.multipart;
10
11 import static org.junit.Assert.assertEquals;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.UnpooledByteBufAllocator;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.multipart.reply.multipart.reply.body.MultipartReplyDesc;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
18
19 public class MultipartReplyDescDeserializerTest extends AbstractMultipartDeserializerTest {
20     private static final int DESC_STR_LEN = 256;
21     private static final int SERIAL_NUM_LEN = 32;
22     private static final String MANUFACTURER = "Company";
23     private static final String HARDWARE = "HW";
24     private static final String SOFTWARE = "SW";
25     private static final String SERIAL_NUMBER = "12345678";
26     private static final String DESCRIPTION = "Description";
27
28     @Test
29     public void deserialize() {
30         ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
31         buffer.writeBytes(MANUFACTURER.getBytes());
32         buffer.writeZero(DESC_STR_LEN - MANUFACTURER.length());
33         buffer.writeBytes(HARDWARE.getBytes());
34         buffer.writeZero(DESC_STR_LEN - HARDWARE.length());
35         buffer.writeBytes(SOFTWARE.getBytes());
36         buffer.writeZero(DESC_STR_LEN - SOFTWARE.length());
37         buffer.writeBytes(SERIAL_NUMBER.getBytes());
38         buffer.writeZero(SERIAL_NUM_LEN - SERIAL_NUMBER.length());
39         buffer.writeBytes(DESCRIPTION.getBytes());
40         buffer.writeZero(DESC_STR_LEN - DESCRIPTION.length());
41
42         final MultipartReplyDesc reply = (MultipartReplyDesc) deserializeMultipart(buffer);
43         assertEquals(MANUFACTURER, reply.getManufacturer().trim());
44         assertEquals(HARDWARE, reply.getHardware().trim());
45         assertEquals(SOFTWARE, reply.getSoftware().trim());
46         assertEquals(SERIAL_NUMBER, reply.getSerialNumber().trim());
47         assertEquals(DESCRIPTION, reply.getDescription().trim());
48         assertEquals(0, buffer.readableBytes());
49     }
50
51     @Override
52     protected int getType() {
53         return MultipartType.OFPMPDESC.getIntValue();
54     }
55 }