Add method to register listener for unknown msg
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / deserialization / instruction / AbstractInstructionDeserializerTest.java
1 /*
2  * Copyright (c) 2014 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.openflowjava.protocol.impl.deserialization.instruction;
10
11 import io.netty.buffer.ByteBuf;
12
13 import org.junit.Assert;
14 import org.junit.Test;
15 import org.opendaylight.openflowjava.util.ByteBufUtils;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ApplyActionsCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.ClearActionsCase;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.GotoTableCase;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.MeterCase;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteActionsCase;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instruction.grouping.instruction.choice.WriteMetadataCase;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.instructions.grouping.Instruction;
23
24 /**
25  * @author michal.polkorab
26  *
27  */
28 public class AbstractInstructionDeserializerTest {
29
30     /**
31      * Tests {@link AbstractInstructionDeserializer#deserializeHeader(ByteBuf)} with different
32      * instruction types
33      */
34     @Test
35     public void test() {
36         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 00 04");
37         Instruction instruction = new GoToTableInstructionDeserializer().deserializeHeader(buffer);
38         Assert.assertTrue("Wrong type", instruction.getInstructionChoice() instanceof GotoTableCase);
39
40         buffer = ByteBufUtils.hexStringToByteBuf("00 02 00 04");
41         instruction = new WriteMetadataInstructionDeserializer().deserializeHeader(buffer);
42         Assert.assertTrue("Wrong type", instruction.getInstructionChoice() instanceof WriteMetadataCase);
43
44         buffer = ByteBufUtils.hexStringToByteBuf("00 03 00 04");
45         instruction = new WriteActionsInstructionDeserializer().deserializeHeader(buffer);
46         Assert.assertTrue("Wrong type", instruction.getInstructionChoice() instanceof WriteActionsCase);
47
48         buffer = ByteBufUtils.hexStringToByteBuf("00 04 00 04");
49         instruction = new ApplyActionsInstructionDeserializer().deserializeHeader(buffer);
50         Assert.assertTrue("Wrong type", instruction.getInstructionChoice() instanceof ApplyActionsCase);
51
52         buffer = ByteBufUtils.hexStringToByteBuf("00 05 00 04");
53         instruction = new ClearActionsInstructionDeserializer().deserializeHeader(buffer);
54         Assert.assertTrue("Wrong type", instruction.getInstructionChoice() instanceof ClearActionsCase);
55
56         buffer = ByteBufUtils.hexStringToByteBuf("00 06 00 04");
57         instruction = new MeterInstructionDeserializer().deserializeHeader(buffer);
58         Assert.assertTrue("Wrong type", instruction.getInstructionChoice() instanceof MeterCase);
59     }
60 }