Default experimenters moved to separate bundle + unit tests
[openflowjava.git] / openflow-protocol-ext / src / test / java / org / opendaylight / openflowjava / protocol / ext / deserialization / OF10VendorActionDeserializerTest.java
1 /*\r
2  * Copyright (c) 2013 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\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
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.ext.deserialization;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 import io.netty.buffer.UnpooledByteBufAllocator;\r
13 \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
20 \r
21 /**\r
22  * @author michal.polkorab\r
23  *\r
24  */\r
25 public class OF10VendorActionDeserializerTest {\r
26 \r
27     /**\r
28      * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO\r
29      * @throws Exception \r
30      */\r
31     @Test\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
39 \r
40         OF10VendorActionDeserializer deserializer =\r
41                 new OF10VendorActionDeserializer();\r
42         Action action = deserializer.deserialize(buffer);\r
43 \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
48     }\r
49 \r
50     /**\r
51      * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO\r
52      * @throws Exception \r
53      */\r
54     @Test\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
60 \r
61         OF10VendorActionDeserializer deserializer =\r
62                 new OF10VendorActionDeserializer();\r
63         Action action = deserializer.deserialize(buffer);\r
64 \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
69     }\r
70 \r
71     /**\r
72      * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO\r
73      * @throws Exception \r
74      */\r
75     @Test\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
81 \r
82         OF10VendorActionDeserializer deserializer =\r
83                 new OF10VendorActionDeserializer();\r
84         Action action = deserializer.deserializeHeader(buffer);\r
85 \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
90     }\r
91 \r
92     /**\r
93      * Testing of {@link OF13ExperimenterActionDeserializer} for correct translation into POJO\r
94      * @throws Exception \r
95      */\r
96     @Test\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
104 \r
105         OF10VendorActionDeserializer deserializer =\r
106                 new OF10VendorActionDeserializer();\r
107         Action action = deserializer.deserializeHeader(buffer);\r
108 \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
113     }\r
114 }\r