0263d0eb6b10595c7daafe15ed4915b7b82e2d7a
[openflowplugin.git] / extension / openflowjava-extension-nicira / src / test / java / org / opendaylight / openflowjava / nx / codec / match / NshMdtypeCodecTest.java
1 /*
2  * Copyright (c) 2018 SUSE LINUX GmbH.  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 package org.opendaylight.openflowjava.nx.codec.match;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.ByteBufAllocator;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.mdtype.grouping.NshMdtypeValues;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.ofj.nxm.nx.match.nsh.mdtype.grouping.NshMdtypeValuesBuilder;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.NxExpMatchEntryValue;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NshMdtypeCaseValue;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.match.rev140421.oxm.container.match.entry.value.experimenter.id._case.nx.exp.match.entry.value.NshMdtypeCaseValueBuilder;
22 import org.opendaylight.yangtools.yang.common.Uint8;
23
24 public class NshMdtypeCodecTest {
25
26     private NshMdtypeCodec nshMdtypeCodec;
27     private ByteBuf buffer;
28
29     private static final Uint8 MDTYPE_VALUE = Uint8.ONE;
30
31     @Before
32     public void setUp() {
33         nshMdtypeCodec = new NshMdtypeCodec();
34         buffer = ByteBufAllocator.DEFAULT.buffer();
35     }
36
37     @Test
38     public void serializeValueTest() {
39         NxExpMatchEntryValue matchEntryValue = createMatchEntryValue(MDTYPE_VALUE);
40
41         nshMdtypeCodec.serializeValue(matchEntryValue, false, buffer);
42
43         assertEquals(MDTYPE_VALUE.shortValue(), buffer.readUnsignedByte());
44         assertFalse(buffer.isReadable());
45     }
46
47     @Test
48     public void deserializeValueTest() {
49         writeBuffer(buffer, MDTYPE_VALUE);
50
51         NxExpMatchEntryValue value = nshMdtypeCodec.deserializeValue(buffer, false);
52
53         assertEquals(MDTYPE_VALUE, ((NshMdtypeCaseValue) value).getNshMdtypeValues().getValue());
54         assertFalse(buffer.isReadable());
55     }
56
57     private static NxExpMatchEntryValue createMatchEntryValue(Uint8 value) {
58         NshMdtypeValues nshMdtypeValues = new NshMdtypeValuesBuilder().setValue(value).build();
59         return new NshMdtypeCaseValueBuilder().setNshMdtypeValues(nshMdtypeValues).build();
60     }
61
62     private static void writeBuffer(ByteBuf message, Uint8 value) {
63         message.writeByte(value.intValue());
64     }
65 }