Route Constrain policies
[bgpcep.git] / bgp / openconfig-rp-statement / src / test / java / org / opendaylight / protocol / bgp / openconfig / routing / policy / statement / SetOriginatorIdToAdvertizerRouterIdHandlerTest.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.assertEquals;
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.RouterIds;
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.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.Ipv4Address;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev180329.path.attributes.Attributes;
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.OriginatorIdBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.PeerRole;
30
31 public class SetOriginatorIdToAdvertizerRouterIdHandlerTest extends AbstractStatementRegistryConsumerTest {
32     private Ipv4Address ipv4 = Ipv4Address.getDefaultInstance("42.42.42.42");
33     private final Attributes multipleCom = new AttributesBuilder()
34             .setOriginatorId(new OriginatorIdBuilder().setOriginator(ipv4).build())
35             .build();
36     @Mock
37     private BGPRouteEntryExportParameters exportParameters;
38     private List<Statement> basicStatements;
39     private PolicyRIBBaseParametersImpl baseAttributes;
40
41     @Before
42     @Override
43     public void setUp() throws Exception {
44         super.setUp();
45         this.basicStatements = loadStatement("set-originator-id-to-advertizer-router-id");
46         this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
47         doReturn(PeerRole.Ibgp).when(this.exportParameters).getFromPeerRole();
48         doReturn(RouterIds.createPeerId(ipv4)).when(this.exportParameters).getFromPeerId();
49     }
50
51     @Test
52     public void testInlineAdd() {
53         Statement statement = this.basicStatements.stream()
54                 .filter(st -> st.getName().equals("set-originator-id-to-advertizer-router-id")).findFirst().get();
55         RouteAttributeContainer attributeContainer = routeAttributeContainerFalse(
56                 new AttributesBuilder().build());
57         RouteAttributeContainer result = this.statementRegistry.applyExportStatement(
58                 this.baseAttributes,
59                 IPV4UNICAST.class,
60                 this.exportParameters,
61                 attributeContainer,
62                 statement);
63
64         assertEquals(this.multipleCom, result.getAttributes());
65     }
66 }