2 * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.ext.deserialization;
\r
11 import io.netty.buffer.ByteBuf;
\r
12 import io.netty.buffer.UnpooledByteBufAllocator;
\r
14 import org.junit.Assert;
\r
15 import org.junit.Test;
\r
16 import org.opendaylight.openflowjava.protocol.ext.util.ExtConstants;
\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.augments.rev131002.ExperimenterAction;
\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.Experimenter;
\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.action.rev130731.actions.grouping.Action;
\r
22 * @author michal.polkorab
\r
25 public class OF10VendorActionDeserializerTest {
\r
28 * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO
\r
29 * @throws Exception
\r
32 public void test() {
\r
33 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
34 buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE);
\r
35 buffer.writeShort(16);
\r
36 buffer.writeInt(42);
\r
37 byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0};
\r
38 buffer.writeBytes(data);
\r
40 OF10VendorActionDeserializer deserializer =
\r
41 new OF10VendorActionDeserializer();
\r
42 Action action = deserializer.deserialize(buffer);
\r
44 Assert.assertEquals("Wrong type", Experimenter.class, action.getType());
\r
45 ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
\r
46 Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue());
\r
47 Assert.assertArrayEquals("Wrong data", data, experimenter.getData());
\r
51 * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO
\r
52 * @throws Exception
\r
55 public void testWithoutData() {
\r
56 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
57 buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE);
\r
58 buffer.writeShort(8);
\r
59 buffer.writeInt(42);
\r
61 OF10VendorActionDeserializer deserializer =
\r
62 new OF10VendorActionDeserializer();
\r
63 Action action = deserializer.deserialize(buffer);
\r
65 Assert.assertEquals("Wrong type", Experimenter.class, action.getType());
\r
66 ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
\r
67 Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue());
\r
68 Assert.assertNull("Data not null", experimenter.getData());
\r
72 * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO
\r
73 * @throws Exception
\r
76 public void testHeader() {
\r
77 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
78 buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE);
\r
79 buffer.writeShort(8);
\r
80 buffer.writeInt(42);
\r
82 OF10VendorActionDeserializer deserializer =
\r
83 new OF10VendorActionDeserializer();
\r
84 Action action = deserializer.deserializeHeader(buffer);
\r
86 Assert.assertEquals("Wrong type", Experimenter.class, action.getType());
\r
87 ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
\r
88 Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue());
\r
89 Assert.assertNull("Data not null", experimenter.getData());
\r
93 * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO
\r
94 * @throws Exception
\r
97 public void testHeaderWithData() {
\r
98 ByteBuf buffer = UnpooledByteBufAllocator.DEFAULT.buffer();
\r
99 buffer.writeShort(ExtConstants.EXPERIMENTER_VALUE);
\r
100 buffer.writeShort(8);
\r
101 buffer.writeInt(42);
\r
102 byte[] data = new byte[]{0, 1, 2, 3, 4, 0, 0, 0};
\r
103 buffer.writeBytes(data);
\r
105 OF10VendorActionDeserializer deserializer =
\r
106 new OF10VendorActionDeserializer();
\r
107 Action action = deserializer.deserializeHeader(buffer);
\r
109 Assert.assertEquals("Wrong type", Experimenter.class, action.getType());
\r
110 ExperimenterAction experimenter = action.getAugmentation(ExperimenterAction.class);
\r
111 Assert.assertEquals("Wrong experimenter", 42, experimenter.getExperimenter().intValue());
\r
112 Assert.assertNull("Data not null", experimenter.getData());
\r