4d381bb9c93186ede6669d013816c7a0896c6604
[bgpcep.git] / bgp / parser-impl / src / test / java / org / opendaylight / protocol / bgp / parser / impl / message / update / BgpPrefixSidAttributeParserTest.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 package org.opendaylight.protocol.bgp.parser.impl.message.update;
9
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.rev171207.path.attributes.AttributesBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.attributes.bgp.prefix.sid.bgp.prefix.sid.tlvs.BgpPrefixSidTlv;
21
22 public final class BgpPrefixSidAttributeParserTest {
23
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};
28
29     @Before
30     public void setUp() {
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));
33     }
34
35     @Test
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());
40
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));
43     }
44 }