b103df57bb9ff9428b803b6763f1262fce123abc
[bgpcep.git] / pcep / auto-bandwidth-extension / src / test / java / org / opendaylight / protocol / pcep / auto / bandwidth / extension / PCEPBandwidthUsageObjectCodecTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.protocol.pcep.auto.bandwidth.extension;
10
11 import static org.junit.Assert.assertArrayEquals;
12 import static org.junit.Assert.assertEquals;
13
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.rev181109.bandwidth.usage.object.BandwidthUsage;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.pcep.auto.bandwidth.rev181109.bandwidth.usage.object.BandwidthUsageBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.network.concepts.rev131125.Bandwidth;
24
25 public class PCEPBandwidthUsageObjectCodecTest {
26
27     private static final byte[] BW_BYTES = new byte[]{0x05, 0x50, 0x00, 0x0C, 0x00, 0x00, 0x10, 0x00,
28         0x00, 0x00, 0x40, 0x00};
29
30     @Test
31     public void testCodec() throws PCEPDeserializerException {
32         final BandwidthUsageObjectCodec codec = new BandwidthUsageObjectCodec(5);
33         assertEquals(5, codec.getObjectType());
34
35         final BandwidthUsageBuilder builder = new BandwidthUsageBuilder();
36         builder.setBwSample(Lists.newArrayList(new Bandwidth(new byte[]{0x00, 0x00, 0x10, 0x00}),
37                 new Bandwidth(new byte[]{0x00, 0x00, 0x40, 0x00})));
38         builder.setIgnore(false);
39         builder.setProcessingRule(false);
40         final BandwidthUsage parsedObject = codec.parseObject(new ObjectHeaderImpl(false, false),
41                 Unpooled.wrappedBuffer(BW_BYTES, 4, BW_BYTES.length - 4));
42         assertEquals(builder.build(), parsedObject);
43
44         final ByteBuf buffer = Unpooled.buffer(BW_BYTES.length);
45         codec.serializeObject(builder.build(), buffer);
46         assertArrayEquals(BW_BYTES, ByteArray.getAllBytes(buffer));
47     }
48
49 }