2 * Copyright (c) 2015 Cisco Systems, Inc. and others. 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.openflowplugin.applications.topology.manager;
10 import static org.mockito.ArgumentMatchers.any;
11 import static org.mockito.Mockito.doReturn;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.when;
15 import java.util.concurrent.ExecutorService;
16 import java.util.concurrent.Executors;
17 import org.junit.After;
18 import org.junit.Before;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.md.sal.binding.api.BindingTransactionChain;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
24 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification.ModificationType;
25 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
26 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
27 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
28 import org.opendaylight.controller.md.sal.common.api.data.TransactionChainListener;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.PortConfig;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.flow.capable.port.StateBuilder;
33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
34 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
37 import org.opendaylight.yangtools.yang.binding.DataObject;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 public abstract class DataTreeChangeListenerBase {
42 private OperationProcessor processor;
43 protected InstanceIdentifier<Topology> topologyIID;
44 protected TerminationPointChangeListenerImpl terminationPointListener;
45 protected NodeChangeListenerImpl nodeChangeListener;
46 private final ExecutorService executor = Executors.newFixedThreadPool(1);
48 private DataBroker mockDataBroker;
50 protected BindingTransactionChain mockTxChain;
54 MockitoAnnotations.initMocks(this);
56 doReturn(mockTxChain).when(mockDataBroker).createTransactionChain(any(TransactionChainListener.class));
58 processor = new OperationProcessor(mockDataBroker);
60 topologyIID = InstanceIdentifier.create(NetworkTopology.class)
61 .child(Topology.class, new TopologyKey(new TopologyId("flow:1")));
62 terminationPointListener = new TerminationPointChangeListenerImpl(mockDataBroker, processor);
63 nodeChangeListener = new NodeChangeListenerImpl(mockDataBroker, processor);
65 executor.execute(processor);
69 public void tearDown() {
70 executor.shutdownNow();
73 protected FlowCapableNodeConnector provideFlowCapableNodeConnector(final boolean isLinkDown,
74 final boolean isPortDown) {
75 FlowCapableNodeConnectorBuilder builder = new FlowCapableNodeConnectorBuilder();
76 builder.setState(new StateBuilder().setLinkDown(isLinkDown).build());
77 builder.setConfiguration(new PortConfig(true, true, true, isPortDown));
78 return builder.build();
81 protected <T extends DataObject> DataTreeModification setupDataTreeChange(final ModificationType type,
82 final InstanceIdentifier<T> ii) {
83 final DataTreeModification dataTreeModification = mock(DataTreeModification.class);
84 final DataTreeIdentifier identifier = new DataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, ii);
85 when(dataTreeModification.getRootNode()).thenReturn(mock(DataObjectModification.class));
86 when(dataTreeModification.getRootNode().getModificationType()).thenReturn(type);
87 when(dataTreeModification.getRootPath()).thenReturn(identifier);
88 when(dataTreeModification.getRootNode().getDataAfter()).thenReturn(mock(FlowCapableNodeConnector.class));
89 return dataTreeModification;