Mass replace CRLF->LF
[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.ApplyActions;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.ClearActions;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.GotoTable;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.Meter;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteActions;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.instruction.rev130731.WriteMetadata;
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(expected=IllegalStateException.class)
35     public void test() {
36         ByteBuf buffer = ByteBufUtils.hexStringToByteBuf("00 01 00 04");
37         GoToTableInstructionDeserializer deserializer = new GoToTableInstructionDeserializer();
38         Instruction instruction = deserializer.deserializeHeader(buffer);
39         Assert.assertEquals("Wrong type", GotoTable.class, instruction.getType());
40
41         buffer = ByteBufUtils.hexStringToByteBuf("00 02 00 04");
42         instruction = deserializer.deserializeHeader(buffer);
43         Assert.assertEquals("Wrong type", WriteMetadata.class, instruction.getType());
44
45         buffer = ByteBufUtils.hexStringToByteBuf("00 03 00 04");
46         instruction = deserializer.deserializeHeader(buffer);
47         Assert.assertEquals("Wrong type", WriteActions.class, instruction.getType());
48
49         buffer = ByteBufUtils.hexStringToByteBuf("00 04 00 04");
50         instruction = deserializer.deserializeHeader(buffer);
51         Assert.assertEquals("Wrong type", ApplyActions.class, instruction.getType());
52
53         buffer = ByteBufUtils.hexStringToByteBuf("00 05 00 04");
54         instruction = deserializer.deserializeHeader(buffer);
55         Assert.assertEquals("Wrong type", ClearActions.class, instruction.getType());
56
57         buffer = ByteBufUtils.hexStringToByteBuf("00 06 00 04");
58         instruction = deserializer.deserializeHeader(buffer);
59         Assert.assertEquals("Wrong type", Meter.class, instruction.getType());
60
61         buffer = ByteBufUtils.hexStringToByteBuf("00 00 00 04");
62         instruction = deserializer.deserializeHeader(buffer);
63         // exception expected
64     }
65 }