Clean up instance checks and casts
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / deserialization / action / SetMplsTtlActionDeserializerTest.java
1 /*
2  * Copyright (c) 2016 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.openflowplugin.impl.protocol.deserialization.action;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.UnpooledByteBufAllocator;
16 import org.junit.Test;
17 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.SetMplsTtlActionCase;
20
21 public class SetMplsTtlActionDeserializerTest extends AbstractActionDeserializerTest {
22
23     @Test
24     public void testDeserialize() throws Exception {
25         final ByteBuf in = UnpooledByteBufAllocator.DEFAULT.buffer();
26         final short mplsTtl = 10;
27         writeHeader(in);
28         in.writeByte(mplsTtl);
29         in.writeZero(ActionConstants.SET_MPLS_TTL_PADDING);
30
31         final Action action = deserializeAction(in);
32         assertTrue(action instanceof SetMplsTtlActionCase);
33         assertEquals(mplsTtl, ((SetMplsTtlActionCase) action).getSetMplsTtlAction().getMplsTtl().shortValue());
34         assertEquals(0, in.readableBytes());
35     }
36
37     @Override
38     protected short getType() {
39         return ActionConstants.SET_MPLS_TTL_CODE;
40     }
41
42     @Override
43     protected short getLength() {
44         return ActionConstants.GENERAL_ACTION_LENGTH;
45     }
46
47 }