2 * Copyright (c) 2018 SUSE LINUX GmbH. All rights reserved.
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
8 package org.opendaylight.openflowjava.nx.codec.match;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
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;
24 public class NshMdtypeCodecTest {
26 private NshMdtypeCodec nshMdtypeCodec;
27 private ByteBuf buffer;
29 private static final Uint8 MDTYPE_VALUE = Uint8.ONE;
33 nshMdtypeCodec = new NshMdtypeCodec();
34 buffer = ByteBufAllocator.DEFAULT.buffer();
38 public void serializeValueTest() {
39 NxExpMatchEntryValue matchEntryValue = createMatchEntryValue(MDTYPE_VALUE);
41 nshMdtypeCodec.serializeValue(matchEntryValue, false, buffer);
43 assertEquals(MDTYPE_VALUE.shortValue(), buffer.readUnsignedByte());
44 assertFalse(buffer.isReadable());
48 public void deserializeValueTest() {
49 writeBuffer(buffer, MDTYPE_VALUE);
51 NxExpMatchEntryValue value = nshMdtypeCodec.deserializeValue(buffer, false);
53 assertEquals(MDTYPE_VALUE, ((NshMdtypeCaseValue) value).getNshMdtypeValues().getValue());
54 assertFalse(buffer.isReadable());
57 private static NxExpMatchEntryValue createMatchEntryValue(Uint8 value) {
58 NshMdtypeValues nshMdtypeValues = new NshMdtypeValuesBuilder().setValue(value).build();
59 return new NshMdtypeCaseValueBuilder().setNshMdtypeValues(nshMdtypeValues).build();
62 private static void writeBuffer(ByteBuf message, Uint8 value) {
63 message.writeByte(value.intValue());