Committed by
Gerrit Code Review
[ONOS-5269] JUNIT Test cases for volt-ponlinks and volt-setponlink for FUJITSU NETCONF
Change-Id: Iaff73d2eb1a617a97ebb1dcd8ccad7c0b809ea41
Showing
3 changed files
with
456 additions
and
36 deletions
... | @@ -25,6 +25,10 @@ import org.onosproject.netconf.NetconfController; | ... | @@ -25,6 +25,10 @@ import org.onosproject.netconf.NetconfController; |
25 | import org.slf4j.Logger; | 25 | import org.slf4j.Logger; |
26 | 26 | ||
27 | import java.io.IOException; | 27 | import java.io.IOException; |
28 | +import java.util.Arrays; | ||
29 | +import java.util.List; | ||
30 | +import java.util.HashMap; | ||
31 | +import java.util.Map; | ||
28 | import java.util.Set; | 32 | import java.util.Set; |
29 | 33 | ||
30 | import com.google.common.collect.ImmutableSet; | 34 | import com.google.common.collect.ImmutableSet; |
... | @@ -40,14 +44,48 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -40,14 +44,48 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
40 | implements VoltPonLinkConfig { | 44 | implements VoltPonLinkConfig { |
41 | 45 | ||
42 | private final Logger log = getLogger(FujitsuVoltPonLinkConfig.class); | 46 | private final Logger log = getLogger(FujitsuVoltPonLinkConfig.class); |
43 | - private final Set<String> ponLinkParams = ImmutableSet.of( | 47 | + private static final Map<String, List<Integer>> PON_LINK_PARAMS = new HashMap<String, List<Integer>>() { |
44 | - "admin-state", "onu-discovery-mode", "onu-discovery-interval", | 48 | + { |
45 | - "dba-cycle-time", "mac-age-time", "lof-threshold", | 49 | + put("onu-discovery-interval", Arrays.asList(ONU_DISCOVERY_INTERVAL_MIN, ONU_DISCOVERY_INTERVAL_MAX)); |
46 | - "los-threshold", "pm-enable"); | 50 | + put("dba-cycle-time", Arrays.asList(DBA_CYCLE_TIME_MIN, DBA_CYCLE_TIME_MAX)); |
51 | + put("mac-age-time", Arrays.asList(MAC_AGE_TIME_MIN, MAC_AGE_TIME_MAX)); | ||
52 | + put("lof-threshold", Arrays.asList(LOF_THRESHOLD_MIN, LOF_THRESHOLD_MAX)); | ||
53 | + put("los-threshold", Arrays.asList(LOS_THRESHOLD_MIN, LOS_THRESHOLD_MAX)); | ||
54 | + put(ONU_DISCOVERY_MODE, null); | ||
55 | + put(PM_ENABLE, null); | ||
56 | + put(ADMIN_STATE, null); | ||
57 | + } | ||
58 | + }; | ||
47 | private static final String VOLT_PORTS = "volt-ports"; | 59 | private static final String VOLT_PORTS = "volt-ports"; |
48 | private static final String GPON_PONLINK_PORTS = "gpon-ponlink-ports"; | 60 | private static final String GPON_PONLINK_PORTS = "gpon-ponlink-ports"; |
49 | private static final String GPON_PONLINK_PORT = "gpon-ponlink-port"; | 61 | private static final String GPON_PONLINK_PORT = "gpon-ponlink-port"; |
50 | - private int pon; | 62 | + private static final String ADMIN_STATE = "admin-state"; |
63 | + private static final String ONU_DISCOVERY_MODE = "onu-discovery-mode"; | ||
64 | + private static final String PM_ENABLE = "pm-enable"; | ||
65 | + private static final Set<String> ADMINSTATES = | ||
66 | + ImmutableSet.of("enable", "disable"); | ||
67 | + private static final Set<String> ONUDISCOVERYMODES = | ||
68 | + ImmutableSet.of("auto", "manual", "disabled"); | ||
69 | + private static final Set<String> PMENABLES = | ||
70 | + ImmutableSet.of("true", "false"); | ||
71 | + | ||
72 | + private static final int ONU_DISCOVERY_INTERVAL_MIN = 1; | ||
73 | + private static final int ONU_DISCOVERY_INTERVAL_MAX = 3600; | ||
74 | + private static final int DBA_CYCLE_TIME_MIN = 2; | ||
75 | + private static final int DBA_CYCLE_TIME_MAX = 40; | ||
76 | + private static final int MAC_AGE_TIME_MIN = 1000; | ||
77 | + private static final int MAC_AGE_TIME_MAX = 3600000; | ||
78 | + private static final int LOF_THRESHOLD_MIN = 1; | ||
79 | + private static final int LOF_THRESHOLD_MAX = 10; | ||
80 | + private static final int LOS_THRESHOLD_MIN = 1; | ||
81 | + private static final int LOS_THRESHOLD_MAX = 10; | ||
82 | + private static final int FIRST_PART = 0; | ||
83 | + private static final int SECOND_PART = 1; | ||
84 | + private static final int THIRD_PART = 2; | ||
85 | + private static final int RANGE_MIN = 0; | ||
86 | + private static final int RANGE_MAX = 1; | ||
87 | + private static final int ZERO = 0; | ||
88 | + private static final int THREE = 3; | ||
51 | 89 | ||
52 | @Override | 90 | @Override |
53 | public String getPonLinks(String target) { | 91 | public String getPonLinks(String target) { |
... | @@ -71,10 +109,15 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -71,10 +109,15 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
71 | request.append(ANGLE_RIGHT).append(NEW_LINE); | 109 | request.append(ANGLE_RIGHT).append(NEW_LINE); |
72 | request.append(buildStartTag(VOLT_PORTS)); | 110 | request.append(buildStartTag(VOLT_PORTS)); |
73 | if (target != null) { | 111 | if (target != null) { |
112 | + int pon; | ||
74 | try { | 113 | try { |
75 | pon = Integer.parseInt(target); | 114 | pon = Integer.parseInt(target); |
115 | + if (pon <= ZERO) { | ||
116 | + log.error("Invalid integer for ponlink-id:{}", target); | ||
117 | + return reply; | ||
118 | + } | ||
76 | } catch (NumberFormatException e) { | 119 | } catch (NumberFormatException e) { |
77 | - log.error("Non-number input"); | 120 | + log.error("Non-number input for ponlink-id:{}", target); |
78 | return reply; | 121 | return reply; |
79 | } | 122 | } |
80 | request.append(buildStartTag(GPON_PONLINK_PORTS)); | 123 | request.append(buildStartTag(GPON_PONLINK_PORTS)); |
... | @@ -91,17 +134,19 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -91,17 +134,19 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
91 | request.append(buildEndTag(VOLT_PORTS)); | 134 | request.append(buildEndTag(VOLT_PORTS)); |
92 | request.append(VOLT_NE_CLOSE); | 135 | request.append(VOLT_NE_CLOSE); |
93 | 136 | ||
94 | - reply = controller. | 137 | + reply = controller |
95 | - getDevicesMap().get(ncDeviceId).getSession(). | 138 | + .getDevicesMap() |
96 | - get(request.toString(), REPORT_ALL); | 139 | + .get(ncDeviceId) |
140 | + .getSession() | ||
141 | + .get(request.toString(), REPORT_ALL); | ||
97 | } catch (IOException e) { | 142 | } catch (IOException e) { |
98 | - log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | 143 | + log.error("Cannot communicate to device {} exception {}", ncDeviceId, e); |
99 | } | 144 | } |
100 | return reply; | 145 | return reply; |
101 | } | 146 | } |
102 | 147 | ||
103 | @Override | 148 | @Override |
104 | - public void setPonLink(String target) { | 149 | + public boolean setPonLink(String target) { |
105 | DriverHandler handler = handler(); | 150 | DriverHandler handler = handler(); |
106 | NetconfController controller = handler.get(NetconfController.class); | 151 | NetconfController controller = handler.get(NetconfController.class); |
107 | MastershipService mastershipService = handler.get(MastershipService.class); | 152 | MastershipService mastershipService = handler.get(MastershipService.class); |
... | @@ -112,27 +157,16 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -112,27 +157,16 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
112 | log.warn("Not master for {} Use {} to execute command", | 157 | log.warn("Not master for {} Use {} to execute command", |
113 | ncDeviceId, | 158 | ncDeviceId, |
114 | mastershipService.getMasterFor(ncDeviceId)); | 159 | mastershipService.getMasterFor(ncDeviceId)); |
115 | - return; | 160 | + return false; |
116 | - } | ||
117 | - | ||
118 | - String[] data = target.split(COLON); | ||
119 | - if (data.length != 3) { | ||
120 | - log.error("Invalid number of arguments"); | ||
121 | - return; | ||
122 | - } | ||
123 | - | ||
124 | - try { | ||
125 | - pon = Integer.parseInt(data[0]); | ||
126 | - } catch (NumberFormatException e) { | ||
127 | - log.error("Non-number input"); | ||
128 | - return; | ||
129 | } | 161 | } |
130 | 162 | ||
131 | - if (!ponLinkParams.contains(data[1])) { | 163 | + String[] data = checkSetInput(target); |
132 | - log.error("Unsupported parameter: {} ", data[1]); | 164 | + if (data == null) { |
133 | - return; | 165 | + log.error("Failed to check input: {}", target); |
166 | + return false; | ||
134 | } | 167 | } |
135 | 168 | ||
169 | + boolean result = false; | ||
136 | try { | 170 | try { |
137 | StringBuilder request = new StringBuilder(); | 171 | StringBuilder request = new StringBuilder(); |
138 | request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); | 172 | request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); |
... | @@ -141,23 +175,117 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour | ... | @@ -141,23 +175,117 @@ public class FujitsuVoltPonLinkConfig extends AbstractHandlerBehaviour |
141 | request.append(buildStartTag(GPON_PONLINK_PORTS)); | 175 | request.append(buildStartTag(GPON_PONLINK_PORTS)); |
142 | request.append(buildStartTag(GPON_PONLINK_PORT)); | 176 | request.append(buildStartTag(GPON_PONLINK_PORT)); |
143 | request.append(buildStartTag(PONLINK_ID, false)); | 177 | request.append(buildStartTag(PONLINK_ID, false)); |
144 | - request.append(data[0]); | 178 | + request.append(data[FIRST_PART]); |
145 | request.append(buildEndTag(PONLINK_ID)); | 179 | request.append(buildEndTag(PONLINK_ID)); |
146 | 180 | ||
147 | - request.append(buildStartTag(data[1], false)); | 181 | + request.append(buildStartTag(data[SECOND_PART], false)); |
148 | - request.append(data[2]); | 182 | + request.append(data[THIRD_PART]); |
149 | - request.append(buildEndTag(data[1])); | 183 | + request.append(buildEndTag(data[SECOND_PART])); |
150 | 184 | ||
151 | request.append(buildEndTag(GPON_PONLINK_PORT)); | 185 | request.append(buildEndTag(GPON_PONLINK_PORT)); |
152 | request.append(buildEndTag(GPON_PONLINK_PORTS)); | 186 | request.append(buildEndTag(GPON_PONLINK_PORTS)); |
153 | request.append(buildEndTag(VOLT_PORTS)); | 187 | request.append(buildEndTag(VOLT_PORTS)); |
154 | request.append(VOLT_NE_CLOSE); | 188 | request.append(VOLT_NE_CLOSE); |
155 | 189 | ||
156 | - controller.getDevicesMap().get(ncDeviceId).getSession(). | 190 | + result = controller.getDevicesMap().get(ncDeviceId).getSession(). |
157 | editConfig(RUNNING, null, request.toString()); | 191 | editConfig(RUNNING, null, request.toString()); |
158 | } catch (IOException e) { | 192 | } catch (IOException e) { |
159 | - log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | 193 | + log.error("Cannot communicate to device {} exception {}", ncDeviceId, e); |
160 | } | 194 | } |
195 | + return result; | ||
161 | } | 196 | } |
162 | 197 | ||
198 | + /** | ||
199 | + * Verifies input string for valid options. | ||
200 | + * | ||
201 | + * @param target input data in string | ||
202 | + * @return String array | ||
203 | + * @return null if an error condition is detected | ||
204 | + */ | ||
205 | + private String[] checkSetInput(String target) { | ||
206 | + String[] data = target.split(COLON); | ||
207 | + String paramName = data[SECOND_PART]; | ||
208 | + String paramValue = data[THIRD_PART]; | ||
209 | + int pon; | ||
210 | + | ||
211 | + if (data.length != THREE) { | ||
212 | + log.error("Invalid number of arguments {}", data.length); | ||
213 | + return null; | ||
214 | + } | ||
215 | + | ||
216 | + try { | ||
217 | + pon = Integer.parseInt(data[FIRST_PART]); | ||
218 | + if (pon <= ZERO) { | ||
219 | + log.error("Invalid integer for ponlink-id: {}", | ||
220 | + data[FIRST_PART]); | ||
221 | + return null; | ||
222 | + } | ||
223 | + } catch (NumberFormatException e) { | ||
224 | + log.error("Non-number input for ponlink-id: {}", | ||
225 | + data[FIRST_PART]); | ||
226 | + return null; | ||
227 | + } | ||
228 | + | ||
229 | + if (!PON_LINK_PARAMS.containsKey(paramName)) { | ||
230 | + log.error("Unsupported parameter: {}", paramName); | ||
231 | + return null; | ||
232 | + } | ||
233 | + | ||
234 | + List<Integer> range = PON_LINK_PARAMS.get(paramName); | ||
235 | + if (range == null) { | ||
236 | + switch (paramName) { | ||
237 | + case ADMIN_STATE: | ||
238 | + if (!validState(ADMINSTATES, paramName, paramValue)) { | ||
239 | + return null; | ||
240 | + } | ||
241 | + break; | ||
242 | + case ONU_DISCOVERY_MODE: | ||
243 | + if (!validState(ONUDISCOVERYMODES, paramName, paramValue)) { | ||
244 | + return null; | ||
245 | + } | ||
246 | + break; | ||
247 | + default: | ||
248 | + if (!validState(PMENABLES, paramName, paramValue)) { | ||
249 | + return null; | ||
250 | + } | ||
251 | + break; | ||
252 | + } | ||
253 | + } else { | ||
254 | + int value; | ||
255 | + | ||
256 | + try { | ||
257 | + value = Integer.parseInt(paramValue); | ||
258 | + } catch (NumberFormatException e) { | ||
259 | + log.error("Non-number input for Name {} : Value {}.", | ||
260 | + paramName, paramValue); | ||
261 | + return null; | ||
262 | + } | ||
263 | + | ||
264 | + if ((value < range.get(RANGE_MIN)) || | ||
265 | + (value > range.get(RANGE_MAX))) { | ||
266 | + log.error("Out of value range for Name {} : Value {}.", | ||
267 | + paramName, paramValue); | ||
268 | + return null; | ||
269 | + } | ||
270 | + } | ||
271 | + | ||
272 | + return data; | ||
273 | + } | ||
274 | + | ||
275 | + /** | ||
276 | + * Verifies input string for valid options. | ||
277 | + * | ||
278 | + * @param states input data in string for parameter state | ||
279 | + * @param name input data in string for parameter name | ||
280 | + * @param value input data in string for parameter value | ||
281 | + * @return true if the param is valid | ||
282 | + * @return false if the param is invalid | ||
283 | + */ | ||
284 | + private boolean validState(Set<String> states, String name, String value) { | ||
285 | + if (!states.contains(value)) { | ||
286 | + log.error("Invalid value for Name {} : Value {}.", name, value); | ||
287 | + return false; | ||
288 | + } | ||
289 | + return true; | ||
290 | + } | ||
163 | } | 291 | } | ... | ... |
... | @@ -36,8 +36,8 @@ public interface VoltPonLinkConfig extends HandlerBehaviour { | ... | @@ -36,8 +36,8 @@ public interface VoltPonLinkConfig extends HandlerBehaviour { |
36 | * Set a parameter value of PON link in the device. | 36 | * Set a parameter value of PON link in the device. |
37 | * | 37 | * |
38 | * @param target input data in string | 38 | * @param target input data in string |
39 | - * | 39 | + * @return true if the operation is successful |
40 | */ | 40 | */ |
41 | - void setPonLink(String target); | 41 | + boolean setPonLink(String target); |
42 | 42 | ||
43 | } | 43 | } | ... | ... |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltPonLinkConfigTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016-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 org.junit.Before; | ||
20 | +import org.junit.Test; | ||
21 | + | ||
22 | +import java.util.HashMap; | ||
23 | +import java.util.Map; | ||
24 | + | ||
25 | +import static org.junit.Assert.assertFalse; | ||
26 | +import static org.junit.Assert.assertTrue; | ||
27 | +import static org.junit.Assert.assertNull; | ||
28 | +import static org.junit.Assert.assertNotNull; | ||
29 | +import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*; | ||
30 | + | ||
31 | +/** | ||
32 | + * Unit tests for methods of FujitsuVoltPonLinkConfig. | ||
33 | + */ | ||
34 | +public class FujitsuVoltPonLinkConfigTest { | ||
35 | + | ||
36 | + private FujitsuNetconfControllerMock controller; | ||
37 | + private FujitsuDriverHandlerAdapter driverHandler; | ||
38 | + private FujitsuVoltPonLinkConfig voltConfig; | ||
39 | + | ||
40 | + private final FujitsuNetconfSessionListenerTest listener = new InternalSessionListenerTest(); | ||
41 | + | ||
42 | + private static final String TEST_VOLT_PORTS = "volt-ports"; | ||
43 | + private static final String TEST_GPON_PONLINK_PORTS = "gpon-ponlink-ports"; | ||
44 | + private static final String TEST_GPON_PONLINK_PORT = "gpon-ponlink-port"; | ||
45 | + private static final int FIRST_PART = 0; | ||
46 | + private static final int SECOND_PART = 1; | ||
47 | + private static final int THIRD_PART = 2; | ||
48 | + | ||
49 | + private static final Map<Integer, String> INVALID_GET_TCS = new HashMap<Integer, String>() { | ||
50 | + { | ||
51 | + put(1, "a-b-c"); | ||
52 | + put(2, "--1"); | ||
53 | + put(3, "s-1"); | ||
54 | + put(4, "1-1"); | ||
55 | + put(5, "1 A"); | ||
56 | + put(6, "1*A"); | ||
57 | + } | ||
58 | + }; | ||
59 | + private static final Map<Integer, String> VALID_GET_TCS = new HashMap<Integer, String>() { | ||
60 | + { | ||
61 | + put(1, "1"); | ||
62 | + put(2, null); | ||
63 | + } | ||
64 | + }; | ||
65 | + private static final Map<Integer, String> INVALID_SET_TCS = new HashMap<Integer, String>() { | ||
66 | + { | ||
67 | + put(1, "-11:admin-state:enable"); | ||
68 | + put(2, "1:admin-state:false"); | ||
69 | + put(3, "2-1:onu-discovery-mode:manual"); | ||
70 | + put(4, "2:onu-discovery-mode:abcdef"); | ||
71 | + put(5, "3:a:onu-discovery-interval:8"); | ||
72 | + put(6, "3:onu-discovery-interval:-1"); | ||
73 | + put(7, "3:onu-discovery-interval:s1"); | ||
74 | + put(8, "4:dba-cycle-time:41"); | ||
75 | + put(9, "5*8:mac-age-time:30000"); | ||
76 | + put(10, "8:mac-age-time:3699999"); | ||
77 | + put(11, "1:lof-threshold:111"); | ||
78 | + put(12, "2:los-threshold:22"); | ||
79 | + put(13, "3:pm-enable:xyz"); | ||
80 | + put(14, "3:abc-enable:xyz"); | ||
81 | + } | ||
82 | + }; | ||
83 | + private static final Map<Integer, String> VALID_SET_TCS = new HashMap<Integer, String>() { | ||
84 | + { | ||
85 | + put(1, "1:admin-state:disable"); | ||
86 | + put(2, "2:onu-discovery-mode:manual"); | ||
87 | + put(3, "3:onu-discovery-interval:8"); | ||
88 | + put(4, "4:dba-cycle-time:8"); | ||
89 | + put(5, "5:mac-age-time:33333"); | ||
90 | + put(6, "6:lof-threshold:7"); | ||
91 | + put(7, "7:los-threshold:5"); | ||
92 | + put(8, "8:pm-enable:true"); | ||
93 | + } | ||
94 | + }; | ||
95 | + private Integer currentKey; | ||
96 | + | ||
97 | + | ||
98 | + @Before | ||
99 | + public void setUp() throws Exception { | ||
100 | + controller = new FujitsuNetconfControllerMock(); | ||
101 | + driverHandler = controller.setUp(listener); | ||
102 | + voltConfig = new FujitsuVoltPonLinkConfig(); | ||
103 | + voltConfig.setHandler(driverHandler); | ||
104 | + } | ||
105 | + | ||
106 | + /** | ||
107 | + * Run to verify handling of invalid input for get operation. | ||
108 | + */ | ||
109 | + @Test | ||
110 | + public void testInvalidGetPonLinksInput() throws Exception { | ||
111 | + String reply; | ||
112 | + String target; | ||
113 | + | ||
114 | + for (Integer key : INVALID_GET_TCS.keySet()) { | ||
115 | + target = INVALID_GET_TCS.get(key); | ||
116 | + reply = voltConfig.getPonLinks(target); | ||
117 | + assertNull("Incorrect response for " + target, reply); | ||
118 | + } | ||
119 | + } | ||
120 | + | ||
121 | + /** | ||
122 | + * Run to verify handling of valid input for get operation. | ||
123 | + */ | ||
124 | + @Test | ||
125 | + public void testValidGetPonLinks() throws Exception { | ||
126 | + String reply; | ||
127 | + String target; | ||
128 | + | ||
129 | + for (Integer key : VALID_GET_TCS.keySet()) { | ||
130 | + target = VALID_GET_TCS.get(key); | ||
131 | + currentKey = key; | ||
132 | + reply = voltConfig.getPonLinks(target); | ||
133 | + assertNotNull("Incorrect response for " + target, reply); | ||
134 | + } | ||
135 | + } | ||
136 | + | ||
137 | + /** | ||
138 | + * Run to verify handling of invalid input for set operation. | ||
139 | + */ | ||
140 | + @Test | ||
141 | + public void testInvalidSetPonLinkInput() throws Exception { | ||
142 | + String target; | ||
143 | + boolean result; | ||
144 | + | ||
145 | + for (Integer key : INVALID_SET_TCS.keySet()) { | ||
146 | + target = INVALID_SET_TCS.get(key); | ||
147 | + result = voltConfig.setPonLink(target); | ||
148 | + assertFalse("Incorrect response for ", result); | ||
149 | + } | ||
150 | + } | ||
151 | + | ||
152 | + /** | ||
153 | + * Run to verify handling of valid input for set operation. | ||
154 | + */ | ||
155 | + @Test | ||
156 | + public void testValidSetPonLink() throws Exception { | ||
157 | + String target; | ||
158 | + boolean result; | ||
159 | + | ||
160 | + for (Integer key : VALID_SET_TCS.keySet()) { | ||
161 | + target = VALID_SET_TCS.get(key); | ||
162 | + currentKey = key; | ||
163 | + result = voltConfig.setPonLink(target); | ||
164 | + assertTrue("Incorrect response for ", result); | ||
165 | + } | ||
166 | + } | ||
167 | + | ||
168 | + /** | ||
169 | + * Verifies XML request string by comparing with generated string. | ||
170 | + * | ||
171 | + * @param request XML string for set operation | ||
172 | + * @return true if XML string matches with generated | ||
173 | + */ | ||
174 | + private boolean verifyGetRequest(String request) { | ||
175 | + StringBuilder rpc = new StringBuilder(); | ||
176 | + String target = VALID_GET_TCS.get(currentKey); | ||
177 | + | ||
178 | + rpc.append(TEST_VOLT_NE_OPEN).append(TEST_VOLT_NE_NAMESPACE); | ||
179 | + rpc.append(TEST_ANGLE_RIGHT).append(TEST_NEW_LINE); | ||
180 | + rpc.append(startTag(TEST_VOLT_PORTS)); | ||
181 | + if (target != null) { | ||
182 | + rpc.append(startTag(TEST_GPON_PONLINK_PORTS)); | ||
183 | + rpc.append(startTag(TEST_GPON_PONLINK_PORT)); | ||
184 | + rpc.append(startTag(TEST_PONLINK_ID, false)); | ||
185 | + rpc.append(target); | ||
186 | + rpc.append(endTag(TEST_PONLINK_ID)); | ||
187 | + rpc.append(endTag(TEST_GPON_PONLINK_PORT)); | ||
188 | + rpc.append(endTag(TEST_GPON_PONLINK_PORTS)); | ||
189 | + } else { | ||
190 | + rpc.append(emptyTag(TEST_GPON_PONLINK_PORTS)); | ||
191 | + } | ||
192 | + rpc.append(endTag(TEST_VOLT_PORTS)); | ||
193 | + rpc.append(TEST_VOLT_NE_CLOSE); | ||
194 | + | ||
195 | + String testRequest = rpc.toString(); | ||
196 | + testRequest = testRequest.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING); | ||
197 | + request = request.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING); | ||
198 | + boolean result = request.equals(testRequest); | ||
199 | + assertTrue("Does not match with generated string", result); | ||
200 | + return result; | ||
201 | + } | ||
202 | + | ||
203 | + /** | ||
204 | + * Verifies XML request string by comparing with generated string. | ||
205 | + * | ||
206 | + * @param request XML string for set operation | ||
207 | + * @return true or false | ||
208 | + */ | ||
209 | + private boolean verifyEditConfigRequest(String request) { | ||
210 | + StringBuilder rpc = new StringBuilder(); | ||
211 | + String target = VALID_SET_TCS.get(currentKey); | ||
212 | + String[] data = target.split(TEST_COLON); | ||
213 | + | ||
214 | + rpc.append(TEST_VOLT_NE_OPEN).append(TEST_VOLT_NE_NAMESPACE); | ||
215 | + rpc.append(TEST_ANGLE_RIGHT).append(TEST_NEW_LINE); | ||
216 | + rpc.append(startTag(TEST_VOLT_PORTS)); | ||
217 | + rpc.append(startTag(TEST_GPON_PONLINK_PORTS)); | ||
218 | + rpc.append(startTag(TEST_GPON_PONLINK_PORT)); | ||
219 | + rpc.append(startTag(TEST_PONLINK_ID, false)); | ||
220 | + rpc.append(data[FIRST_PART]); | ||
221 | + rpc.append(endTag(TEST_PONLINK_ID)); | ||
222 | + rpc.append(startTag(data[SECOND_PART], false)); | ||
223 | + rpc.append(data[THIRD_PART]); | ||
224 | + rpc.append(endTag(data[SECOND_PART])); | ||
225 | + rpc.append(endTag(TEST_GPON_PONLINK_PORT)); | ||
226 | + rpc.append(endTag(TEST_GPON_PONLINK_PORTS)); | ||
227 | + rpc.append(endTag(TEST_VOLT_PORTS)); | ||
228 | + rpc.append(TEST_VOLT_NE_CLOSE); | ||
229 | + | ||
230 | + String testRequest = rpc.toString(); | ||
231 | + testRequest = testRequest.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING); | ||
232 | + request = request.replaceAll(TEST_WHITESPACES_REGEX, TEST_EMPTY_STRING); | ||
233 | + boolean result = request.equals(testRequest); | ||
234 | + assertTrue("Does not match with generated string", result); | ||
235 | + return result; | ||
236 | + } | ||
237 | + | ||
238 | + /** | ||
239 | + * Internal listener for device service events. | ||
240 | + */ | ||
241 | + private class InternalSessionListenerTest implements FujitsuNetconfSessionListenerTest { | ||
242 | + @Override | ||
243 | + public boolean verifyEditConfig(String request) { | ||
244 | + return false; | ||
245 | + } | ||
246 | + | ||
247 | + @Override | ||
248 | + public boolean verifyEditConfig(String target, String mode, String request) { | ||
249 | + boolean result; | ||
250 | + | ||
251 | + assertTrue("Incorrect target", target.equals(TEST_RUNNING)); | ||
252 | + assertNull("Incorrect mode", mode); | ||
253 | + | ||
254 | + request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE); | ||
255 | + assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE, | ||
256 | + request.contains(TEST_VOLT_NAMESPACE)); | ||
257 | + result = verifyEditConfigRequest(request); | ||
258 | + assertTrue("XML verification failure", result); | ||
259 | + return result; | ||
260 | + } | ||
261 | + | ||
262 | + @Override | ||
263 | + public boolean verifyGet(String filterSchema, String withDefaultsMode) { | ||
264 | + boolean result; | ||
265 | + | ||
266 | + assertTrue("Incorrect withDefaultsMode", | ||
267 | + withDefaultsMode.equals(TEST_REPORT_ALL)); | ||
268 | + | ||
269 | + filterSchema = filterSchema.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE); | ||
270 | + assertTrue("Does not contain:" + TEST_VOLT_NAMESPACE, | ||
271 | + filterSchema.contains(TEST_VOLT_NAMESPACE)); | ||
272 | + result = verifyGetRequest(filterSchema); | ||
273 | + assertTrue("XML verification failure", result); | ||
274 | + return result; | ||
275 | + } | ||
276 | + | ||
277 | + @Override | ||
278 | + public String buildGetReply() { | ||
279 | + return null; | ||
280 | + } | ||
281 | + | ||
282 | + @Override | ||
283 | + public boolean verifyWrappedRpc(String request) { | ||
284 | + return false; | ||
285 | + } | ||
286 | + | ||
287 | + @Override | ||
288 | + public void verifyStartSubscription(String filterSchema) { | ||
289 | + } | ||
290 | + } | ||
291 | + | ||
292 | +} |
-
Please register or login to post a comment