Migrate away from legacy setters
[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
9 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
10
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
14
15 import java.util.Collections;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.opendaylight.protocol.bgp.openconfig.routing.policy.impl.PolicyRIBBaseParametersImpl;
21 import org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer;
22 import org.opendaylight.protocol.bgp.rib.spi.policy.BGPRouteEntryExportParameters;
23 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV4UNICAST;
24 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.types.rev151009.IPV6UNICAST;
25 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.AsNumber;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.AttributesBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.attributes.ExtendedCommunitiesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.as._4.spec.common.As4SpecificCommonBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.As4RouteOriginExtendedCommunityCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev180329.extended.community.extended.community.as._4.route.origin.extended.community._case.As4RouteOriginExtendedCommunityBuilder;
32 import org.opendaylight.yangtools.yang.common.Uint16;
33
34 public class MatchAfiSafiNotInTest extends AbstractStatementRegistryConsumerTest {
35     @Mock
36     private BGPRouteEntryExportParameters exportParameters;
37     private List<Statement> basicStatements;
38     private PolicyRIBBaseParametersImpl baseAttributes;
39
40     @Before
41     @Override
42     public void setUp() throws Exception {
43         super.setUp();
44         this.basicStatements = loadStatement("match-afi-safi-not-in-test");
45         this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
46     }
47
48     @Test
49     public void testExtComAny() {
50         Statement statement = this.basicStatements.stream()
51                 .filter(st -> st.getName().equals("match-afi-safi-not-in-test")).findFirst().get();
52         RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
53                 new AttributesBuilder().build());
54         RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
55                 this.baseAttributes,
56                 IPV4UNICAST.class,
57                 this.exportParameters,
58                 attributeContainer,
59                 statement);
60         assertNotNull(result.getAttributes());
61
62
63         attributeContainer = routeAttributeContainerFalse(new AttributesBuilder()
64                 .setExtendedCommunities(Collections.singletonList(new ExtendedCommunitiesBuilder()
65                         .setExtendedCommunity(new As4RouteOriginExtendedCommunityCaseBuilder()
66                                 .setAs4RouteOriginExtendedCommunity(new As4RouteOriginExtendedCommunityBuilder()
67                                         .setAs4SpecificCommon(new As4SpecificCommonBuilder()
68                                                 .setAsNumber(AsNumber.getDefaultInstance("65000"))
69                                                 .setLocalAdministrator(Uint16.valueOf(123))
70                                                 .build()).build()).build()).build())).build());
71
72         result = this.statementRegistry.applyExportStatement(
73                 this.baseAttributes,
74                 IPV6UNICAST.class,
75                 this.exportParameters,
76                 attributeContainer,
77                 statement);
78         assertNull(result.getAttributes());
79     }
80 }