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.bgp.parser.impl.message.update;
10 import static org.junit.Assert.assertEquals;
11 import io.netty.buffer.ByteBuf;
12 import io.netty.buffer.Unpooled;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mockito;
16 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
17 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
18 import org.opendaylight.protocol.bgp.parser.spi.BgpPrefixSidTlvRegistry;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv;
22 public final class BgpPrefixSidAttributeParserTest {
24 private final BgpPrefixSidTlvRegistry reg = Mockito.mock(BgpPrefixSidTlvRegistry.class);
25 private final BgpPrefixSidTlv tlv = Mockito.mock(BgpPrefixSidTlv.class);
26 private final BgpPrefixSidAttributeParser parser = new BgpPrefixSidAttributeParser(this.reg);
27 private final byte[] bytes = new byte[] {1, 2, 3};
31 Mockito.doReturn(this.tlv).when(this.reg).parseBgpPrefixSidTlv(Mockito.anyInt(), Mockito.any(ByteBuf.class));
32 Mockito.doNothing().when(this.reg).serializeBgpPrefixSidTlv(Mockito.any(BgpPrefixSidTlv.class), Mockito.any(ByteBuf.class));
36 public void testHandling() throws BGPDocumentedException, BGPParsingException {
37 final AttributesBuilder builder = new AttributesBuilder();
38 this.parser.parseAttribute(Unpooled.copiedBuffer(this.bytes), builder);
39 assertEquals(3, builder.getBgpPrefixSid().getBgpPrefixSidTlvs().size());
41 this.parser.serializeAttribute(builder.build(), Unpooled.EMPTY_BUFFER);
42 Mockito.verify(this.reg, Mockito.times(3)).serializeBgpPrefixSidTlv(Mockito.any(BgpPrefixSidTlv.class), Mockito.any(ByteBuf.class));