xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 1 | /* |
Brian O'Connor | 0a4e674 | 2016-09-15 23:03:10 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.drivers.fujitsu; |
| 18 | |
| 19 | import com.google.common.annotations.Beta; |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 20 | import org.onosproject.netconf.TargetConfig; |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 21 | import org.onosproject.netconf.NetconfDeviceOutputEventListener; |
| 22 | import org.onosproject.netconf.NetconfException; |
| 23 | import org.onosproject.netconf.NetconfSession; |
| 24 | |
| 25 | import java.util.List; |
| 26 | import java.util.concurrent.CompletableFuture; |
| 27 | |
| 28 | |
| 29 | /** |
| 30 | * Mock NetconfSessionImpl. |
| 31 | */ |
| 32 | public class FujitsuNetconfSessionMock implements NetconfSession { |
| 33 | |
| 34 | private FujitsuNetconfSessionListenerTest listener; |
| 35 | |
| 36 | /** |
| 37 | * Registers a listener to be invoked for verification. |
| 38 | * |
| 39 | * @param listener listener to be added |
| 40 | */ |
| 41 | public void setListener(FujitsuNetconfSessionListenerTest listener) { |
| 42 | this.listener = listener; |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public CompletableFuture<String> request(String request) throws NetconfException { |
| 47 | return null; |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public String get(String request) throws NetconfException { |
| 52 | return null; |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public String get(String filterSchema, String withDefaultsMode) |
| 57 | throws NetconfException { |
| 58 | boolean result = true; |
| 59 | String reply = null; |
| 60 | if (listener != null) { |
| 61 | result = listener.verifyGet(filterSchema, withDefaultsMode); |
| 62 | if (result) { |
| 63 | reply = listener.buildGetReply(); |
| 64 | } |
| 65 | } |
| 66 | return result ? ((reply == null) ? filterSchema : reply) : null; |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public String doWrappedRpc(String request) throws NetconfException { |
| 71 | boolean result = true; |
| 72 | if (listener != null) { |
| 73 | result = listener.verifyWrappedRpc(request); |
| 74 | } |
| 75 | return result ? request : null; |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public String requestSync(String request) throws NetconfException { |
| 80 | return null; |
| 81 | } |
| 82 | |
| 83 | @Override |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 84 | public String getConfig(TargetConfig targetConfiguration) throws NetconfException { |
| 85 | return null; |
| 86 | } |
| 87 | |
| 88 | @Override |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 89 | public String getConfig(String targetConfiguration) throws NetconfException { |
| 90 | return null; |
| 91 | } |
| 92 | |
| 93 | @Override |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 94 | public String getConfig(TargetConfig targetConfiguration, String configurationFilterSchema) |
| 95 | throws NetconfException { |
| 96 | return null; |
| 97 | } |
| 98 | |
| 99 | @Override |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 100 | public String getConfig(String targetConfiguration, String configurationFilterSchema) |
| 101 | throws NetconfException { |
| 102 | return null; |
| 103 | } |
| 104 | |
| 105 | @Override |
| 106 | public boolean editConfig(String newConfiguration) throws NetconfException { |
| 107 | boolean result = true; |
| 108 | if (listener != null) { |
| 109 | result = listener.verifyEditConfig(newConfiguration); |
| 110 | } |
| 111 | return result; |
| 112 | } |
| 113 | |
| 114 | @Override |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 115 | public boolean editConfig(TargetConfig targetConfiguration, String mode, String newConfiguration) |
| 116 | throws NetconfException { |
| 117 | boolean result = true; |
| 118 | if (listener != null) { |
| 119 | result = listener.verifyEditConfig(targetConfiguration, mode, newConfiguration); |
| 120 | } |
| 121 | return result; |
| 122 | } |
| 123 | |
| 124 | @Override |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 125 | public boolean editConfig(String targetConfiguration, String mode, String newConfiguration) |
| 126 | throws NetconfException { |
| 127 | boolean result = true; |
| 128 | if (listener != null) { |
| 129 | result = listener.verifyEditConfig(targetConfiguration, mode, newConfiguration); |
| 130 | } |
| 131 | return result; |
| 132 | } |
| 133 | |
| 134 | @Override |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 135 | public boolean copyConfig(TargetConfig targetConfiguration, String newConfiguration) |
| 136 | throws NetconfException { |
| 137 | return false; |
| 138 | } |
| 139 | |
| 140 | @Override |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 141 | public boolean copyConfig(String targetConfiguration, String newConfiguration) |
| 142 | throws NetconfException { |
| 143 | return false; |
| 144 | } |
| 145 | |
| 146 | @Override |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 147 | public boolean deleteConfig(TargetConfig targetConfiguration) throws NetconfException { |
| 148 | return false; |
| 149 | } |
| 150 | |
| 151 | @Override |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 152 | public boolean deleteConfig(String targetConfiguration) throws NetconfException { |
| 153 | return false; |
| 154 | } |
| 155 | |
Andrei Mihaescu | ac542ca | 2017-03-26 21:36:25 +0300 | [diff] [blame] | 156 | |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 157 | @Override |
| 158 | public void startSubscription() throws NetconfException { |
| 159 | } |
| 160 | |
| 161 | @Beta |
| 162 | @Override |
| 163 | public void startSubscription(String filterSchema) throws NetconfException { |
| 164 | if (listener != null) { |
| 165 | listener.verifyStartSubscription(filterSchema); |
| 166 | } |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void endSubscription() throws NetconfException { |
| 172 | } |
| 173 | |
| 174 | @Override |
| 175 | public boolean lock(String configType) throws NetconfException { |
| 176 | return false; |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public boolean unlock(String configType) throws NetconfException { |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | @Override |
| 185 | public boolean lock() throws NetconfException { |
| 186 | return false; |
| 187 | } |
| 188 | |
| 189 | @Override |
| 190 | public boolean unlock() throws NetconfException { |
| 191 | return false; |
| 192 | } |
| 193 | |
| 194 | @Override |
| 195 | public boolean close() throws NetconfException { |
| 196 | return false; |
| 197 | } |
| 198 | |
| 199 | @Override |
| 200 | public String getSessionId() { |
| 201 | return null; |
| 202 | } |
| 203 | |
| 204 | @Override |
| 205 | public String getServerCapabilities() { |
| 206 | return null; |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | public void setDeviceCapabilities(List<String> capabilities) { |
| 211 | } |
| 212 | |
| 213 | @Override |
Andrea Campanella | c362784 | 2017-04-04 18:06:54 +0200 | [diff] [blame^] | 214 | public void checkAndReestablish() throws NetconfException { |
| 215 | } |
| 216 | |
| 217 | @Override |
xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame] | 218 | public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
| 219 | } |
| 220 | |
| 221 | @Override |
| 222 | public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
| 223 | } |
| 224 | |
| 225 | } |