Add Action serializers
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / protocol / serialization / actions / PopMplsActionSerializerTest.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.serialization.actions;
10
11 import static org.junit.Assert.assertEquals;
12
13 import org.junit.Test;
14 import org.opendaylight.openflowjava.protocol.impl.util.ActionConstants;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.Action;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCase;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.PopMplsActionCaseBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.action.pop.mpls.action._case.PopMplsActionBuilder;
19
20 public class PopMplsActionSerializerTest extends AbstractActionSerializerTest {
21
22     @Test
23     public void testSerialize() throws Exception {
24         final int ethType = 10;
25
26         final Action action = new PopMplsActionCaseBuilder()
27                 .setPopMplsAction(new PopMplsActionBuilder()
28                         .setEthernetType(ethType)
29                         .build())
30                 .build();
31
32         assertAction(action, out -> {
33             assertEquals(out.readUnsignedShort(), ethType);
34             out.skipBytes(ActionConstants.ETHERTYPE_ACTION_PADDING);
35         });
36     }
37
38     @Override
39     protected Class<? extends Action> getClazz() {
40         return PopMplsActionCase.class;
41     }
42
43     @Override
44     protected int getType() {
45         return ActionConstants.POP_MPLS_CODE;
46     }
47
48     @Override
49     protected int getLength() {
50         return ActionConstants.GENERAL_ACTION_LENGTH;
51     }
52
53 }