2 * Copyright (c) 2016 Cisco Systems, Inc. and others. 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.protocol.pcep.auto.bandwidth.extension;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import com.google.common.collect.Lists;
14 import io.netty.buffer.ByteBuf;
15 import io.netty.buffer.Unpooled;
16 import org.junit.Test;
17 import org.opendaylight.protocol.pcep.PCEPDeserializerException;
18 import org.opendaylight.protocol.pcep.spi.ObjectHeaderImpl;
19 import org.opendaylight.protocol.util.ByteArray;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsage;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsageBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
24 public class PCEPBandwidthUsageObjectCodecTest {
26 private static final byte[] BW_BYTES = new byte[]{0x05, 0x50, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00,
27 0x00, 0x00, 0x40, 0x00};
30 public void testCodec() throws PCEPDeserializerException {
31 final BandwidthUsageObjectCodec codec = new BandwidthUsageObjectCodec(5);
32 assertEquals(5, codec.getObjectType());
34 final BandwidthUsageBuilder builder = new BandwidthUsageBuilder()
35 .setBwSample(Lists.newArrayList(new Bandwidth(new byte[]{0x00, 0x00, 0x10, 0x00}),
36 new Bandwidth(new byte[]{0x00, 0x00, 0x40, 0x00})))
38 .setProcessingRule(false);
39 final BandwidthUsage parsedObject = codec.parseObject(new ObjectHeaderImpl(false, false),
40 Unpooled.wrappedBuffer(BW_BYTES, 4, BW_BYTES.length - 4));
41 assertEquals(builder.build(), parsedObject);
43 final ByteBuf buffer = Unpooled.buffer(BW_BYTES.length);
44 codec.serializeObject(builder.build(), buffer);
45 assertArrayEquals(BW_BYTES, ByteArray.getAllBytes(buffer));