eb1fa925a06df2b53e94294435232bc2f61c64be
[bgpcep.git] / bgp / openconfig-rp-statement / src / test / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / statement / MatchAfiSafiNotInTest.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.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
13
14 import java.util.List;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.mockito.Mock;
18 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
19 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
20 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
22 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
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.spec.common.As4SpecificCommonBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
30 import org.opendaylight.yangtools.yang.common.Uint16;
31
32 public class MatchAfiSafiNotInTest extends AbstractStatementRegistryConsumerTest {
33     @Mock
34     private BGPRouteEntryExportParameters exportParameters;
35     private List<Statement> basicStatements;
36     private PolicyRIBBaseParametersImpl baseAttributes;
37
38     @Before
39     @Override
40     public void setUp() throws Exception {
41         super.setUp();
42         basicStatements = loadStatement("match-afi-safi-not-in-test");
43         baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
44     }
45
46     @Test
47     public void testExtComAny() {
48         Statement statement = basicStatements.stream()
49                 .filter(st -> st.getName().equals("match-afi-safi-not-in-test")).findFirst().get();
50         RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
51                 new AttributesBuilder().build());
52         RouteAttributeContainer result = statementRegistry.applyExportStatement(
53                 baseAttributes, IPV4UNICAST.VALUE, exportParameters, attributeContainer, statement);
54         assertNotNull(result.getAttributes());
55
56
57         attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
58                 .setExtendedCommunities(List.of(new ExtendedCommunitiesBuilder()
59                         .setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder()
60                                 .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder()
61                                         .setAs4SpecificCommon(new As4SpecificCommonBuilder()
62                                                 .setAsNumber(AsNumber.getDefaultInstance("65000"))
63                                                 .setLocalAdministrator(Uint16.valueOf(123))
64                                                 .build()).build()).build()).build())).build());
65
66         result = statementRegistry.applyExportStatement(
67                 baseAttributes, IPV6UNICAST.VALUE, exportParameters, attributeContainer, statement);
68         assertNull(result.getAttributes());
69     }
70 }