ORAN A1 Adapter YANG Model Update
[ccsdk/features.git] / sdnr / wt / netconfnode-state-service / provider / src / test / java / org / onap / ccsdk / features / sdnr / wt / netconfnodestateservice / test / mock / MountPointMock.java
1 /*******************************************************************************
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk feature sdnr wt sdnr-wt-devicemanager-provider
4  *  ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
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
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
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  ******************************************************************************/
21
22 package org.onap.ccsdk.features.sdnr.wt.netconfnodestateservice.test.mock;
23
24 import java.util.Optional;
25 import org.opendaylight.mdsal.binding.api.BindingService;
26 import org.opendaylight.mdsal.binding.api.DataBroker;
27 import org.opendaylight.mdsal.binding.api.MountPoint;
28 import org.opendaylight.mdsal.binding.api.NotificationService;
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;
35
36 /**
37  * @author herbert
38  *
39  */
40 public class MountPointMock implements MountPoint {
41
42     private boolean databrokerAbsent = true;
43     private final DataBrokerMountpointMock dataBroker = new DataBrokerMountpointMock();
44     private final RpcConsumerRegistryMock rpcConsumerRegistry = new RpcConsumerRegistryMock();
45     private NotificationService setReadTransaction;
46
47     private static final InstanceIdentifier<Topology> NETCONF_TOPO_IID =
48             InstanceIdentifier.create(NetworkTopology.class).child(Topology.class,
49                     new TopologyKey(new TopologyId(TopologyNetconf.QNAME.getLocalName())));
50
51     @Override
52     public InstanceIdentifier<?> getIdentifier() {
53         return NETCONF_TOPO_IID;
54     }
55
56     @SuppressWarnings("unchecked")
57     @Override
58     public <T extends BindingService> Optional<T> getService(Class<T> service) {
59
60         System.out.println("Requested mountpoint service: "+service.getSimpleName()+" databrokerAbsent state: "+databrokerAbsent);
61
62         Optional<? extends BindingService> res;
63         if (service.isInstance(dataBroker)) {
64             System.out.println("Delivering databroker");
65             res =  databrokerAbsent ? Optional.empty() : Optional.of(dataBroker);
66         } else if (service.isInstance(rpcConsumerRegistry)) {
67             System.out.println("Delivering RpcConsumerRegistryMock");
68             res = Optional.of(rpcConsumerRegistry);
69         } else if (service.isInstance(setReadTransaction)) {
70             System.out.println("Delivering notificationService");
71             res = Optional.of(setReadTransaction);
72         } else {
73             System.out.println("Delivering no service");
74             res = Optional.empty();
75         }
76         return (Optional<T>) res;
77     }
78
79     public void setDatabrokerAbsent( boolean state) {
80         this.databrokerAbsent = state;
81     }
82
83     public DataBroker getDataBroker() {
84         return dataBroker;
85     }
86
87 }