2 * Copyright (c) 2014 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.spi;
10 import static org.junit.Assert.assertEquals;
12 import com.google.common.collect.Lists;
13 import io.netty.buffer.ByteBuf;
14 import io.netty.buffer.Unpooled;
15 import java.util.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.mockito.Mockito;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfListBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.vendor.information.tlvs.VendorInformationTlv;
30 public class AbstractObjectWithTlvsTest {
35 private TlvRegistry tlvRegistry;
38 private VendorInformationTlvRegistry viTlvRegistry;
40 private class Abs extends AbstractObjectWithTlvsParser<TlvsBuilder> {
42 protected Abs(TlvRegistry tlvReg, VendorInformationTlvRegistry viTlvReg) {
43 super(tlvReg, viTlvReg);
47 public Object parseObject(ObjectHeader header, ByteBuf buffer) throws PCEPDeserializerException {
52 public void serializeObject(Object object, ByteBuf buffer) {
56 public void addTlv(final TlvsBuilder builder, final Tlv tlv) {
57 builder.setOfList((OfList) tlv);
61 protected void addVendorInformationTlvs(TlvsBuilder builder, List<VendorInformationTlv> tlvs) {
62 builder.setVendorInformationTlv(tlvs);
67 public void setUp() throws PCEPDeserializerException {
68 MockitoAnnotations.initMocks(this);
69 this.tlv = new OfListBuilder().setCodes(Lists.newArrayList(new OfId(10))).build();
70 Mockito.doNothing().when(this.tlvRegistry).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));
71 Mockito.doReturn(this.tlv).when(this.tlvRegistry).parseTlv(4, Unpooled.wrappedBuffer(new byte[] { 5, 6 }));
75 public void testParseTlvs() throws PCEPDeserializerException {
76 Abs a = new Abs(this.tlvRegistry, this.viTlvRegistry);
77 ByteBuf buffer = Unpooled.buffer();
78 a.serializeTlv(this.tlv, buffer);
80 Mockito.verify(this.tlvRegistry, Mockito.only()).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));;
82 TlvsBuilder b = new TlvsBuilder();
83 a.parseTlvs(b, Unpooled.wrappedBuffer(new byte[] { 0, 4, 0, 2, 5, 6, 0, 0 }));
85 assertEquals(this.tlv, b.getOfList());