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