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
9 package org.opendaylight.protocol.bgp.parser.spi.pojo;
11 import com.google.common.collect.Lists;
12 import io.netty.buffer.ByteBuf;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.MockitoAnnotations;
18 import org.opendaylight.protocol.bgp.parser.BGPDocumentedException;
19 import org.opendaylight.protocol.bgp.parser.BGPParsingException;
20 import org.opendaylight.protocol.bgp.parser.spi.AbstractBGPExtensionProviderActivator;
21 import org.opendaylight.protocol.bgp.parser.spi.AttributeParser;
22 import org.opendaylight.protocol.bgp.parser.spi.AttributeSerializer;
23 import org.opendaylight.protocol.bgp.parser.spi.BGPExtensionProviderContext;
24 import org.opendaylight.protocol.bgp.parser.spi.CapabilityParser;
25 import org.opendaylight.protocol.bgp.parser.spi.CapabilitySerializer;
26 import org.opendaylight.protocol.bgp.parser.spi.MessageParser;
27 import org.opendaylight.protocol.bgp.parser.spi.MessageSerializer;
28 import org.opendaylight.protocol.bgp.parser.spi.NlriParser;
29 import org.opendaylight.protocol.bgp.parser.spi.NlriSerializer;
30 import org.opendaylight.protocol.bgp.parser.spi.ParameterParser;
31 import org.opendaylight.protocol.bgp.parser.spi.ParameterSerializer;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.BgpParameters;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.open.bgp.parameters.optional.capabilities.CParameters;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev130919.update.PathAttributesBuilder;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpReachNlriBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.update.path.attributes.MpUnreachNlriBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.UnicastSubsequentAddressFamily;
39 import org.opendaylight.yangtools.yang.binding.DataObject;
40 import org.opendaylight.yangtools.yang.binding.Notification;
42 public class BgpTestActivator extends AbstractBGPExtensionProviderActivator {
44 protected static final int TYPE = 0;
45 private static final String EMPTY = "";
48 protected AttributeSerializer attrSerializer;
50 protected AttributeParser attrParser;
53 protected ParameterParser paramParser;
55 protected ParameterSerializer paramSerializer;
58 protected CapabilityParser capaParser;
60 protected CapabilitySerializer capaSerializer;
63 protected MessageParser msgParser;
65 protected MessageSerializer msgSerializer;
68 protected NlriParser nlriParser;
70 protected NlriSerializer nlriSerializer;
73 protected List<AutoCloseable> startImpl(BGPExtensionProviderContext context) {
75 final List<AutoCloseable> regs = Lists.newArrayList();
76 regs.add(context.registerAttributeParser(TYPE, this.attrParser));
77 regs.add(context.registerAttributeSerializer(DataObject.class, this.attrSerializer));
79 regs.add(context.registerParameterParser(TYPE, this.paramParser));
80 regs.add(context.registerParameterSerializer(BgpParameters.class, this.paramSerializer));
82 regs.add(context.registerCapabilityParser(TYPE, this.capaParser));
83 regs.add(context.registerCapabilitySerializer(CParameters.class, this.capaSerializer));
85 regs.add(context.registerMessageParser(TYPE, this.msgParser));
86 regs.add(context.registerMessageSerializer(Notification.class, this.msgSerializer));
88 regs.add(context.registerAddressFamily(Ipv4AddressFamily.class, 1));
89 regs.add(context.registerSubsequentAddressFamily(UnicastSubsequentAddressFamily.class, 1));
91 regs.add(context.registerNlriParser(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class, this.nlriParser));
92 regs.add(context.registerNlriSerializer(DataObject.class, this.nlriSerializer));
97 private void initMock() {
98 MockitoAnnotations.initMocks(this);
100 Mockito.doNothing().when(this.attrParser).parseAttribute(Mockito.any(ByteBuf.class), Mockito.any(PathAttributesBuilder.class));
101 Mockito.doReturn(EMPTY).when(this.attrParser).toString();
102 Mockito.doNothing().when(this.attrSerializer).serializeAttribute(Mockito.any(DataObject.class), Mockito.any(ByteBuf.class));
103 Mockito.doReturn(EMPTY).when(this.attrSerializer).toString();
105 Mockito.doReturn(null).when(this.paramParser).parseParameter(Mockito.any(ByteBuf.class));
106 Mockito.doReturn(EMPTY).when(this.paramParser).toString();
107 Mockito.doNothing().when(this.paramSerializer).serializeParameter(Mockito.any(BgpParameters.class), Mockito.any(ByteBuf.class));
108 Mockito.doReturn(EMPTY).when(this.paramSerializer).toString();
110 Mockito.doReturn(null).when(this.capaParser).parseCapability(Mockito.any(ByteBuf.class));
111 Mockito.doReturn(EMPTY).when(this.capaParser).toString();
112 Mockito.doNothing().when(this.capaSerializer).serializeCapability(Mockito.any(CParameters.class), Mockito.any(ByteBuf.class));
113 Mockito.doReturn(EMPTY).when(this.capaSerializer).toString();
115 Mockito.doReturn(Mockito.mock(Notification.class)).when(this.msgParser).parseMessageBody(Mockito.any(ByteBuf.class), Mockito.anyInt());
116 Mockito.doReturn(EMPTY).when(this.msgParser).toString();
117 Mockito.doNothing().when(this.msgSerializer).serializeMessage(Mockito.any(Notification.class), Mockito.any(ByteBuf.class));
118 Mockito.doReturn(EMPTY).when(this.msgSerializer).toString();
120 Mockito.doNothing().when(this.nlriParser).parseNlri(Mockito.any(ByteBuf.class), Mockito.any(MpUnreachNlriBuilder.class));
121 Mockito.doNothing().when(this.nlriParser).parseNlri(Mockito.any(ByteBuf.class), Mockito.any(MpReachNlriBuilder.class));
122 Mockito.doReturn(EMPTY).when(this.nlriParser).toString();
123 } catch (BGPDocumentedException | BGPParsingException e) {