b1fa49d8336fe835fad3448745dc6330b384f6b9
[bgpcep.git] / bgp / openconfig-rp-statement / src / test / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / statement / VpnNonMemberHandlerTest.java
1 /*
2  * Copyright (c) 2018 AT&T Intellectual Property. 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.openconfig.routing.policy.statement;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.mockito.Mockito.doReturn;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
14
15 import java.util.List;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.Mock;
19 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
20 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
21 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.AttributesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev200120.path.attributes.attributes.ExtendedCommunitiesBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.as._4.route.target.extended.community.grouping.As4RouteTargetExtendedCommunity;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.as._4.route.target.extended.community.grouping.As4RouteTargetExtendedCommunityBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.as._4.spec.common.As4SpecificCommon;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.as._4.spec.common.As4SpecificCommonBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.As4RouteTargetExtendedCommunityCaseBuilder;
32 import org.opendaylight.yangtools.yang.common.Uint16;
33 import org.opendaylight.yangtools.yang.common.Uint32;
34
35 public class VpnNonMemberHandlerTest extends AbstractStatementRegistryConsumerTest {
36     private static final As4SpecificCommon AS_COMMON = new As4SpecificCommonBuilder()
37             .setAsNumber(new AsNumber(Uint32.valueOf(20))).setLocalAdministrator(Uint16.valueOf(100)).build();
38
39     private static final As4RouteTargetExtendedCommunity RT = new As4RouteTargetExtendedCommunityBuilder()
40             .setAs4SpecificCommon(AS_COMMON).build();
41     @Mock
42     private BGPRouteEntryExportParameters exportParameters;
43     private List<Statement> basicStatements;
44     private PolicyRIBBaseParametersImpl baseAttributes;
45
46     @Before
47     @Override
48     public void setUp() throws Exception {
49         super.setUp();
50         basicStatements = loadStatement("vpn-non-member-test");
51         baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
52     }
53
54     @Test
55     public void testExtComAny() {
56         Statement statement = basicStatements.stream()
57                 .filter(st -> st.getName().equals("vpn-non-member-test")).findFirst().get();
58         RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
59                 new AttributesBuilder()
60                         .setExtendedCommunities(List.of(new ExtendedCommunitiesBuilder()
61                                 .setExtendedCommunity(new As4RouteTargetExtendedCommunityCaseBuilder()
62                                         .setAs4RouteTargetExtendedCommunity(RT).build()).build())).build());
63
64         doReturn(List.of(RT)).when(exportParameters).getMemberships();
65
66         RouteAttributeContainer result = statementRegistry.applyExportStatement(
67                 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
68         assertNotNull(result.getAttributes());
69
70         doReturn(List.of()).when(exportParameters).getMemberships();
71
72         result = statementRegistry.applyExportStatement(
73                 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
74         assertNull(result.getAttributes());
75     }
76 }