45c0f390060f58ce37a8a4c2b68b3be95ee13cd3
[ccsdk/features.git] /
1 /*******************************************************************************
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk feature sdnr wt
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 package org.onap.ccsdk.features.sdnr.wt.devicemanager.test.util;
22
23 import com.google.common.base.Optional;
24 import com.google.common.util.concurrent.CheckedFuture;
25 import java.util.concurrent.ExecutionException;
26 import java.util.concurrent.Executor;
27 import java.util.concurrent.TimeUnit;
28 import java.util.concurrent.TimeoutException;
29 import org.opendaylight.controller.md.sal.binding.api.NotificationService;
30 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
31 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
32 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
33 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.core.model.rev170320.NetworkElement;
34 import org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.MicrowaveModelListener;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNode;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeBuilder;
38 import org.opendaylight.yangtools.concepts.ListenerRegistration;
39 import org.opendaylight.yangtools.yang.binding.DataObject;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 import org.opendaylight.yangtools.yang.binding.NotificationListener;
42
43 /**
44  * @author herbert
45  *
46  */
47 @SuppressWarnings("deprecation")
48 public class ReadOnlyTransactionMountpoint12Mock implements ReadOnlyTransaction, NotificationService {
49
50     private final Model12ObjectMock mock = new Model12ObjectMock();
51     private MicrowaveModelListener modelListener;
52
53     @Override
54     public Object getIdentifier() {
55         return null;
56     }
57
58     public Model12ObjectMock getMock() {
59         return mock;
60     }
61
62     @SuppressWarnings("unchecked")
63     @Override
64     public <T extends DataObject> CheckedFuture<Optional<T>, ReadFailedException> read(LogicalDatastoreType store,
65             InstanceIdentifier<T> path) {
66
67         System.out.println("READ: " + path + " Store: " + store);
68
69         Optional<T> res1;
70
71         if (path.getTargetType().equals(Node.class)) {
72             System.out.println("Deliver " + path.getTargetType());
73             NetconfNode nNode = mock.getNetconfNode();
74             NodeBuilder nodeBuilder = new NodeBuilder();
75             nodeBuilder.addAugmentation(NetconfNode.class, nNode);
76             Node node = nodeBuilder.build();
77             res1 = (Optional<T>) Optional.of(node);
78
79         } else if (path.getTargetType().equals(NetworkElement.class)) {
80             System.out.println("Deliver " + path.getTargetType());
81             NetworkElement ne = mock.getNetworkElement();
82             res1 = (Optional<T>) Optional.of(ne);
83
84         } else if (path.getTargetType().equals(
85                 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.pac.AirInterfaceCurrentProblems.class)) {
86             // MwAirInterfacePac
87             System.out.println("Deliver " + path.getTargetType());
88             res1 = (Optional<T>) Optional.of(mock.getCurrentProblems(
89                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.air._interface.current.problems.g.CurrentProblemListBuilder.class,
90                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.pac.AirInterfaceCurrentProblemsBuilder.class));
91
92         } else if (path.getTargetType().equals(
93                 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.hybrid.mw.structure.pac.HybridMwStructureCurrentProblems.class)) {
94             // MwHybridMwStructurePac
95             System.out.println("Deliver " + path.getTargetType());
96             res1 = (Optional<T>) Optional.of(mock.getCurrentProblems(
97                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.hybrid.mw.structure.current.problems.g.CurrentProblemListBuilder.class,
98                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.hybrid.mw.structure.pac.HybridMwStructureCurrentProblemsBuilder.class));
99
100         } else if (path.getTargetType().equals(
101                 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.diversity.pac.AirInterfaceDiversityCurrentProblems.class)) {
102             // MwAirInterfaceDiversityPac
103             System.out.println("Deliver " + path.getTargetType());
104             res1 = (Optional<T>) Optional.of(mock.getCurrentProblems(
105                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.air._interface.diversity.current.problems.g.CurrentProblemListBuilder.class,
106                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.air._interface.diversity.pac.AirInterfaceDiversityCurrentProblemsBuilder.class));
107
108         } else if (path.getTargetType().equals(
109                 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.pure.ethernet.structure.pac.PureEthernetStructureCurrentProblems.class)) {
110             // MwPureEthernetStructurePac
111             System.out.println("Deliver " + path.getTargetType());
112             res1 = (Optional<T>) Optional.of(mock.getCurrentProblems(
113                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.pure.ethernet.structure.current.problems.g.CurrentProblemListBuilder.class,
114                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.pure.ethernet.structure.pac.PureEthernetStructureCurrentProblemsBuilder.class));
115
116         } else if (path.getTargetType().equals(
117                 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.ethernet.container.pac.EthernetContainerCurrentProblems.class)) {
118             //EthernetContainerCurrentProblems
119             System.out.println("Deliver " + path.getTargetType());
120             res1 = (Optional<T>) Optional.of(mock.getCurrentProblems(
121                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.ethernet.container.current.problems.g.CurrentProblemListBuilder.class,
122                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.ethernet.container.pac.EthernetContainerCurrentProblemsBuilder.class));
123
124         } else if (path.getTargetType().equals(
125                 org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.tdm.container.pac.TdmContainerCurrentProblems.class)) {
126             // TdmContainerCurrentProblems
127             System.out.println("Deliver " + path.getTargetType());
128             res1 = (Optional<T>) Optional.of(mock.getCurrentProblems(
129                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.tdm.container.current.problems.g.CurrentProblemListBuilder.class,
130                     org.opendaylight.yang.gen.v1.urn.onf.params.xml.ns.yang.microwave.model.rev170324.mw.tdm.container.pac.TdmContainerCurrentProblemsBuilder.class));
131
132         } else {
133             System.err.println("Nothing to deliver for" + path.getTargetType());
134             res1 = Optional.absent();
135         }
136
137
138         CheckedFuture<Optional<T>, ReadFailedException> res = new CheckedFuture<Optional<T>, ReadFailedException>() {
139
140             @Override
141             public void addListener(Runnable arg0, Executor arg1) {}
142
143             @Override
144             public boolean cancel(boolean mayInterruptIfRunning) {
145                 return false;
146             }
147
148             @Override
149             public Optional<T> get() throws InterruptedException, ExecutionException {
150                 return res1;
151             }
152
153             @Override
154             public Optional<T> get(long timeout, TimeUnit unit)
155                     throws InterruptedException, ExecutionException, TimeoutException {
156                 return null;
157             }
158
159             @Override
160             public boolean isCancelled() {
161                 return false;
162             }
163
164             @Override
165             public boolean isDone() {
166                 return false;
167             }
168
169             @Override
170             public Optional<T> checkedGet() throws ReadFailedException {
171                 return res1;
172             }
173
174             @Override
175             public Optional<T> checkedGet(long arg0, TimeUnit arg1) throws TimeoutException, ReadFailedException {
176                 return null;
177             }
178
179         };
180         return res;
181
182     }
183
184     @Override
185     public void close() {}
186
187     @Override
188     public <T extends NotificationListener> ListenerRegistration<T> registerNotificationListener(T listener) {
189         this.modelListener = (MicrowaveModelListener)listener;
190         return null;
191     }
192
193
194     public void sendProblemNotification() {
195         System.out.println("Send out Problemnotification");
196         modelListener.onProblemNotification(mock.getProblemNotification());
197     }
198
199 }