1 /*******************************************************************************
2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk feature sdnr wt sdnr-wt-devicemanager-provider
4 * ================================================================================
5 * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
20 ******************************************************************************/
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test.mock;
24 import java.util.Optional;
25 import org.opendaylight.mdsal.binding.api.BindingService;
26 import org.opendaylight.mdsal.binding.api.MountPoint;
27 import org.opendaylight.mdsal.binding.api.NotificationService;
28 import org.opendaylight.mdsal.binding.api.ReadTransaction;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.network.topology.topology.topology.types.TopologyNetconf;
30 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NetworkTopology;
31 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.TopologyId;
32 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.Topology;
33 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.TopologyKey;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 @SuppressWarnings("deprecation")
41 public class MountPointMock implements MountPoint {
43 private boolean databrokerAbsent = true;
44 private final DataBrokerMountpointMock dataBroker = new DataBrokerMountpointMock();
45 private final RpcConsumerRegistryMock rpcConsumerRegistry = new RpcConsumerRegistryMock();
46 private NotificationService setReadOnlyTransaction;
48 private static final InstanceIdentifier<Topology> NETCONF_TOPO_IID =
49 InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
50 new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())));
53 public InstanceIdentifier<?> getIdentifier() {
54 return NETCONF_TOPO_IID;
57 @SuppressWarnings("unchecked")
59 public <T extends BindingService> Optional<T> getService(Class<T> service) {
61 System.out.println("Requested mountpoint service: "+service.getSimpleName()+" databrokerAbsent state: "+databrokerAbsent);
64 if (service.isInstance(dataBroker)) {
65 System.out.println("Delivering databroker");
66 res = databrokerAbsent ? Optional.empty() : Optional.of(dataBroker);
67 } else if (service.isInstance(rpcConsumerRegistry)) {
68 System.out.println("Delivering RpcConsumerRegistryMock");
69 res = Optional.of(rpcConsumerRegistry);
70 } else if (service.isInstance(setReadOnlyTransaction)) {
71 System.out.println("Delivering notificationService");
72 res = Optional.of(setReadOnlyTransaction);
74 System.out.println("Delivering no service");
75 res = Optional.empty();
77 return (Optional<T>)res;
80 public void setDatabrokerAbsent( boolean state) {
81 this.databrokerAbsent = state;
84 public <T extends NotificationService&ReadTransaction>void setReadOnlyTransaction(T readOnlyTransaction) {
85 this.setReadOnlyTransaction = readOnlyTransaction;
86 dataBroker.setReadOnlyTransaction(readOnlyTransaction);