xueliang | 37a396a | 2016-09-09 14:43:49 +0900 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2015-present Open Networking Laboratory |
| 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; |
| 20 | import org.onosproject.netconf.NetconfDeviceOutputEventListener; |
| 21 | import org.onosproject.netconf.NetconfException; |
| 22 | import org.onosproject.netconf.NetconfSession; |
| 23 | |
| 24 | import java.util.List; |
| 25 | import java.util.concurrent.CompletableFuture; |
| 26 | |
| 27 | |
| 28 | /** |
| 29 | * Mock NetconfSessionImpl. |
| 30 | */ |
| 31 | public class FujitsuNetconfSessionMock implements NetconfSession { |
| 32 | |
| 33 | private FujitsuNetconfSessionListenerTest listener; |
| 34 | |
| 35 | /** |
| 36 | * Registers a listener to be invoked for verification. |
| 37 | * |
| 38 | * @param listener listener to be added |
| 39 | */ |
| 40 | public void setListener(FujitsuNetconfSessionListenerTest listener) { |
| 41 | this.listener = listener; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public CompletableFuture<String> request(String request) throws NetconfException { |
| 46 | return null; |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public String get(String request) throws NetconfException { |
| 51 | return null; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public String get(String filterSchema, String withDefaultsMode) |
| 56 | throws NetconfException { |
| 57 | boolean result = true; |
| 58 | String reply = null; |
| 59 | if (listener != null) { |
| 60 | result = listener.verifyGet(filterSchema, withDefaultsMode); |
| 61 | if (result) { |
| 62 | reply = listener.buildGetReply(); |
| 63 | } |
| 64 | } |
| 65 | return result ? ((reply == null) ? filterSchema : reply) : null; |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public String doWrappedRpc(String request) throws NetconfException { |
| 70 | boolean result = true; |
| 71 | if (listener != null) { |
| 72 | result = listener.verifyWrappedRpc(request); |
| 73 | } |
| 74 | return result ? request : null; |
| 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public String requestSync(String request) throws NetconfException { |
| 79 | return null; |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public String getConfig(String targetConfiguration) throws NetconfException { |
| 84 | return null; |
| 85 | } |
| 86 | |
| 87 | @Override |
| 88 | public String getConfig(String targetConfiguration, String configurationFilterSchema) |
| 89 | throws NetconfException { |
| 90 | return null; |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public boolean editConfig(String newConfiguration) throws NetconfException { |
| 95 | boolean result = true; |
| 96 | if (listener != null) { |
| 97 | result = listener.verifyEditConfig(newConfiguration); |
| 98 | } |
| 99 | return result; |
| 100 | } |
| 101 | |
| 102 | @Override |
| 103 | public boolean editConfig(String targetConfiguration, String mode, String newConfiguration) |
| 104 | throws NetconfException { |
| 105 | boolean result = true; |
| 106 | if (listener != null) { |
| 107 | result = listener.verifyEditConfig(targetConfiguration, mode, newConfiguration); |
| 108 | } |
| 109 | return result; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public boolean copyConfig(String targetConfiguration, String newConfiguration) |
| 114 | throws NetconfException { |
| 115 | return false; |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public boolean deleteConfig(String targetConfiguration) throws NetconfException { |
| 120 | return false; |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public void startSubscription() throws NetconfException { |
| 125 | } |
| 126 | |
| 127 | @Beta |
| 128 | @Override |
| 129 | public void startSubscription(String filterSchema) throws NetconfException { |
| 130 | if (listener != null) { |
| 131 | listener.verifyStartSubscription(filterSchema); |
| 132 | } |
| 133 | return; |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public void endSubscription() throws NetconfException { |
| 138 | } |
| 139 | |
| 140 | @Override |
| 141 | public boolean lock(String configType) throws NetconfException { |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public boolean unlock(String configType) throws NetconfException { |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | @Override |
| 151 | public boolean lock() throws NetconfException { |
| 152 | return false; |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | public boolean unlock() throws NetconfException { |
| 157 | return false; |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public boolean close() throws NetconfException { |
| 162 | return false; |
| 163 | } |
| 164 | |
| 165 | @Override |
| 166 | public String getSessionId() { |
| 167 | return null; |
| 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public String getServerCapabilities() { |
| 172 | return null; |
| 173 | } |
| 174 | |
| 175 | @Override |
| 176 | public void setDeviceCapabilities(List<String> capabilities) { |
| 177 | } |
| 178 | |
| 179 | @Override |
| 180 | public void addDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
| 181 | } |
| 182 | |
| 183 | @Override |
| 184 | public void removeDeviceOutputListener(NetconfDeviceOutputEventListener listener) { |
| 185 | } |
| 186 | |
| 187 | } |