dcfbe924261c71b1a0624862caa4c9c6d326429a
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / instruction / AbstractInstructionDeserializerTest.java
1 /*\r
2  * Copyright (c) 2014 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.impl.deserialization.instruction;\r
10 \r
11 import io.netty.buffer.ByteBuf;\r
12 \r
13 import org.junit.Assert;\r
14 import org.junit.Test;\r
15 import org.opendaylight.openflowjava.util.ByteBufUtils;\r
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ApplyActions;\r
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions;\r
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;\r
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter;\r
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;\r
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;\r
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;\r
23 \r
24 /**\r
25  * @author michal.polkorab\r
26  *\r
27  */\r
28 public class AbstractInstructionDeserializerTest {\r
29 \r
30     /**\r
31      * Tests {@link AbstractInstructionDeserializer#deserializeHeader(ByteBuf)} with different\r
32      * instruction types\r
33      */\r
34     @Test(expected=IllegalStateException.class)\r
35     public void test() {\r
36         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 00 04");\r
37         GoToTableInstructionDeserializer deserializer = new GoToTableInstructionDeserializer();\r
38         Instruction instruction = deserializer.deserializeHeader(buffer);\r
39         Assert.assertEquals("Wrong type", GotoTable.class, instruction.getType());\r
40 \r
41         buffer = ByteBufUtils.hexStringToByteBuf("00 02 00 04");\r
42         instruction = deserializer.deserializeHeader(buffer);\r
43         Assert.assertEquals("Wrong type", WriteMetadata.class, instruction.getType());\r
44 \r
45         buffer = ByteBufUtils.hexStringToByteBuf("00 03 00 04");\r
46         instruction = deserializer.deserializeHeader(buffer);\r
47         Assert.assertEquals("Wrong type", WriteActions.class, instruction.getType());\r
48 \r
49         buffer = ByteBufUtils.hexStringToByteBuf("00 04 00 04");\r
50         instruction = deserializer.deserializeHeader(buffer);\r
51         Assert.assertEquals("Wrong type", ApplyActions.class, instruction.getType());\r
52 \r
53         buffer = ByteBufUtils.hexStringToByteBuf("00 05 00 04");\r
54         instruction = deserializer.deserializeHeader(buffer);\r
55         Assert.assertEquals("Wrong type", ClearActions.class, instruction.getType());\r
56 \r
57         buffer = ByteBufUtils.hexStringToByteBuf("00 06 00 04");\r
58         instruction = deserializer.deserializeHeader(buffer);\r
59         Assert.assertEquals("Wrong type", Meter.class, instruction.getType());\r
60 \r
61         buffer = ByteBufUtils.hexStringToByteBuf("00 00 00 04");\r
62         instruction = deserializer.deserializeHeader(buffer);\r
63         // exception expected\r
64     }\r
65 }