Committed by
Gerrit Code Review
[ONOS-5326] JUNIT Test cases for volt-rebootonu and volt-ethloopback as FUJITSU NETCONF
Change-Id: Ied14896955595ce4f694885991231b75be2e63c5
Showing
3 changed files
with
393 additions
and
57 deletions
... | @@ -16,6 +16,7 @@ | ... | @@ -16,6 +16,7 @@ |
16 | 16 | ||
17 | package org.onosproject.drivers.fujitsu; | 17 | package org.onosproject.drivers.fujitsu; |
18 | 18 | ||
19 | +import com.google.common.collect.ImmutableSet; | ||
19 | import org.onosproject.mastership.MastershipService; | 20 | import org.onosproject.mastership.MastershipService; |
20 | import org.onosproject.net.DeviceId; | 21 | import org.onosproject.net.DeviceId; |
21 | import org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig; | 22 | import org.onosproject.drivers.fujitsu.behaviour.VoltOnuOperConfig; |
... | @@ -25,6 +26,7 @@ import org.onosproject.netconf.NetconfController; | ... | @@ -25,6 +26,7 @@ import org.onosproject.netconf.NetconfController; |
25 | import org.slf4j.Logger; | 26 | import org.slf4j.Logger; |
26 | 27 | ||
27 | import java.io.IOException; | 28 | import java.io.IOException; |
29 | +import java.util.Set; | ||
28 | 30 | ||
29 | import static com.google.common.base.Preconditions.checkNotNull; | 31 | import static com.google.common.base.Preconditions.checkNotNull; |
30 | import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*; | 32 | import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*; |
... | @@ -41,10 +43,9 @@ public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour | ... | @@ -41,10 +43,9 @@ public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour |
41 | private static final String ONU_REBOOT = "onu-reboot"; | 43 | private static final String ONU_REBOOT = "onu-reboot"; |
42 | private static final String ONU_ETHPORT_LOOPBACK = "onu-ethport-loopback"; | 44 | private static final String ONU_ETHPORT_LOOPBACK = "onu-ethport-loopback"; |
43 | private static final String ETHPORT_ID = "ethport-id"; | 45 | private static final String ETHPORT_ID = "ethport-id"; |
44 | - private int pon; | 46 | + private static final String LOOPBACK_MODE = "mode"; |
45 | - private int onu; | 47 | + private static final Set<String> LOOPBACKMODES = |
46 | - private int eth; | 48 | + ImmutableSet.of("operate", "release"); |
47 | - | ||
48 | 49 | ||
49 | @Override | 50 | @Override |
50 | public String rebootOnu(String target) { | 51 | public String rebootOnu(String target) { |
... | @@ -60,39 +61,35 @@ public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour | ... | @@ -60,39 +61,35 @@ public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour |
60 | log.warn("Not master for {} Use {} to execute command", | 61 | log.warn("Not master for {} Use {} to execute command", |
61 | ncDeviceId, | 62 | ncDeviceId, |
62 | mastershipService.getMasterFor(ncDeviceId)); | 63 | mastershipService.getMasterFor(ncDeviceId)); |
63 | - return reply; | 64 | + return null; |
64 | } | 65 | } |
65 | 66 | ||
66 | - onuId = target.split(HYPHEN); | 67 | + onuId = checkIdString(target, TWO); |
67 | - if (onuId.length != 2) { | 68 | + if (onuId == null) { |
68 | - log.error("Invalid number of arguments"); | 69 | + log.error("Invalid ONU identifier {}", target); |
69 | - return reply; | 70 | + return null; |
70 | - } | ||
71 | - try { | ||
72 | - pon = Integer.parseInt(onuId[0]); | ||
73 | - onu = Integer.parseInt(onuId[1]); | ||
74 | - } catch (NumberFormatException e) { | ||
75 | - log.error("Non-number input"); | ||
76 | - return reply; | ||
77 | } | 71 | } |
78 | 72 | ||
79 | try { | 73 | try { |
80 | StringBuilder request = new StringBuilder(); | 74 | StringBuilder request = new StringBuilder(); |
81 | - request.append(ANGLE_LEFT).append(ONU_REBOOT).append(SPACE); | 75 | + request.append(ANGLE_LEFT + ONU_REBOOT + SPACE); |
82 | - request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE); | 76 | + request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE); |
83 | - request.append(buildStartTag(PONLINK_ID, false)); | 77 | + |
84 | - request.append(onuId[0]); | 78 | + request.append(buildStartTag(PONLINK_ID, false)) |
85 | - request.append(buildEndTag(PONLINK_ID)); | 79 | + .append(onuId[FIRST_PART]) |
86 | - request.append(buildStartTag(ONU_ID, false)); | 80 | + .append(buildEndTag(PONLINK_ID)) |
87 | - request.append(onuId[1]); | 81 | + .append(buildStartTag(ONU_ID, false)) |
88 | - request.append(buildEndTag(ONU_ID)); | 82 | + .append(onuId[SECOND_PART]) |
89 | - request.append(buildEndTag(ONU_REBOOT)); | 83 | + .append(buildEndTag(ONU_ID)) |
90 | - | 84 | + .append(buildEndTag(ONU_REBOOT)); |
91 | - reply = controller. | 85 | + |
92 | - getDevicesMap().get(ncDeviceId).getSession(). | 86 | + reply = controller |
93 | - doWrappedRpc(request.toString()); | 87 | + .getDevicesMap() |
88 | + .get(ncDeviceId) | ||
89 | + .getSession() | ||
90 | + .doWrappedRpc(request.toString()); | ||
94 | } catch (IOException e) { | 91 | } catch (IOException e) { |
95 | - log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | 92 | + log.error("Cannot communicate to device {} exception {}", ncDeviceId, e); |
96 | } | 93 | } |
97 | return reply; | 94 | return reply; |
98 | } | 95 | } |
... | @@ -105,51 +102,110 @@ public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour | ... | @@ -105,51 +102,110 @@ public class FujitsuVoltOnuOperConfig extends AbstractHandlerBehaviour |
105 | DeviceId ncDeviceId = handler.data().deviceId(); | 102 | DeviceId ncDeviceId = handler.data().deviceId(); |
106 | checkNotNull(controller, "Netconf controller is null"); | 103 | checkNotNull(controller, "Netconf controller is null"); |
107 | String reply = null; | 104 | String reply = null; |
105 | + String[] data = null; | ||
108 | String[] ethId = null; | 106 | String[] ethId = null; |
109 | 107 | ||
110 | if (!mastershipService.isLocalMaster(ncDeviceId)) { | 108 | if (!mastershipService.isLocalMaster(ncDeviceId)) { |
111 | log.warn("Not master for {} Use {} to execute command", | 109 | log.warn("Not master for {} Use {} to execute command", |
112 | ncDeviceId, | 110 | ncDeviceId, |
113 | mastershipService.getMasterFor(ncDeviceId)); | 111 | mastershipService.getMasterFor(ncDeviceId)); |
114 | - return reply; | 112 | + return null; |
115 | } | 113 | } |
116 | 114 | ||
117 | - ethId = target.split(HYPHEN); | 115 | + data = target.split(COLON); |
118 | - if (ethId.length != 3) { | 116 | + if (data.length > TWO) { |
119 | - log.error("Invalid number of arguments"); | 117 | + log.error("Invalid number of parameters {}", target); |
120 | - return reply; | 118 | + return null; |
121 | } | 119 | } |
122 | - try { | 120 | + |
123 | - pon = Integer.parseInt(ethId[0]); | 121 | + ethId = checkIdString(data[FIRST_PART], THREE); |
124 | - onu = Integer.parseInt(ethId[1]); | 122 | + if (ethId == null) { |
125 | - eth = Integer.parseInt(ethId[2]); | 123 | + log.error("Invalid ETH port identifier {}", data[FIRST_PART]); |
126 | - } catch (NumberFormatException e) { | 124 | + return null; |
127 | - log.error("Non-number input"); | 125 | + } |
128 | - return reply; | 126 | + |
127 | + if (data.length > ONE) { | ||
128 | + if (!LOOPBACKMODES.contains(data[SECOND_PART])) { | ||
129 | + log.error("Unsupported parameter: {}", data[SECOND_PART]); | ||
130 | + return null; | ||
131 | + } | ||
129 | } | 132 | } |
130 | 133 | ||
131 | try { | 134 | try { |
132 | StringBuilder request = new StringBuilder(); | 135 | StringBuilder request = new StringBuilder(); |
133 | - request.append(ANGLE_LEFT).append(ONU_ETHPORT_LOOPBACK).append(SPACE); | 136 | + request.append(ANGLE_LEFT + ONU_ETHPORT_LOOPBACK + SPACE); |
134 | - request.append(VOLT_NE_NAMESPACE).append(ANGLE_RIGHT).append(NEW_LINE); | 137 | + request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE); |
135 | - request.append(buildStartTag(PONLINK_ID, false)); | 138 | + |
136 | - request.append(ethId[0]); | 139 | + request.append(buildStartTag(PONLINK_ID, false)) |
137 | - request.append(buildEndTag(PONLINK_ID)); | 140 | + .append(ethId[FIRST_PART]) |
138 | - request.append(buildStartTag(ONU_ID, false)); | 141 | + .append(buildEndTag(PONLINK_ID)) |
139 | - request.append(ethId[1]); | 142 | + .append(buildStartTag(ONU_ID, false)) |
140 | - request.append(buildEndTag(ONU_ID)); | 143 | + .append(ethId[SECOND_PART]) |
141 | - request.append(buildStartTag(ETHPORT_ID, false)); | 144 | + .append(buildEndTag(ONU_ID)) |
142 | - request.append(ethId[2]); | 145 | + .append(buildStartTag(ETHPORT_ID, false)) |
143 | - request.append(buildEndTag(ETHPORT_ID)); | 146 | + .append(ethId[THIRD_PART]) |
147 | + .append(buildEndTag(ETHPORT_ID)); | ||
148 | + if (data.length > ONE) { | ||
149 | + request.append(buildStartTag(LOOPBACK_MODE, false)) | ||
150 | + .append(data[SECOND_PART]) | ||
151 | + .append(buildEndTag(LOOPBACK_MODE)); | ||
152 | + } | ||
144 | request.append(buildEndTag(ONU_ETHPORT_LOOPBACK)); | 153 | request.append(buildEndTag(ONU_ETHPORT_LOOPBACK)); |
145 | 154 | ||
146 | - reply = controller. | 155 | + reply = controller |
147 | - getDevicesMap().get(ncDeviceId).getSession(). | 156 | + .getDevicesMap() |
148 | - doWrappedRpc(request.toString()); | 157 | + .get(ncDeviceId) |
158 | + .getSession() | ||
159 | + .doWrappedRpc(request.toString()); | ||
149 | } catch (IOException e) { | 160 | } catch (IOException e) { |
150 | - log.error("Cannot communicate to device {} exception ", ncDeviceId, e); | 161 | + log.error("Cannot communicate to device {} exception {}", ncDeviceId, e); |
151 | } | 162 | } |
152 | return reply; | 163 | return reply; |
153 | } | 164 | } |
154 | 165 | ||
166 | + /** | ||
167 | + * Verifies input string for ponlink-id{-onu-id}{-ethport-id}. | ||
168 | + * | ||
169 | + * @param target input data in string | ||
170 | + * @param expected number of IDs expected | ||
171 | + * @return String array containing IDs; may be null if an error is detected | ||
172 | + */ | ||
173 | + private String[] checkIdString(String target, int expected) { | ||
174 | + String[] id = target.split(HYPHEN); | ||
175 | + int pon; | ||
176 | + int onu; | ||
177 | + | ||
178 | + if (id.length < TWO) { | ||
179 | + log.error("Invalid number of arguments for id: {}", id.length); | ||
180 | + return null; | ||
181 | + } | ||
182 | + if (id.length != expected) { | ||
183 | + log.error("Invalid number of arguments for id: {}", id.length); | ||
184 | + return null; | ||
185 | + } | ||
186 | + try { | ||
187 | + pon = Integer.parseInt(id[FIRST_PART]); | ||
188 | + if (pon <= ZERO) { | ||
189 | + log.error("Invalid integer for ponlink-id: {}", id[FIRST_PART]); | ||
190 | + return null; | ||
191 | + } | ||
192 | + onu = Integer.parseInt(id[SECOND_PART]); | ||
193 | + if (onu <= ZERO) { | ||
194 | + log.error("Invalid integer for onu-id: {}", id[SECOND_PART]); | ||
195 | + return null; | ||
196 | + } | ||
197 | + if (expected > TWO) { | ||
198 | + int port = Integer.parseInt(id[THIRD_PART]); | ||
199 | + if (port <= ZERO) { | ||
200 | + log.error("Invalid integer for port-id: {}", id[THIRD_PART]); | ||
201 | + return null; | ||
202 | + } | ||
203 | + } | ||
204 | + } catch (NumberFormatException e) { | ||
205 | + log.error("Non-number input for id: {}", target); | ||
206 | + return null; | ||
207 | + } | ||
208 | + return id; | ||
209 | + } | ||
210 | + | ||
155 | } | 211 | } | ... | ... |
drivers/fujitsu/src/test/java/org/onosproject/drivers/fujitsu/FujitsuVoltOnuOperConfigTest.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 static org.junit.Assert.assertTrue; | ||
23 | +import static org.junit.Assert.assertNull; | ||
24 | +import static org.junit.Assert.assertNotNull; | ||
25 | +import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtilityMock.*; | ||
26 | + | ||
27 | +/** | ||
28 | + * Unit tests for methods of FujitsuVoltOnuOperConfig. | ||
29 | + */ | ||
30 | +public class FujitsuVoltOnuOperConfigTest { | ||
31 | + | ||
32 | + private final FujitsuNetconfSessionListenerTest listener = new InternalSessionListener(); | ||
33 | + | ||
34 | + private static final String TEST_ONU_REBOOT = "onu-reboot"; | ||
35 | + private static final String TEST_ONU_ETHPORT_LOOPBACK = "onu-ethport-loopback"; | ||
36 | + private static final String TEST_ETHPORT_ID = "ethport-id"; | ||
37 | + private static final String TEST_LOOPBACK_MODE = "mode"; | ||
38 | + | ||
39 | + private static final String TEST_ONU_REBOOT_WITH_NAMESPACE = TEST_ANGLE_LEFT + | ||
40 | + TEST_ONU_REBOOT + TEST_SPACE + TEST_VOLT_NE_NAMESPACE; | ||
41 | + private static final String TEST_ONU_ETHPORT_LOOPBACK_WITH_NAMESPACE = | ||
42 | + TEST_ANGLE_LEFT + TEST_ONU_ETHPORT_LOOPBACK + TEST_SPACE + | ||
43 | + TEST_VOLT_NE_NAMESPACE; | ||
44 | + | ||
45 | + private static final String[] INVALID_REBOOT_TCS = { | ||
46 | + "xy1-b", | ||
47 | + "--1", | ||
48 | + "s-1", | ||
49 | + "16-1-1", | ||
50 | + "&AA-1", | ||
51 | + "-1-1", | ||
52 | + }; | ||
53 | + private static final String[] VALID_REBOOT_TCS = { | ||
54 | + "1-2", | ||
55 | + "16-11", | ||
56 | + }; | ||
57 | + private static final String[] INVALID_ETHPORT_LOOPBACK_TCS = { | ||
58 | + "-11-3--11", | ||
59 | + "1-CCa", | ||
60 | + "abc-1", | ||
61 | + "^1-1-3", | ||
62 | + "1-2:23-1", | ||
63 | + "1:33:2", | ||
64 | + "2-2-2:false", | ||
65 | + }; | ||
66 | + private static final String[] VALID_ETHPORT_LOOPBACK_TCS = { | ||
67 | + "8-1-1", | ||
68 | + "1-11-3:release", | ||
69 | + "2-2-2:operate", | ||
70 | + }; | ||
71 | + private Integer currentKey; | ||
72 | + private FujitsuNetconfControllerMock controller; | ||
73 | + private FujitsuDriverHandlerAdapter driverHandler; | ||
74 | + private FujitsuVoltOnuOperConfig voltConfig; | ||
75 | + | ||
76 | + @Before | ||
77 | + public void setUp() throws Exception { | ||
78 | + controller = new FujitsuNetconfControllerMock(); | ||
79 | + driverHandler = controller.setUp(listener); | ||
80 | + voltConfig = new FujitsuVoltOnuOperConfig(); | ||
81 | + voltConfig.setHandler(driverHandler); | ||
82 | + } | ||
83 | + | ||
84 | + /** | ||
85 | + * Run to verify handling of invalid input for rpc operation. | ||
86 | + */ | ||
87 | + @Test | ||
88 | + public void testInvalidRebootOnuInput() throws Exception { | ||
89 | + String reply; | ||
90 | + String target; | ||
91 | + | ||
92 | + for (int i = ZERO; i < INVALID_REBOOT_TCS.length; i++) { | ||
93 | + target = INVALID_REBOOT_TCS[i]; | ||
94 | + reply = voltConfig.rebootOnu(target); | ||
95 | + assertNull("Incorrect response for INVALID_REBOOT_TCS", reply); | ||
96 | + } | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Run to verify handling of valid input for rpc operation. | ||
101 | + */ | ||
102 | + @Test | ||
103 | + public void testValidRebootOnu() throws Exception { | ||
104 | + String reply; | ||
105 | + String target; | ||
106 | + | ||
107 | + for (int i = ZERO; i < VALID_REBOOT_TCS.length; i++) { | ||
108 | + target = VALID_REBOOT_TCS[i]; | ||
109 | + currentKey = i; | ||
110 | + reply = voltConfig.rebootOnu(target); | ||
111 | + assertNotNull("Incorrect response for VALID_REBOOT_TCS", reply); | ||
112 | + } | ||
113 | + } | ||
114 | + | ||
115 | + /** | ||
116 | + * Run to verify handling of invalid input for rpc operation. | ||
117 | + */ | ||
118 | + @Test | ||
119 | + public void testInvalidEthLoopbackOnuInput() throws Exception { | ||
120 | + String target; | ||
121 | + String reply; | ||
122 | + | ||
123 | + for (int i = ZERO; i < INVALID_ETHPORT_LOOPBACK_TCS.length; i++) { | ||
124 | + target = INVALID_ETHPORT_LOOPBACK_TCS[i]; | ||
125 | + reply = voltConfig.loopbackEthOnu(target); | ||
126 | + assertNull("Incorrect response for INVALID_ETHPORT_LOOPBACK_TCS", reply); | ||
127 | + } | ||
128 | + } | ||
129 | + | ||
130 | + /** | ||
131 | + * Run to verify handling of valid input for rpc operation. | ||
132 | + */ | ||
133 | + @Test | ||
134 | + public void testValidLoopbackEthOnu() throws Exception { | ||
135 | + String target; | ||
136 | + String reply; | ||
137 | + | ||
138 | + for (int i = ZERO; i < VALID_ETHPORT_LOOPBACK_TCS.length; i++) { | ||
139 | + target = VALID_ETHPORT_LOOPBACK_TCS[i]; | ||
140 | + currentKey = i; | ||
141 | + reply = voltConfig.loopbackEthOnu(target); | ||
142 | + assertNotNull("Incorrect response for VALID_ETHPORT_LOOPBACK_TCS", reply); | ||
143 | + } | ||
144 | + } | ||
145 | + | ||
146 | + /** | ||
147 | + * Verifies XML request string by comparing with generated string. | ||
148 | + * | ||
149 | + * @param request XML string for rpc operation | ||
150 | + * @return true or false | ||
151 | + */ | ||
152 | + private boolean verifyWrappedRpcRequestForReboot(String request) { | ||
153 | + StringBuilder rpc = new StringBuilder(); | ||
154 | + String target = VALID_REBOOT_TCS[currentKey]; | ||
155 | + String[] data = target.split(TEST_COLON); | ||
156 | + String[] onuId = data[FIRST_PART].split(TEST_HYPHEN); | ||
157 | + | ||
158 | + rpc.append(TEST_ANGLE_LEFT + TEST_ONU_REBOOT + TEST_SPACE); | ||
159 | + rpc.append(TEST_VOLT_NE_NAMESPACE + TEST_ANGLE_RIGHT + TEST_NEW_LINE); | ||
160 | + | ||
161 | + rpc.append(startTag(TEST_PONLINK_ID, false)) | ||
162 | + .append(onuId[FIRST_PART]) | ||
163 | + .append(endTag(TEST_PONLINK_ID)) | ||
164 | + .append(startTag(TEST_ONU_ID, false)) | ||
165 | + .append(onuId[SECOND_PART]) | ||
166 | + .append(endTag(TEST_ONU_ID)) | ||
167 | + .append(endTag(TEST_ONU_REBOOT)); | ||
168 | + | ||
169 | + String testRequest = rpc.toString(); | ||
170 | + String regex = TEST_WHITESPACES_REGEX; | ||
171 | + int index = rpc.indexOf(regex); | ||
172 | + while (index >= ZERO) { | ||
173 | + testRequest = rpc.replace(index, index + regex.length(), TEST_EMPTY_STRING).toString(); | ||
174 | + request = request.replaceAll(regex, TEST_EMPTY_STRING); | ||
175 | + } | ||
176 | + boolean result = request.equals(testRequest); | ||
177 | + assertTrue("Does not match with generated string", result); | ||
178 | + return result; | ||
179 | + } | ||
180 | + | ||
181 | + /** | ||
182 | + * Verifies XML request string by comparing with generated string. | ||
183 | + * | ||
184 | + * @param request XML string for rpc operation | ||
185 | + * @return true or false | ||
186 | + */ | ||
187 | + private boolean verifyWrappedRpcRequestForEthLoopback(String request) { | ||
188 | + StringBuilder rpc = new StringBuilder(); | ||
189 | + String target = VALID_ETHPORT_LOOPBACK_TCS[currentKey]; | ||
190 | + String[] data = target.split(TEST_COLON); | ||
191 | + String[] ethId = data[FIRST_PART].split(TEST_HYPHEN); | ||
192 | + | ||
193 | + rpc.append(TEST_ANGLE_LEFT + TEST_ONU_ETHPORT_LOOPBACK + TEST_SPACE); | ||
194 | + rpc.append(TEST_VOLT_NE_NAMESPACE + TEST_ANGLE_RIGHT + TEST_NEW_LINE); | ||
195 | + | ||
196 | + rpc.append(startTag(TEST_PONLINK_ID, false)) | ||
197 | + .append(ethId[FIRST_PART]) | ||
198 | + .append(endTag(TEST_PONLINK_ID)) | ||
199 | + .append(startTag(TEST_ONU_ID, false)) | ||
200 | + .append(ethId[SECOND_PART]) | ||
201 | + .append(endTag(TEST_ONU_ID)) | ||
202 | + .append(startTag(TEST_ETHPORT_ID, false)) | ||
203 | + .append(ethId[THIRD_PART]) | ||
204 | + .append(endTag(TEST_ETHPORT_ID)); | ||
205 | + if (data.length > SECOND_PART) { | ||
206 | + rpc.append(startTag(TEST_LOOPBACK_MODE, false)) | ||
207 | + .append(data[SECOND_PART]) | ||
208 | + .append(endTag(TEST_LOOPBACK_MODE)); | ||
209 | + } | ||
210 | + rpc.append(endTag(TEST_ONU_ETHPORT_LOOPBACK)); | ||
211 | + | ||
212 | + String testRequest = rpc.toString(); | ||
213 | + String regex = TEST_WHITESPACES_REGEX; | ||
214 | + int index = rpc.indexOf(regex); | ||
215 | + while (index >= ZERO) { | ||
216 | + testRequest = rpc.replace(index, index + regex.length(), TEST_EMPTY_STRING).toString(); | ||
217 | + request = request.replaceAll(regex, TEST_EMPTY_STRING); | ||
218 | + } | ||
219 | + boolean result = request.equals(testRequest); | ||
220 | + assertTrue("Does not match with generated string", result); | ||
221 | + return result; | ||
222 | + } | ||
223 | + | ||
224 | + /** | ||
225 | + * Internal listener for device service events. | ||
226 | + */ | ||
227 | + private class InternalSessionListener implements FujitsuNetconfSessionListenerTest { | ||
228 | + @Override | ||
229 | + public boolean verifyEditConfig(String request) { | ||
230 | + return false; | ||
231 | + } | ||
232 | + | ||
233 | + @Override | ||
234 | + public boolean verifyEditConfig(String target, String mode, String request) { | ||
235 | + return false; | ||
236 | + } | ||
237 | + | ||
238 | + @Override | ||
239 | + public boolean verifyGet(String filterSchema, String withDefaultsMode) { | ||
240 | + return false; | ||
241 | + } | ||
242 | + | ||
243 | + @Override | ||
244 | + public String buildGetReply() { | ||
245 | + return null; | ||
246 | + } | ||
247 | + | ||
248 | + @Override | ||
249 | + public boolean verifyWrappedRpc(String request) { | ||
250 | + boolean result; | ||
251 | + boolean reboot = false; | ||
252 | + | ||
253 | + if (request.contains(TEST_ONU_REBOOT)) { | ||
254 | + request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE); | ||
255 | + assertTrue("Does not contain:" + TEST_ONU_REBOOT_WITH_NAMESPACE, | ||
256 | + request.contains(TEST_ONU_REBOOT_WITH_NAMESPACE)); | ||
257 | + reboot = true; | ||
258 | + } else { | ||
259 | + request = request.replaceAll(TEST_DUPLICATE_SPACES_REGEX, TEST_SPACE); | ||
260 | + assertTrue("Does not contain:" + TEST_ONU_ETHPORT_LOOPBACK_WITH_NAMESPACE, | ||
261 | + request.contains(TEST_ONU_ETHPORT_LOOPBACK_WITH_NAMESPACE)); | ||
262 | + } | ||
263 | + | ||
264 | + if (reboot) { | ||
265 | + result = verifyWrappedRpcRequestForReboot(request); | ||
266 | + } else { | ||
267 | + result = verifyWrappedRpcRequestForEthLoopback(request); | ||
268 | + } | ||
269 | + | ||
270 | + assertTrue("XML verification failure", result); | ||
271 | + return result; | ||
272 | + } | ||
273 | + | ||
274 | + @Override | ||
275 | + public void verifyStartSubscription(String filterSchema) { | ||
276 | + } | ||
277 | + } | ||
278 | + | ||
279 | +} |
... | @@ -58,6 +58,7 @@ final class FujitsuVoltXmlUtilityMock { | ... | @@ -58,6 +58,7 @@ final class FujitsuVoltXmlUtilityMock { |
58 | public static final int FIRST_PART = 0; | 58 | public static final int FIRST_PART = 0; |
59 | public static final int SECOND_PART = 1; | 59 | public static final int SECOND_PART = 1; |
60 | public static final int THIRD_PART = 2; | 60 | public static final int THIRD_PART = 2; |
61 | + public static final int ZERO = 0; | ||
61 | public static final int ONE = 1; | 62 | public static final int ONE = 1; |
62 | 63 | ||
63 | private FujitsuVoltXmlUtilityMock() { | 64 | private FujitsuVoltXmlUtilityMock() { | ... | ... |
-
Please register or login to post a comment