<groupId>org.opendaylight.yangtools</groupId>
<artifactId>mockito-configuration</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-manager</artifactId>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>config-manager</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>sal-dom-broker-config</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.openconfig.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.opendaylight.protocol.bgp.openconfig.impl.util.GlobalIdentifier;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.bgp.openconfig.rev150718.OpenconfigBgp;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+public class BGPConfigHolderImplTest {
+ private static final BGPConfigHolderImpl<DataObject> HOLDER = new BGPConfigHolderImpl<DataObject>();
+
+ @Test
+ public void test() {
+ assertNull(HOLDER.getModuleKey(GlobalIdentifier.GLOBAL_IDENTIFIER));
+
+ final ModuleKey moduleKey = new ModuleKey("key1", OpenconfigBgp.class);
+ final ModuleKey moduleKey2 = new ModuleKey("key2", OpenconfigBgp.class);
+ assertNull(HOLDER.getKey(moduleKey));
+
+ final MyDataObject obj1 = new MyDataObject();
+ final MyDataObject obj2 = new MyDataObject();
+ assertTrue(HOLDER.addOrUpdate(moduleKey, GlobalIdentifier.GLOBAL_IDENTIFIER, obj1));
+ assertFalse(HOLDER.addOrUpdate(moduleKey, GlobalIdentifier.GLOBAL_IDENTIFIER, obj1));
+ assertEquals(moduleKey, HOLDER.getModuleKey(GlobalIdentifier.GLOBAL_IDENTIFIER));
+ assertEquals(GlobalIdentifier.GLOBAL_IDENTIFIER, HOLDER.getKey(moduleKey));
+ assertTrue(HOLDER.addOrUpdate(moduleKey, GlobalIdentifier.GLOBAL_IDENTIFIER, obj2));
+ assertFalse(HOLDER.addOrUpdate(moduleKey, GlobalIdentifier.GLOBAL_IDENTIFIER, obj2));
+ assertTrue(HOLDER.remove(moduleKey));
+ assertFalse(HOLDER.remove(moduleKey2));
+ assertTrue(HOLDER.addOrUpdate(moduleKey, GlobalIdentifier.GLOBAL_IDENTIFIER, obj2));
+ }
+
+ private class MyDataObject implements DataObject {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return null;
+ }
+ }
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.openconfig.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.binding.DataContainer;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+public class BGPConfigStateStoreImplTest {
+
+ private static final BGPConfigStateStoreImpl STORE = new BGPConfigStateStoreImpl();
+ private static final BGPConfigHolderImpl<MyDataObject> HOLDER = new BGPConfigHolderImpl<MyDataObject>();
+
+ @Test
+ public void test() {
+ assertNull(STORE.getBGPConfigHolder(MyDataObject.class));
+ STORE.registerBGPConfigHolder(MyDataObject.class, HOLDER);
+ assertEquals(HOLDER, STORE.getBGPConfigHolder(MyDataObject.class));
+ }
+
+ private class MyDataObject implements DataObject {
+ @Override
+ public Class<? extends DataContainer> getImplementedInterface() {
+ return null;
+ }
+ }
+
+}
--- /dev/null
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.protocol.bgp.openconfig.impl.openconfig;
+
+import static org.junit.Assert.assertTrue;
+import com.google.common.util.concurrent.CheckedFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
+import org.opendaylight.controller.md.sal.binding.impl.BindingDOMDataBrokerAdapter;
+import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
+import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigHolder;
+import org.opendaylight.protocol.bgp.openconfig.impl.spi.BGPConfigStateStore;
+import org.opendaylight.protocol.bgp.openconfig.spi.pojo.BGPAppPeerInstanceConfiguration;
+import org.opendaylight.protocol.bgp.openconfig.spi.pojo.BGPPeerInstanceConfiguration;
+import org.opendaylight.protocol.bgp.openconfig.spi.pojo.BGPRibInstanceConfiguration;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+
+public class BGPConfigModuleMapperProviderTest {
+
+ private BGPConfigModuleMapperProvider mapperProvider;
+
+ private final BindingTransactionChain txChain = Mockito.mock(BindingTransactionChain.class);
+ private final AsyncTransaction<?, ?> asyncTx = Mockito.mock(AsyncTransaction.class);
+ private final WriteTransaction myTx = Mockito.mock(WriteTransaction.class);
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void setUp() throws Exception {
+
+ final BindingDOMDataBrokerAdapter dataBroker = Mockito.mock(BindingDOMDataBrokerAdapter.class);
+ final BGPConfigStateStore stateHolders = Mockito.mock(BGPConfigStateStore.class);
+ final CheckedFuture<?, ?> checkedFuture = Mockito.mock(CheckedFuture.class);
+ final BGPConfigHolder<?> confHolder = Mockito.mock(BGPConfigHolder.class);
+
+ Mockito.doReturn(this.txChain).when(dataBroker).createTransactionChain(Mockito.any(TransactionChainListener.class));
+ Mockito.doReturn(this.myTx).when(this.txChain).newWriteOnlyTransaction();
+ Mockito.doNothing().when(this.txChain).close();
+ Mockito.doNothing().when(this.myTx).put(Mockito.any(LogicalDatastoreType.class), Mockito.any(InstanceIdentifier.class), Mockito.any(DataObject.class));
+ Mockito.doNothing().when(this.myTx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(InstanceIdentifier.class));
+ Mockito.doReturn(checkedFuture).when(this.myTx).submit();
+ Mockito.doReturn(null).when(checkedFuture).checkedGet();
+ Mockito.doReturn(confHolder).when(stateHolders).getBGPConfigHolder(Mockito.any(Class.class));
+
+ this.mapperProvider = new BGPConfigModuleMapperProvider(dataBroker, stateHolders);
+ }
+
+ @Test
+ public void testGetOpenConfigMapper() {
+ assertTrue(this.mapperProvider.getOpenConfigMapper(BGPRibInstanceConfiguration.class) instanceof BGPGlobalProviderImpl);
+ assertTrue(this.mapperProvider.getOpenConfigMapper(BGPPeerInstanceConfiguration.class) instanceof BGPNeighborProviderImpl);
+ assertTrue(this.mapperProvider.getOpenConfigMapper(BGPAppPeerInstanceConfiguration.class) instanceof BGPAppNeighborProviderImpl);
+ }
+
+ @Test
+ public void testOnTransactionChainFailed() {
+ this.mapperProvider.onTransactionChainFailed(this.txChain, this.asyncTx, new Throwable());
+ Mockito.verify(this.txChain).close();
+ }
+
+ @Test
+ public void testClose() throws Exception {
+ this.mapperProvider.close();
+ Mockito.verify(this.myTx).delete(Mockito.any(LogicalDatastoreType.class), Mockito.any(InstanceIdentifier.class));
+ Mockito.verify(this.myTx, Mockito.times(2)).submit();
+ Mockito.verify(this.txChain).close();
+ }
+
+}
final BGPConfigStateStore stateHolders = Mockito.mock(BGPConfigStateStore.class);
final BGPConfigHolder<Global> configHolder = Mockito.mock(BGPConfigHolder.class);
Mockito.doReturn(configHolder).when(stateHolders).getBGPConfigHolder(Mockito.any(Class.class));
- globalProvider = new BGPGlobalProviderImpl(txChain, stateHolders);
+ this.globalProvider = new BGPGlobalProviderImpl(txChain, stateHolders);
}
@Test
public void testCreateModuleKey() {
- assertEquals(new ModuleKey("instanceName", RibImpl.class), globalProvider.createModuleKey("instanceName"));
+ assertEquals(new ModuleKey("instanceName", RibImpl.class), this.globalProvider.createModuleKey("instanceName"));
}
@Test
public void testApply() {
- final Global global = globalProvider.apply(new BGPRibInstanceConfiguration(new InstanceConfigurationIdentifier("instanceName"), new AsNumber(1L),
+ final Global global = this.globalProvider.apply(new BGPRibInstanceConfiguration(new InstanceConfigurationIdentifier("instanceName"), new AsNumber(1L),
new Ipv4Address("1.2.3.4"), null,
Lists.<BgpTableType>newArrayList(new BgpTableTypeImpl(LinkstateAddressFamily.class, LinkstateSubsequentAddressFamily.class))));
final Global expectedGlobal = new GlobalBuilder()
@Test
public void testKeyForConfigurationGlobal() {
- assertEquals(GlobalIdentifier.GLOBAL_IDENTIFIER, globalProvider.keyForConfiguration(new GlobalBuilder().build()));
+ final GlobalIdentifier globalId = (GlobalIdentifier) this.globalProvider.keyForConfiguration(new GlobalBuilder().build());
+ assertEquals(GlobalIdentifier.GLOBAL_IDENTIFIER, globalId);
+ assertEquals("GLOBAL", globalId.getName());
}
@Test
public void testGetInstanceConfigurationType() {
- assertEquals(BGPRibInstanceConfiguration.class, globalProvider.getInstanceConfigurationType());
+ assertEquals(BGPRibInstanceConfiguration.class, this.globalProvider.getInstanceConfigurationType());
}
}
import com.google.common.base.Optional;
import com.google.common.collect.Lists;
import java.math.BigDecimal;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715.PortNumber;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.flowspec.rev150807.FlowspecSubsequentAddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.multiprotocol.rev130919.BgpTableType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev150930.Ipv4Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.openconfig.extensions.rev150930.Ipv6Flow;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev130925.PeerRole;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv4AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev130919.Ipv6AddressFamily;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.bgp.rib.impl.rev130409.BgpPeer;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.rev130405.modules.ModuleKey;
public class BGPNeighborProviderImplTest {
private BGPNeighborProviderImpl neighborProvider;
+ private static final String PASSWORD = "Ug1Yp4Ssw0Rd";
+ private static final IpAddress IP = new IpAddress(new Ipv4Address("1.2.3.4"));
+ private static final PortNumber PORT = new PortNumber(123);
+ private static final short TIMER = (short) 10;
+ private static final AsNumber AS = new AsNumber(10L);
@SuppressWarnings("unchecked")
@Before
final BGPConfigStateStore stateHolders = Mockito.mock(BGPConfigStateStore.class);
final BGPConfigHolder<Neighbor> configHolder = Mockito.mock(BGPConfigHolder.class);
Mockito.doReturn(configHolder).when(stateHolders).getBGPConfigHolder(Mockito.any(Class.class));
- neighborProvider = new BGPNeighborProviderImpl(txChain, stateHolders);
+ this.neighborProvider = new BGPNeighborProviderImpl(txChain, stateHolders);
}
@Test
public void testCreateModuleKey() {
- assertEquals(new ModuleKey("instanceName", BgpPeer.class), neighborProvider.createModuleKey("instanceName"));
+ assertEquals(new ModuleKey("instanceName", BgpPeer.class), this.neighborProvider.createModuleKey("instanceName"));
}
@Test
public void testGetInstanceConfigurationType() {
- assertEquals(BGPPeerInstanceConfiguration.class, neighborProvider.getInstanceConfigurationType());
+ assertEquals(BGPPeerInstanceConfiguration.class, this.neighborProvider.getInstanceConfigurationType());
}
@Test
public void testApply() {
- final Neighbor neighbor = neighborProvider.apply(new BGPPeerInstanceConfiguration(new InstanceConfigurationIdentifier("instanceName"),
- new IpAddress(new Ipv4Address("1.2.3.4")), new PortNumber(123), (short) 10, PeerRole.RrClient, false,
- Lists.<BgpTableType>newArrayList(new BgpTableTypeImpl(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class)),
- new AsNumber(10L), Optional.<Rfc2385Key>absent()));
- final Neighbor expectedNeighbor = new NeighborBuilder()
- .setAfiSafis(new AfiSafisBuilder().setAfiSafi(Lists.<AfiSafi>newArrayList(new AfiSafiBuilder().setAfiSafiName(Ipv6Flow.class).build())).build())
- .setNeighborAddress(new IpAddress(new Ipv4Address("1.2.3.4")))
- .setKey(new NeighborKey(new IpAddress(new Ipv4Address("1.2.3.4"))))
- .setConfig(new ConfigBuilder().setPeerAs(new AsNumber(10L)).setPeerType(PeerType.INTERNAL).build())
- .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(true).build()).build())
- .setTimers(new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder().setHoldTime(BigDecimal.valueOf(10)).build()).build())
- .setTransport(new TransportBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.transport.ConfigBuilder().setPassiveMode(true).build()).build())
- .build();
+ final boolean active = false;
+ final PeerRole role = PeerRole.RrClient;
+ final Neighbor neighbor = this.neighborProvider.apply(createConfiguration(new InstanceConfigurationIdentifier("instanceName"),
+ IP, PORT, TIMER, role, active,
+ Lists.<BgpTableType>newArrayList(new BgpTableTypeImpl(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class)),
+ AS, Optional.<Rfc2385Key>absent()));
+ final Neighbor expectedNeighbor = createNeighbor(Lists.<AfiSafi>newArrayList(new AfiSafiBuilder().setAfiSafiName(Ipv6Flow.class).build()),
+ IP, null, AS, PeerType.INTERNAL, role, TIMER, !active);
assertEquals(expectedNeighbor, neighbor);
}
+ @Test
+ public void testApply2() {
+ final boolean active = false;
+ final PeerRole role = PeerRole.Ebgp;
+ final Neighbor neighbor = this.neighborProvider.apply(createConfiguration(new InstanceConfigurationIdentifier("instanceName"),
+ IP, PORT, TIMER, role, active,
+ Lists.<BgpTableType>newArrayList(new BgpTableTypeImpl(Ipv6AddressFamily.class, FlowspecSubsequentAddressFamily.class)),
+ AS, Optional.of(new Rfc2385Key(PASSWORD)) ));
+ final Neighbor expectedNeighbor = createNeighbor(Lists.<AfiSafi>newArrayList(new AfiSafiBuilder().setAfiSafiName(Ipv6Flow.class).build()),
+ IP, PASSWORD, AS, PeerType.EXTERNAL, role, TIMER, !active);
+ assertEquals(expectedNeighbor, neighbor);
+ }
+
+ @Test
+ public void testApply3() {
+ final boolean active = true;
+ final PeerRole role = PeerRole.Internal;
+ final Neighbor neighbor = this.neighborProvider.apply(createConfiguration(new InstanceConfigurationIdentifier("instanceName"),
+ IP, PORT, TIMER, role, active,
+ Lists.<BgpTableType>newArrayList(new BgpTableTypeImpl(Ipv4AddressFamily.class, FlowspecSubsequentAddressFamily.class)),
+ AS, Optional.of(new Rfc2385Key(PASSWORD)) ));
+ final Neighbor expectedNeighbor = createNeighbor(Lists.<AfiSafi>newArrayList(new AfiSafiBuilder().setAfiSafiName(Ipv4Flow.class).build()),
+ IP, PASSWORD, AS, null, role, TIMER, !active);
+ assertEquals(expectedNeighbor, neighbor);
+ }
+
+ private BGPPeerInstanceConfiguration createConfiguration(final InstanceConfigurationIdentifier confId, final IpAddress ip, final PortNumber port,
+ final short holdTimer, final PeerRole role, final boolean active, final List<BgpTableType> advertized, final AsNumber as, final Optional<Rfc2385Key> passwd) {
+ return new BGPPeerInstanceConfiguration(confId, ip, port, holdTimer, role, active, advertized, as, passwd);
+ }
+
+ private Neighbor createNeighbor(final List<AfiSafi> families, final IpAddress ip, final String passwd, final AsNumber as, final PeerType peerType, final PeerRole role, final short timer, final boolean passive) {
+ return new NeighborBuilder()
+ .setAfiSafis(new AfiSafisBuilder().setAfiSafi(families).build())
+ .setNeighborAddress(ip)
+ .setKey(new NeighborKey(ip))
+ .setConfig(new ConfigBuilder().setAuthPassword(passwd).setPeerAs(as).setPeerType(peerType).build())
+ .setRouteReflector(new RouteReflectorBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.route.reflector.ConfigBuilder().setRouteReflectorClient(role == PeerRole.RrClient).build()).build())
+ .setTimers(new TimersBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.timers.ConfigBuilder().setHoldTime(BigDecimal.valueOf(timer)).build()).build())
+ .setTransport(new TransportBuilder().setConfig(new org.opendaylight.yang.gen.v1.http.openconfig.net.yang.bgp.rev151009.bgp.neighbor.group.transport.ConfigBuilder().setPassiveMode(passive).build()).build())
+ .build();
+ }
}