MVPN RFC6514 Extendend communities
[bgpcep.git] / bgp / parser-spi / src / test / java / org / opendaylight / protocol / bgp / parser / spi / MultiPathSupportUtilTest.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
9 package org.opendaylight.protocol.bgp.parser.spi;
10
11 import java.util.Optional;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.Mock;
16 import org.mockito.Mockito;
17 import org.mockito.MockitoAnnotations;
18 import org.opendaylight.protocol.bgp.parser.BgpTableTypeImpl;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev180329.BgpTableType;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.Ipv4AddressFamily;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.UnicastSubsequentAddressFamily;
22
23 public class MultiPathSupportUtilTest {
24
25     private static final BgpTableType AFI_SAFI = new BgpTableTypeImpl(Ipv4AddressFamily.class, UnicastSubsequentAddressFamily.class);
26
27     @Mock
28     private PeerSpecificParserConstraint constraints;
29
30     @Mock
31     private MultiPathSupport mpSupport;
32
33     @Before
34     public void setUp() {
35         MockitoAnnotations.initMocks(this);
36     }
37
38     @Test
39     public void testIsTableTypeSupportedPossitive() {
40         Mockito.doReturn(Optional.of(this.mpSupport)).when(this.constraints).getPeerConstraint(Mockito.any());
41         Mockito.doReturn(true).when(this.mpSupport).isTableTypeSupported(Mockito.any());
42         Assert.assertTrue(MultiPathSupportUtil.isTableTypeSupported(this.constraints, AFI_SAFI));
43     }
44
45     @Test
46     public void testIsTableTypeSupportedNegativeTableTypeNotSupported() {
47         Mockito.doReturn(Optional.of(this.mpSupport)).when(this.constraints).getPeerConstraint(Mockito.any());
48         Mockito.doReturn(false).when(this.mpSupport).isTableTypeSupported(Mockito.any());
49         Assert.assertFalse(MultiPathSupportUtil.isTableTypeSupported(this.constraints, AFI_SAFI));
50     }
51
52     @Test
53     public void testIsTableTypeSupportedNegativeMpSupportAbsent() {
54         Mockito.doReturn(Optional.empty()).when(this.constraints).getPeerConstraint(Mockito.any());
55         Assert.assertFalse(MultiPathSupportUtil.isTableTypeSupported(this.constraints, AFI_SAFI));
56     }
57
58     @Test
59     public void testIsTableTypeSupportedNegativeNull() {
60         Assert.assertFalse(MultiPathSupportUtil.isTableTypeSupported(null, AFI_SAFI));
61     }
62
63     @Test(expected=NullPointerException.class)
64     public void testIsTableTypeSupportedNPE() {
65         MultiPathSupportUtil.isTableTypeSupported(null, null);
66     }
67
68 }