2 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
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
8 package org.opendaylight.protocol.bgp.openconfig.routing.policy.statement;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12 import static org.opendaylight.protocol.bgp.openconfig.routing.policy.spi.registry.RouteAttributeContainer.routeAttributeContainerFalse;
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.BGPRouteEntryImportParameters;
21 import org.opendaylight.yang.gen.v1.http.openconfig.net.yang.routing.policy.rev151009.routing.policy.top.routing.policy.policy.definitions.policy.definition.statements.Statement;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.message.rev171207.path.attributes.Attributes;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev171207.PeerRole;
25 public class ImportDefaultStatementTest extends AbstractStatementRegistryConsumerTest {
27 private BGPRouteEntryImportParameters importParameters;
28 private List<Statement> defaultImportStatements;
29 private PolicyRIBBaseParametersImpl baseAttributes;
33 public void setUp() throws Exception {
35 this.defaultImportStatements = loadStatement("default-odl-import-policy");
36 this.baseAttributes = new PolicyRIBBaseParametersImpl(LOCAL_AS, IPV4, CLUSTER);
40 public void testFromEbgp() {
41 final Statement statement = getStatement("from-external");
43 final RouteAttributeContainer attributeContainer
44 = routeAttributeContainerFalse(ImportAttributeTestUtil.createInput());
46 assertApplyImportStatement(statement, PeerRole.Ebgp, attributeContainer,
47 ImportAttributeTestUtil.createOutput());
51 public void testFromNonExternal() {
52 final Statement statement = getStatement("from-non-external");
54 final Attributes expected = ImportAttributeTestUtil.createInput();
55 final RouteAttributeContainer attributeContainer
56 = routeAttributeContainerFalse(expected);
58 assertApplyImportStatement(statement, PeerRole.Ibgp, attributeContainer, expected);
59 assertApplyImportStatement(statement, PeerRole.RrClient, attributeContainer, expected);
60 assertApplyImportStatement(statement, PeerRole.Internal, attributeContainer, expected);
63 private Statement getStatement(final String statementName) {
64 return this.defaultImportStatements.stream()
65 .filter(st -> st.getName().equals(statementName)).findFirst().get();
68 private void assertApplyImportStatement(
69 final Statement statement,
70 final PeerRole fromPeerRole,
71 final RouteAttributeContainer attInput,
72 final Attributes attExpected) {
74 doReturn(fromPeerRole).when(this.importParameters).getFromPeerRole();
76 RouteAttributeContainer result = this.statementRegistry.applyImportStatement(
78 this.importParameters,
81 assertEquals(attExpected, result.getAttributes());