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 org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.mockito.Mockito;
19 import org.mockito.MockitoAnnotations;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.ObjectHeader;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.OfId;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Tlv;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfList;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.of.list.tlv.OfListBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.open.object.open.TlvsBuilder;
28 public class AbstractObjectWithTlvsTest {
33 private TlvRegistry tlvRegistry;
35 private class Abs extends AbstractObjectWithTlvsParser<TlvsBuilder> {
37 protected Abs(TlvRegistry tlvReg) {
42 public Object parseObject(ObjectHeader header, ByteBuf buffer) throws PCEPDeserializerException {
47 public void serializeObject(Object object, ByteBuf buffer) {
51 public void addTlv(final TlvsBuilder builder, final Tlv tlv) {
52 builder.setOfList((OfList) tlv);
57 public void setUp() throws PCEPDeserializerException {
58 MockitoAnnotations.initMocks(this);
59 this.tlv = new OfListBuilder().setCodes(Lists.newArrayList(new OfId(10))).build();
60 Mockito.doNothing().when(this.tlvRegistry).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));
61 Mockito.doReturn(this.tlv).when(this.tlvRegistry).parseTlv(4, Unpooled.wrappedBuffer(new byte[] { 5, 6 }));
65 public void testParseTlvs() throws PCEPDeserializerException {
66 Abs a = new Abs(this.tlvRegistry);
67 ByteBuf buffer = Unpooled.buffer();
68 a.serializeTlv(this.tlv, buffer);
70 Mockito.verify(this.tlvRegistry, Mockito.only()).serializeTlv(Mockito.any(Tlv.class), Mockito.any(ByteBuf.class));;
72 TlvsBuilder b = new TlvsBuilder();
73 a.parseTlvs(b, Unpooled.wrappedBuffer(new byte[] { 0, 4, 0, 2, 5, 6, 0, 0 }));
75 assertEquals(this.tlv, b.getOfList());