Shankara-Huawei | d5823ab | 2016-11-22 10:14:52 +0530 | [diff] [blame^] | 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.yms.app.ych; |
| 18 | |
| 19 | import org.junit.Test; |
| 20 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.CombinedOpParam; |
| 21 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.AsNum; |
| 22 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.Attributes; |
| 23 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.DefaultAttributes; |
| 24 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.Metric; |
| 25 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.PathId; |
| 26 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.Aigp; |
| 27 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.BgpParameters; |
| 28 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.DefaultAigp; |
| 29 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.DefaultBgpParameters; |
| 30 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.DefaultLocalPref; |
| 31 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.DefaultMultiExitDisc; |
| 32 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.DefaultOrigin; |
| 33 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.DefaultUnrecognizedAttributes; |
| 34 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.LocalPref; |
| 35 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.MultiExitDisc; |
| 36 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.Origin; |
| 37 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.UnrecognizedAttributes; |
| 38 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.aigp.AigpTlv; |
| 39 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.aigp.DefaultAigpTlv; |
| 40 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.bgpparameters.DefaultOptionalCapabilities; |
| 41 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.bgpparameters.OptionalCapabilities; |
| 42 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.bgpparameters.optionalcapabilities.Cparameters; |
| 43 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.bgpparameters.optionalcapabilities.DefaultCparameters; |
| 44 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.bgpparameters.optionalcapabilities.cparameters.As4BytesCapability; |
| 45 | import org.onosproject.yang.gen.v1.ych.combined.rev20160524.combined.attributes.bgpparameters.optionalcapabilities.cparameters.DefaultAs4BytesCapability; |
| 46 | import org.onosproject.yang.gen.v1.ych.empty.container.rev20160524.EmptyContainerOpParam; |
| 47 | import org.onosproject.yang.gen.v1.ych.empty.container.rev20160524.emptycontainer.EmptyContainer; |
| 48 | import org.onosproject.yang.gen.v1.ych.purchasing.supervisor.rev20160524.YchPurchasingsupervisorOpParam; |
| 49 | import org.onosproject.yang.gen.v1.ych.purchasing.supervisor.rev20160524.ychpurchasingsupervisor.DefaultYchPurchasingSupervisor; |
| 50 | import org.onosproject.yang.gen.v1.ych.purchasing.supervisor.rev20160524.ychpurchasingsupervisor.YchPurchasingSupervisor; |
| 51 | import org.onosproject.yang.gen.v1.ydt.customs.supervisor.rev20160524.CustomssupervisorOpParam; |
| 52 | import org.onosproject.yang.gen.v1.ydt.employee.id.rev20160524.EmployeeidOpParam; |
| 53 | import org.onosproject.yang.gen.v1.ydt.material.supervisor.rev20160524.MaterialsupervisorOpParam; |
| 54 | import org.onosproject.yang.gen.v1.ydt.material.supervisor.rev20160524.materialsupervisor.DefaultSupervisor; |
| 55 | import org.onosproject.yang.gen.v1.ydt.material.supervisor.rev20160524.materialsupervisor.Supervisor; |
| 56 | import org.onosproject.yang.gen.v1.ydt.merchandiser.supervisor.rev20160524.MerchandisersupervisorOpParam; |
| 57 | import org.onosproject.yang.gen.v1.ydt.root.rev20160524.LogisticsManagerOpParam; |
| 58 | import org.onosproject.yang.gen.v1.ydt.root.rev20160524.logisticsmanager.DefaultPurchasingSupervisor; |
| 59 | import org.onosproject.yang.gen.v1.ydt.trading.supervisor.rev20160524.TradingsupervisorOpParam; |
| 60 | import org.onosproject.yang.gen.v1.ydt.warehouse.supervisor.rev20160524.WarehousesupervisorOpParam; |
| 61 | import org.onosproject.yms.app.ych.defaultcodecs.YangCodecRegistry; |
| 62 | import org.onosproject.yms.app.ysr.DefaultYangSchemaRegistry; |
| 63 | import org.onosproject.yms.app.ysr.TestYangSchemaNodeProvider; |
| 64 | import org.onosproject.yms.ych.YangCompositeEncoding; |
| 65 | |
| 66 | import java.io.BufferedReader; |
| 67 | import java.io.FileReader; |
| 68 | import java.io.IOException; |
| 69 | import java.util.ArrayList; |
| 70 | import java.util.HashMap; |
| 71 | import java.util.Iterator; |
| 72 | import java.util.List; |
| 73 | import java.util.Map; |
| 74 | |
| 75 | import static org.junit.Assert.assertEquals; |
| 76 | import static org.junit.Assert.assertNull; |
| 77 | import static org.onosproject.yang.gen.v1.ydt.root.rev20160524.logisticsmanager.DefaultPurchasingSupervisor.OnosYangNodeOperationType.DELETE; |
| 78 | import static org.onosproject.yms.ych.YangProtocolEncodingFormat.XML; |
| 79 | import static org.onosproject.yms.ydt.YmsOperationType.EDIT_CONFIG_REQUEST; |
| 80 | import static org.onosproject.yms.ydt.YmsOperationType.QUERY_CONFIG_REQUEST; |
| 81 | import static org.onosproject.yms.ydt.YmsOperationType.QUERY_REQUEST; |
| 82 | |
| 83 | /** |
| 84 | * Unit test case for default codec handler. |
| 85 | */ |
| 86 | public class DefaultYangCodecHandlerTest { |
| 87 | private TestYangSchemaNodeProvider testYangSchemaNodeProvider = |
| 88 | new TestYangSchemaNodeProvider(); |
| 89 | private static final String AM_XML = "Incorrect XML generated: "; |
| 90 | private static final String AM_OBJ = "Incorrect object generated: "; |
| 91 | private static final String EMPTY_CONTAINER = "EmptyContainerOpParam"; |
| 92 | private static final String LOGISTIC_MOD = "LogisticsManagerOpParam"; |
| 93 | private static final String MERCHA_MOD = "MerchandisersupervisorOpParam"; |
| 94 | |
| 95 | /** |
| 96 | * Returns the xml string for customssupervisor module. |
| 97 | * |
| 98 | * @return the xml string for customssupervisor module |
| 99 | */ |
| 100 | private static String customsXml() { |
| 101 | return "<filter xmlns=\"ydt.filter-type\" type=\"subtree\">" + |
| 102 | "<customssupervisor xmlns=\"ydt.customs-supervisor\">" + |
| 103 | "<supervisor>Customssupervisor</supervisor>" + |
| 104 | "</customssupervisor>" + |
| 105 | "</filter>"; |
| 106 | } |
| 107 | |
| 108 | /** |
| 109 | * Returns the xml string for merchandisersupervisor module. |
| 110 | * |
| 111 | * @return the xml string for merchandisersupervisor module |
| 112 | */ |
| 113 | private static String merchandXml() { |
| 114 | return "<config xmlns=\"ydt.root\">" + |
| 115 | "<merchandisersupervisor xmlns=\"ydt.Merchandiser-" + |
| 116 | "supervisor\">" + |
| 117 | "<supervisor>Merchandisersupervisor</supervisor>" + |
| 118 | "</merchandisersupervisor>" + |
| 119 | "</config>"; |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Returns the xml string for tradingsupervisor module. |
| 124 | * |
| 125 | * @return the xml string for tradingsupervisor module |
| 126 | */ |
| 127 | private static String tradingXml() { |
| 128 | return "<config xmlns=\"ydt.root\">" + |
| 129 | "<tradingsupervisor xmlns=\"ydt.trading-supervisor\">" + |
| 130 | "<supervisor>Tradingsupervisor</supervisor>" + |
| 131 | "</tradingsupervisor>" + |
| 132 | "</config>"; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Returns the xml string for customssupervisor module. |
| 137 | * |
| 138 | * @return the xml string for customssupervisor module |
| 139 | */ |
| 140 | private static String customsCompositeXml() { |
| 141 | return "<filter xmlns=\"ydt.filter-type\"><customssupervisor " + |
| 142 | "xmlns=\"ydt.customs-supervisor\">" + |
| 143 | "<supervisor>Customssupervisor</supervisor>" + |
| 144 | "</customssupervisor></filter>"; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * Returns the xml string for customssupervisor module with filter-type. |
| 149 | * |
| 150 | * @return the xml string for customssupervisor module with filter-type |
| 151 | */ |
| 152 | private static String customsEmptyXml() { |
| 153 | return "<filter xmlns=\"ydt.filter-type\" type=\"subtree\">" + |
| 154 | "<customssupervisor xmlns=\"ydt.customs-supervisor\"/>" + |
| 155 | "</filter>"; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Returns the xml string for materialsupervisor module. |
| 160 | * |
| 161 | * @return the xml string for materialsupervisor module |
| 162 | */ |
| 163 | private static String materialXml() { |
| 164 | return "<filter xmlns=\"ydt.filter-type\" type=\"subtree\">" + |
| 165 | "<materialsupervisor xmlns=\"ydt.material-supervisor\">" + |
| 166 | "<supervisor>" + |
| 167 | "<name>abc1</name><departmentId>xyz1</departmentId>" + |
| 168 | "</supervisor>" + |
| 169 | "<supervisor><name>abc2</name><departmentId>xyz2</departmentId>" + |
| 170 | "</supervisor>" + |
| 171 | "<supervisor><name>abc3</name><departmentId>xyz3</departmentId>" + |
| 172 | "</supervisor>" + |
| 173 | "<supervisor><name>abc4</name><departmentId>xyz4</departmentId>" + |
| 174 | "</supervisor>" + |
| 175 | "<supervisor><name>abc5</name><departmentId>xyz5</departmentId>" + |
| 176 | "</supervisor>" + |
| 177 | "</materialsupervisor>" + |
| 178 | "</filter>"; |
| 179 | } |
| 180 | |
| 181 | /** |
| 182 | * Returns the xml string for EmptyContainer module. |
| 183 | * |
| 184 | * @return the xml string for EmptyContainer module |
| 185 | */ |
| 186 | private static String containerEmptyXml() { |
| 187 | return "<filter xmlns=\"ydt.filter-type\" type=\"subtree\">" + |
| 188 | "<EmptyContainer xmlns=\"ych.Empty.Container\"/>" + |
| 189 | "</filter>"; |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Returns the xml string for Combined module. |
| 194 | * |
| 195 | * @return the xml string for Combined module |
| 196 | */ |
| 197 | private static String listTestXml() { |
| 198 | return "<filter xmlns=\"ydt.filter-type\" type=\"subtree\">" + |
| 199 | "<Combined xmlns=\"ych:combined\"><attributes>" + |
| 200 | "<origin><value>123</value></origin>" + |
| 201 | "<multi-exit-disc><med>456</med></multi-exit-disc>" + |
| 202 | "<local-pref><pref>23</pref></local-pref>" + |
| 203 | "<aigp><aigp-tlv><metric>456</metric></aigp-tlv></aigp>" + |
| 204 | "<unrecognized-attributes><partial>false</partial>" + |
| 205 | "<transitive>false</transitive><type>1</type>" + |
| 206 | "<value>QUJD</value></unrecognized-attributes>" + |
| 207 | "<unrecognized-attributes><partial>true</partial>" + |
| 208 | "<transitive>true</transitive><type>2</type>" + |
| 209 | "<value>QUJD</value></unrecognized-attributes>" + |
| 210 | "<unrecognized-attributes><partial>true</partial>" + |
| 211 | "<transitive>false</transitive><type>3</type>" + |
| 212 | "<value>QUJD</value></unrecognized-attributes>" + |
| 213 | "<unrecognized-attributes><partial>false</partial>" + |
| 214 | "<transitive>true</transitive><type>4</type>" + |
| 215 | "<value>QUJD</value></unrecognized-attributes>" + |
| 216 | "<bgp-parameters><optional-capabilities><c-parameters>" + |
| 217 | "<as4-bytes-capability><as-number>11</as-number>" + |
| 218 | "</as4-bytes-capability></c-parameters>" + |
| 219 | "</optional-capabilities><optional-capabilities>" + |
| 220 | "<c-parameters><as4-bytes-capability>" + |
| 221 | "<as-number>22</as-number></as4-bytes-capability>" + |
| 222 | "</c-parameters></optional-capabilities>" + |
| 223 | "<optional-capabilities><c-parameters><as4-bytes-capability>" + |
| 224 | "<as-number>33</as-number></as4-bytes-capability>" + |
| 225 | "</c-parameters></optional-capabilities></bgp-parameters>" + |
| 226 | "<bgp-parameters><optional-capabilities><c-parameters>" + |
| 227 | "<as4-bytes-capability><as-number>11</as-number>" + |
| 228 | "</as4-bytes-capability></c-parameters>" + |
| 229 | "</optional-capabilities><optional-capabilities>" + |
| 230 | "<c-parameters><as4-bytes-capability>" + |
| 231 | "<as-number>22</as-number></as4-bytes-capability>" + |
| 232 | "</c-parameters></optional-capabilities>" + |
| 233 | "<optional-capabilities><c-parameters><as4-bytes-capability>" + |
| 234 | "<as-number>33</as-number></as4-bytes-capability>" + |
| 235 | "</c-parameters></optional-capabilities>" + |
| 236 | "</bgp-parameters></attributes></Combined></filter>"; |
| 237 | } |
| 238 | |
| 239 | /** |
| 240 | * Returns the xml string for ych-purchasingsupervisor module. |
| 241 | * |
| 242 | * @return the xml string for ych-purchasingsupervisor module |
| 243 | */ |
| 244 | private static String purchaseXml() { |
| 245 | return "<filter xmlns=\"ydt.filter-type\" type=\"subtree\">" + |
| 246 | "<ych-purchasingsupervisor xmlns=\"ych.purchasing-supervisor\">" + |
| 247 | "<ych-purchasing-supervisor operation=\"create\">" + |
| 248 | "<ych-purchasing-specialist>purchasingSpecialist" + |
| 249 | "</ych-purchasing-specialist>" + |
| 250 | "<ych-purchasing-support>support</ych-purchasing-support>" + |
| 251 | "</ych-purchasing-supervisor>" + |
| 252 | "</ych-purchasingsupervisor>" + |
| 253 | "</filter>"; |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Returns the xml string for employeeid module. |
| 258 | * |
| 259 | * @return the xml string for employeeid module |
| 260 | */ |
| 261 | private static String emplyIdXml() { |
| 262 | return "<config xmlns=\"ydt.root\">" + |
| 263 | "<employeeid xmlns=\"ydt.employee-id\">" + |
| 264 | "<employeeid>Employ1</employeeid>" + |
| 265 | "<employeeid>Employ5</employeeid>" + |
| 266 | "<employeeid>Employ4</employeeid>" + |
| 267 | "<employeeid>Employ3</employeeid>" + |
| 268 | "<employeeid>Employ2</employeeid>" + |
| 269 | "</employeeid>" + |
| 270 | "</config>"; |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Returns the xml string for warehousesupervisor module. |
| 275 | * |
| 276 | * @return the xml string for warehousesupervisor module |
| 277 | */ |
| 278 | private static String wareHseXml() { |
| 279 | return "<config xmlns=\"ydt.root\">" + |
| 280 | "<warehousesupervisor xmlns=\"ydt.warehouse-supervisor\">" + |
| 281 | "<supervisor>supervisor4</supervisor>" + |
| 282 | "<supervisor>supervisor5</supervisor>" + |
| 283 | "<supervisor>supervisor1</supervisor>" + |
| 284 | "<supervisor>supervisor2</supervisor>" + |
| 285 | "<supervisor>supervisor3</supervisor>" + |
| 286 | "</warehousesupervisor>" + |
| 287 | "</config>"; |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Returns the xml string for more than one module. |
| 292 | * |
| 293 | * @return the xml string for more than one module |
| 294 | */ |
| 295 | private static String multiModuleXml() { |
| 296 | return "<config xmlns=\"ydt.root\">" + |
| 297 | "<customssupervisor xmlns=\"ydt.customs-supervisor\">" + |
| 298 | "<supervisor>Customssupervisor</supervisor>" + |
| 299 | "</customssupervisor>" + |
| 300 | "<merchandisersupervisor xmlns=\"ydt.Merchandiser-supervisor\">" + |
| 301 | "<supervisor>Merchandisersupervisor</supervisor>" + |
| 302 | "</merchandisersupervisor>" + |
| 303 | "<materialsupervisor xmlns=\"ydt.material-supervisor\">" + |
| 304 | "<supervisor>" + |
| 305 | "<name>abc1</name>" + |
| 306 | "<departmentId>xyz1</departmentId>" + |
| 307 | "</supervisor>" + |
| 308 | "<supervisor>" + |
| 309 | "<name>abc2</name>" + |
| 310 | "<departmentId>xyz2</departmentId>" + |
| 311 | "</supervisor>" + |
| 312 | "<supervisor>" + |
| 313 | "<name>abc3</name>" + |
| 314 | "<departmentId>xyz3</departmentId>" + |
| 315 | "</supervisor>" + |
| 316 | "<supervisor>" + |
| 317 | "<name>abc4</name>" + |
| 318 | "<departmentId>xyz4</departmentId>" + |
| 319 | "</supervisor>" + |
| 320 | "<supervisor>" + |
| 321 | "<name>abc5</name>" + |
| 322 | "<departmentId>xyz5</departmentId>" + |
| 323 | "</supervisor>" + |
| 324 | "</materialsupervisor>" + |
| 325 | "<ych-purchasingsupervisor xmlns=\"ych.purchasing-supervisor\">" + |
| 326 | "<ych-purchasing-supervisor>" + |
| 327 | "<ych-purchasing-specialist>purchasingSpecialist" + |
| 328 | "</ych-purchasing-specialist>" + |
| 329 | "<ych-purchasing-support>support</ych-purchasing-support>" + |
| 330 | "</ych-purchasing-supervisor>" + |
| 331 | "</ych-purchasingsupervisor>" + |
| 332 | "<warehousesupervisor xmlns=\"ydt.warehouse-supervisor\">" + |
| 333 | "<supervisor>supervisor4</supervisor>" + |
| 334 | "<supervisor>supervisor5</supervisor>" + |
| 335 | "<supervisor>supervisor1</supervisor>" + |
| 336 | "<supervisor>supervisor2</supervisor>" + |
| 337 | "<supervisor>supervisor3</supervisor>" + |
| 338 | "</warehousesupervisor>" + |
| 339 | "<tradingsupervisor xmlns=\"ydt.trading-supervisor\">" + |
| 340 | "<supervisor>Tradingsupervisor</supervisor>" + |
| 341 | "</tradingsupervisor>" + |
| 342 | "<employeeid xmlns=\"ydt.employee-id\">" + |
| 343 | "<employeeid>Employ1</employeeid>" + |
| 344 | "<employeeid>Employ5</employeeid>" + |
| 345 | "<employeeid>Employ4</employeeid>" + |
| 346 | "<employeeid>Employ3</employeeid>" + |
| 347 | "<employeeid>Employ2</employeeid>" + |
| 348 | "</employeeid>" + |
| 349 | "</config>"; |
| 350 | } |
| 351 | |
| 352 | /** |
| 353 | * Unit test case in which verifying xml string for module object with leaf |
| 354 | * for composite encode. |
| 355 | */ |
| 356 | @Test |
| 357 | public void proceessCodecHandlerForCompositeEnc() { |
| 358 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 359 | DefaultYangSchemaRegistry schemaRegistry = testYangSchemaNodeProvider |
| 360 | .getDefaultYangSchemaRegistry(); |
| 361 | |
| 362 | // Creating the object |
| 363 | Object object = CustomssupervisorOpParam.builder() |
| 364 | .supervisor("Customssupervisor").build(); |
| 365 | |
| 366 | // Get the xml string and compare |
| 367 | Map<String, String> tagAttr = new HashMap<String, String>(); |
| 368 | tagAttr.put("type", "subtree"); |
| 369 | |
| 370 | YangCodecRegistry.initializeDefaultCodec(); |
| 371 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 372 | new DefaultYangCodecHandler(schemaRegistry); |
| 373 | YangCompositeEncoding xml = |
| 374 | defaultYangCodecHandler |
| 375 | .encodeCompositeOperation("filter", "ydt.filter-type", |
| 376 | object, XML, null); |
| 377 | |
| 378 | assertNull("customs-super: resource id not null", |
| 379 | xml.getResourceIdentifier()); |
| 380 | assertEquals(AM_XML + "customs-super: comp res info", |
| 381 | customsCompositeXml(), xml.getResourceInformation()); |
| 382 | |
| 383 | // Creating the object |
| 384 | object = MerchandisersupervisorOpParam.builder() |
| 385 | .supervisor("Merchandisersupervisor").build(); |
| 386 | |
| 387 | // Get the xml string and compare |
| 388 | xml = defaultYangCodecHandler.encodeCompositeOperation("config", |
| 389 | "ydt.root", |
| 390 | object, XML, |
| 391 | null); |
| 392 | assertNull("merch-super: res id not null", xml.getResourceIdentifier()); |
| 393 | assertEquals(AM_XML + "merch-super: comp res info", |
| 394 | merchandXml(), xml.getResourceInformation()); |
| 395 | |
| 396 | // Creating the object |
| 397 | object = TradingsupervisorOpParam.builder() |
| 398 | .supervisor("Tradingsupervisor").build(); |
| 399 | |
| 400 | // Get the xml string and compare |
| 401 | xml = defaultYangCodecHandler |
| 402 | .encodeCompositeOperation("config", "ydt.root", object, XML, |
| 403 | null); |
| 404 | assertNull("trading-super: res id not null", |
| 405 | xml.getResourceIdentifier()); |
| 406 | assertEquals(AM_XML + "trading-super: comp res info", |
| 407 | tradingXml(), xml.getResourceInformation()); |
| 408 | } |
| 409 | |
| 410 | /** |
| 411 | * Unit test case in which verifying xml string for module object with leaf. |
| 412 | */ |
| 413 | @Test |
| 414 | public void proceessCodecHandlerForLeaf() { |
| 415 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 416 | DefaultYangSchemaRegistry schemaRegistry = testYangSchemaNodeProvider |
| 417 | .getDefaultYangSchemaRegistry(); |
| 418 | List<Object> yangModuleList = new ArrayList<>(); |
| 419 | |
| 420 | // Creating the object |
| 421 | Object object = CustomssupervisorOpParam.builder() |
| 422 | .supervisor("Customssupervisor").build(); |
| 423 | yangModuleList.add(object); |
| 424 | |
| 425 | // Get the xml string and compare |
| 426 | Map<String, String> tagAttr = new HashMap<String, String>(); |
| 427 | tagAttr.put("type", "subtree"); |
| 428 | |
| 429 | YangCodecRegistry.initializeDefaultCodec(); |
| 430 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 431 | new DefaultYangCodecHandler(schemaRegistry); |
| 432 | String xml = |
| 433 | defaultYangCodecHandler.encodeOperation("filter", |
| 434 | "ydt.filter-type", |
| 435 | tagAttr, yangModuleList, |
| 436 | XML, null); |
| 437 | |
| 438 | assertEquals(AM_XML + "customs-super: leaf info", customsXml(), xml); |
| 439 | |
| 440 | // Creating the object |
| 441 | object = MerchandisersupervisorOpParam.builder() |
| 442 | .supervisor("Merchandisersupervisor").build(); |
| 443 | yangModuleList.clear(); |
| 444 | yangModuleList.add(object); |
| 445 | |
| 446 | // Get the xml string and compare |
| 447 | xml = defaultYangCodecHandler.encodeOperation("config", "ydt.root", |
| 448 | null, yangModuleList, |
| 449 | XML, null); |
| 450 | assertEquals(AM_XML + "merchandiser-super: leaf info", merchandXml(), |
| 451 | xml); |
| 452 | |
| 453 | // Creating the object |
| 454 | object = TradingsupervisorOpParam.builder() |
| 455 | .supervisor("Tradingsupervisor").build(); |
| 456 | yangModuleList.clear(); |
| 457 | yangModuleList.add(object); |
| 458 | |
| 459 | // Get the xml string and compare |
| 460 | xml = defaultYangCodecHandler.encodeOperation("config", "ydt.root", |
| 461 | null, yangModuleList, |
| 462 | XML, null); |
| 463 | assertEquals(AM_XML + "trading-super: leaf info", tradingXml(), xml); |
| 464 | } |
| 465 | |
| 466 | /** |
| 467 | * Unit test case in which verifying xml string for module object with |
| 468 | * empty leaf. |
| 469 | */ |
| 470 | @Test |
| 471 | public void proceessCodecHandlerForEmptyLeaf() { |
| 472 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 473 | DefaultYangSchemaRegistry schemaRegistry = testYangSchemaNodeProvider |
| 474 | .getDefaultYangSchemaRegistry(); |
| 475 | List<Object> yangModuleList = new ArrayList<>(); |
| 476 | |
| 477 | // Creating the object |
| 478 | Object object = CustomssupervisorOpParam.builder().supervisor("") |
| 479 | .build(); |
| 480 | yangModuleList.add(object); |
| 481 | |
| 482 | // Get the xml string and compare |
| 483 | Map<String, String> tagAttr = new HashMap<String, String>(); |
| 484 | tagAttr.put("type", "subtree"); |
| 485 | |
| 486 | YangCodecRegistry.initializeDefaultCodec(); |
| 487 | DefaultYangCodecHandler codecHandler = |
| 488 | new DefaultYangCodecHandler(schemaRegistry); |
| 489 | String xml = codecHandler.encodeOperation("filter", "ydt.filter-type", |
| 490 | tagAttr, yangModuleList, |
| 491 | XML, null); |
| 492 | |
| 493 | assertEquals(AM_XML + "customs-super: leaf is not empty", |
| 494 | customsEmptyXml(), xml); |
| 495 | } |
| 496 | |
| 497 | /** |
| 498 | * Unit test case in which verifying xml string for module object with list. |
| 499 | */ |
| 500 | @Test |
| 501 | public void proceessCodecHandlerForList() { |
| 502 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 503 | DefaultYangSchemaRegistry schemaRegistry = |
| 504 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 505 | List<Object> yangModuleList = new ArrayList<>(); |
| 506 | |
| 507 | // Creating the object |
| 508 | Supervisor supervisor1 = new DefaultSupervisor.SupervisorBuilder() |
| 509 | .name("abc1").departmentId("xyz1").build(); |
| 510 | Supervisor supervisor2 = new DefaultSupervisor.SupervisorBuilder() |
| 511 | .name("abc2").departmentId("xyz2").build(); |
| 512 | Supervisor supervisor3 = new DefaultSupervisor.SupervisorBuilder() |
| 513 | .name("abc3").departmentId("xyz3").build(); |
| 514 | Supervisor supervisor4 = new DefaultSupervisor.SupervisorBuilder() |
| 515 | .name("abc4").departmentId("xyz4").build(); |
| 516 | Supervisor supervisor5 = new DefaultSupervisor.SupervisorBuilder() |
| 517 | .name("abc5").departmentId("xyz5").build(); |
| 518 | |
| 519 | Object object = MaterialsupervisorOpParam.builder() |
| 520 | .addToSupervisor(supervisor1) |
| 521 | .addToSupervisor(supervisor2) |
| 522 | .addToSupervisor(supervisor3) |
| 523 | .addToSupervisor(supervisor4) |
| 524 | .addToSupervisor(supervisor5).build(); |
| 525 | |
| 526 | yangModuleList.add(object); |
| 527 | |
| 528 | // Get the xml string and compare |
| 529 | Map<String, String> tagAttr = new HashMap<String, String>(); |
| 530 | tagAttr.put("type", "subtree"); |
| 531 | |
| 532 | YangCodecRegistry.initializeDefaultCodec(); |
| 533 | DefaultYangCodecHandler codecHandler = |
| 534 | new DefaultYangCodecHandler(schemaRegistry); |
| 535 | String xml = codecHandler.encodeOperation("filter", "ydt.filter-type", |
| 536 | tagAttr, yangModuleList, |
| 537 | XML, null); |
| 538 | assertEquals(AM_XML + "material-super: list info", materialXml(), xml); |
| 539 | } |
| 540 | |
| 541 | /** |
| 542 | * Unit test case in which verifying xml string for module object with |
| 543 | * empty container. |
| 544 | */ |
| 545 | @Test |
| 546 | public void proceessCodecHandlerForEmptyContainer() { |
| 547 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 548 | DefaultYangSchemaRegistry schemaRegistry = |
| 549 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 550 | List<Object> yangModuleList = new ArrayList<>(); |
| 551 | |
| 552 | // Creating the object |
| 553 | EmptyContainer emptyContainer = EmptyContainerOpParam.builder() |
| 554 | .emptyContainer(); |
| 555 | Object object = EmptyContainerOpParam.builder() |
| 556 | .emptyContainer(emptyContainer).build(); |
| 557 | |
| 558 | yangModuleList.add(object); |
| 559 | |
| 560 | // Get the xml string and compare |
| 561 | Map<String, String> tagAttr = new HashMap<String, String>(); |
| 562 | tagAttr.put("type", "subtree"); |
| 563 | |
| 564 | YangCodecRegistry.initializeDefaultCodec(); |
| 565 | DefaultYangCodecHandler codecHandler = |
| 566 | new DefaultYangCodecHandler(schemaRegistry); |
| 567 | String xml = codecHandler.encodeOperation("filter", "ydt.filter-type", |
| 568 | tagAttr, yangModuleList, |
| 569 | XML, null); |
| 570 | assertEquals(AM_XML + "empty-contain: container is not empty", |
| 571 | containerEmptyXml(), xml); |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Unit test case in which verifying xml string for module object with list |
| 576 | * inside list. |
| 577 | */ |
| 578 | @Test |
| 579 | public void proceessCodecHandlerForListInsideList() { |
| 580 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 581 | DefaultYangSchemaRegistry schemaRegistry = |
| 582 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 583 | List<Object> yangModuleList = new ArrayList<>(); |
| 584 | |
| 585 | // Creating the object |
| 586 | PathId pathId = new PathId(123); |
| 587 | Origin origin = new DefaultOrigin.OriginBuilder().value(pathId) |
| 588 | .build(); |
| 589 | MultiExitDisc multiExitDisc = new DefaultMultiExitDisc |
| 590 | .MultiExitDiscBuilder().med(456).build(); |
| 591 | LocalPref localPref = new DefaultLocalPref.LocalPrefBuilder() |
| 592 | .pref(23).build(); |
| 593 | Metric metric = new Metric(456); |
| 594 | AigpTlv aigpTlv = new DefaultAigpTlv.AigpTlvBuilder().metric(metric) |
| 595 | .build(); |
| 596 | Aigp aigp = new DefaultAigp.AigpBuilder().aigpTlv(aigpTlv).build(); |
| 597 | |
| 598 | UnrecognizedAttributes unrecognizedAttributes1 = |
| 599 | new DefaultUnrecognizedAttributes |
| 600 | .UnrecognizedAttributesBuilder() |
| 601 | .partial(false).transitive(false).type((short) 1) |
| 602 | .value("ABC".getBytes()).build(); |
| 603 | |
| 604 | UnrecognizedAttributes unrecognizedAttributes2 = |
| 605 | new DefaultUnrecognizedAttributes |
| 606 | .UnrecognizedAttributesBuilder() |
| 607 | .partial(true).transitive(true).type((short) 2) |
| 608 | .value("ABC".getBytes()) |
| 609 | .build(); |
| 610 | |
| 611 | UnrecognizedAttributes unrecognizedAttributes3 = |
| 612 | new DefaultUnrecognizedAttributes |
| 613 | .UnrecognizedAttributesBuilder() |
| 614 | .partial(true).transitive(false).type((short) 3) |
| 615 | .value("ABC".getBytes()) |
| 616 | .build(); |
| 617 | |
| 618 | UnrecognizedAttributes unrecognizedAttributes4 = |
| 619 | new DefaultUnrecognizedAttributes |
| 620 | .UnrecognizedAttributesBuilder() |
| 621 | .partial(false).transitive(true).type((short) 4) |
| 622 | .value("ABC".getBytes()).build(); |
| 623 | |
| 624 | AsNum asNum1 = new AsNum(11); |
| 625 | As4BytesCapability as4BytesCapability1 = |
| 626 | new DefaultAs4BytesCapability.As4BytesCapabilityBuilder() |
| 627 | .asNumber(asNum1).build(); |
| 628 | Cparameters cparameters1 = new DefaultCparameters.CparametersBuilder() |
| 629 | .as4BytesCapability(as4BytesCapability1) |
| 630 | .build(); |
| 631 | OptionalCapabilities optionalCapabilities1 = |
| 632 | new DefaultOptionalCapabilities.OptionalCapabilitiesBuilder() |
| 633 | .cParameters(cparameters1).build(); |
| 634 | |
| 635 | AsNum asNum2 = new AsNum(22); |
| 636 | As4BytesCapability as4BytesCapability2 = |
| 637 | new DefaultAs4BytesCapability.As4BytesCapabilityBuilder() |
| 638 | .asNumber(asNum2).build(); |
| 639 | Cparameters cparameters2 = new DefaultCparameters.CparametersBuilder() |
| 640 | .as4BytesCapability(as4BytesCapability2) |
| 641 | .build(); |
| 642 | OptionalCapabilities optionalCapabilities2 = |
| 643 | new DefaultOptionalCapabilities.OptionalCapabilitiesBuilder() |
| 644 | .cParameters(cparameters2).build(); |
| 645 | |
| 646 | AsNum asNum3 = new AsNum(33); |
| 647 | As4BytesCapability as4BytesCapability3 = |
| 648 | new DefaultAs4BytesCapability.As4BytesCapabilityBuilder() |
| 649 | .asNumber(asNum3).build(); |
| 650 | Cparameters cparameters3 = new DefaultCparameters.CparametersBuilder() |
| 651 | .as4BytesCapability(as4BytesCapability3) |
| 652 | .build(); |
| 653 | OptionalCapabilities optionalCapabilities3 = |
| 654 | new DefaultOptionalCapabilities.OptionalCapabilitiesBuilder() |
| 655 | .cParameters(cparameters3).build(); |
| 656 | |
| 657 | BgpParameters bgpParameters1 = |
| 658 | new DefaultBgpParameters.BgpParametersBuilder() |
| 659 | .addToOptionalCapabilities(optionalCapabilities1) |
| 660 | .addToOptionalCapabilities(optionalCapabilities2) |
| 661 | .addToOptionalCapabilities(optionalCapabilities3) |
| 662 | .build(); |
| 663 | |
| 664 | AsNum asNum4 = new AsNum(11); |
| 665 | As4BytesCapability as4BytesCapability4 = new DefaultAs4BytesCapability |
| 666 | .As4BytesCapabilityBuilder() |
| 667 | .asNumber(asNum4).build(); |
| 668 | Cparameters cparameters4 = new DefaultCparameters.CparametersBuilder() |
| 669 | .as4BytesCapability(as4BytesCapability4) |
| 670 | .build(); |
| 671 | OptionalCapabilities optionalCapabilities4 = |
| 672 | new DefaultOptionalCapabilities.OptionalCapabilitiesBuilder() |
| 673 | .cParameters(cparameters4).build(); |
| 674 | |
| 675 | AsNum asNum5 = new AsNum(22); |
| 676 | As4BytesCapability as4BytesCapability5 = |
| 677 | new DefaultAs4BytesCapability.As4BytesCapabilityBuilder() |
| 678 | .asNumber(asNum5).build(); |
| 679 | Cparameters cparameters5 = |
| 680 | new DefaultCparameters.CparametersBuilder() |
| 681 | .as4BytesCapability(as4BytesCapability5) |
| 682 | .build(); |
| 683 | OptionalCapabilities optionalCapabilities5 = |
| 684 | new DefaultOptionalCapabilities.OptionalCapabilitiesBuilder() |
| 685 | .cParameters(cparameters5).build(); |
| 686 | |
| 687 | AsNum asNum6 = new AsNum(33); |
| 688 | As4BytesCapability as4BytesCapability6 = |
| 689 | new DefaultAs4BytesCapability.As4BytesCapabilityBuilder() |
| 690 | .asNumber(asNum6).build(); |
| 691 | Cparameters cparameters6 = |
| 692 | new DefaultCparameters.CparametersBuilder() |
| 693 | .as4BytesCapability(as4BytesCapability6) |
| 694 | .build(); |
| 695 | OptionalCapabilities optionalCapabilities6 = |
| 696 | new DefaultOptionalCapabilities.OptionalCapabilitiesBuilder() |
| 697 | .cParameters(cparameters6).build(); |
| 698 | |
| 699 | BgpParameters bgpParameters2 = |
| 700 | new DefaultBgpParameters.BgpParametersBuilder() |
| 701 | .addToOptionalCapabilities(optionalCapabilities4) |
| 702 | .addToOptionalCapabilities(optionalCapabilities5) |
| 703 | .addToOptionalCapabilities(optionalCapabilities6) |
| 704 | .build(); |
| 705 | |
| 706 | Attributes attributes = new DefaultAttributes.AttributesBuilder() |
| 707 | .origin(origin) |
| 708 | .multiExitDisc(multiExitDisc) |
| 709 | .localPref(localPref) |
| 710 | .aigp(aigp) |
| 711 | .addToUnrecognizedAttributes(unrecognizedAttributes1) |
| 712 | .addToUnrecognizedAttributes(unrecognizedAttributes2) |
| 713 | .addToUnrecognizedAttributes(unrecognizedAttributes3) |
| 714 | .addToUnrecognizedAttributes(unrecognizedAttributes4) |
| 715 | .addToBgpParameters(bgpParameters1) |
| 716 | .addToBgpParameters(bgpParameters2).build(); |
| 717 | Object object = CombinedOpParam.builder().attributes(attributes) |
| 718 | .build(); |
| 719 | |
| 720 | yangModuleList.add(object); |
| 721 | |
| 722 | // Get the xml string and compare |
| 723 | Map<String, String> tagAttr = new HashMap<String, String>(); |
| 724 | tagAttr.put("type", "subtree"); |
| 725 | |
| 726 | YangCodecRegistry.initializeDefaultCodec(); |
| 727 | DefaultYangCodecHandler codecHandler = |
| 728 | new DefaultYangCodecHandler(schemaRegistry); |
| 729 | String xml = codecHandler.encodeOperation("filter", "ydt.filter-type", |
| 730 | tagAttr, yangModuleList, |
| 731 | XML, null); |
| 732 | assertEquals(AM_XML + "combined: list info", listTestXml(), xml); |
| 733 | } |
| 734 | |
| 735 | /** |
| 736 | * Unit test case in which verifying xml string for module object with |
| 737 | * container. |
| 738 | */ |
| 739 | @Test |
| 740 | public void proceessCodecHandlerForContainer() { |
| 741 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 742 | DefaultYangSchemaRegistry schemaRegistry = |
| 743 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 744 | List<Object> yangModuleList = new ArrayList<>(); |
| 745 | |
| 746 | // Creating the object |
| 747 | YchPurchasingSupervisor supervisor = |
| 748 | new DefaultYchPurchasingSupervisor |
| 749 | .YchPurchasingSupervisorBuilder() |
| 750 | .ychPurchasingSpecialist("purchasingSpecialist") |
| 751 | .ychPurchasingSupport("support") |
| 752 | .onosYangNodeOperationType( |
| 753 | DefaultYchPurchasingSupervisor |
| 754 | .OnosYangNodeOperationType |
| 755 | .CREATE).build(); |
| 756 | Object object = YchPurchasingsupervisorOpParam.builder() |
| 757 | .ychPurchasingSupervisor(supervisor).build(); |
| 758 | yangModuleList.add(object); |
| 759 | |
| 760 | // Get the xml string and compare |
| 761 | Map<String, String> tagAttr = new HashMap<String, String>(); |
| 762 | tagAttr.put("type", "subtree"); |
| 763 | |
| 764 | YangCodecRegistry.initializeDefaultCodec(); |
| 765 | DefaultYangCodecHandler codecHandler = |
| 766 | new DefaultYangCodecHandler(schemaRegistry); |
| 767 | String xml = codecHandler.encodeOperation("filter", "ydt.filter-type", |
| 768 | tagAttr, yangModuleList, |
| 769 | XML, null); |
| 770 | assertEquals(AM_XML + "puchas-super: container info", purchaseXml(), |
| 771 | xml); |
| 772 | } |
| 773 | |
| 774 | |
| 775 | /** |
| 776 | * Unit test case in which verifying xml string for module object with |
| 777 | * leaf list. |
| 778 | */ |
| 779 | @Test |
| 780 | public void proceessCodecHandlerForLeafList() { |
| 781 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 782 | DefaultYangSchemaRegistry schemaRegistry = |
| 783 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 784 | List<Object> yangModuleList = new ArrayList<>(); |
| 785 | |
| 786 | // Creating the object |
| 787 | EmployeeidOpParam.EmployeeidBuilder employeeidBuilder = |
| 788 | EmployeeidOpParam.builder(); |
| 789 | employeeidBuilder.addToEmployeeid("Employ1"); |
| 790 | employeeidBuilder.addToEmployeeid("Employ2"); |
| 791 | employeeidBuilder.addToEmployeeid("Employ3"); |
| 792 | employeeidBuilder.addToEmployeeid("Employ4"); |
| 793 | employeeidBuilder.addToEmployeeid("Employ5"); |
| 794 | |
| 795 | Object object = employeeidBuilder.build(); |
| 796 | yangModuleList.add(object); |
| 797 | |
| 798 | // Get the xml string and compare |
| 799 | YangCodecRegistry.initializeDefaultCodec(); |
| 800 | DefaultYangCodecHandler codecHandler = |
| 801 | new DefaultYangCodecHandler(schemaRegistry); |
| 802 | String xml = codecHandler.encodeOperation("config", "ydt.root", null, |
| 803 | yangModuleList, XML, null); |
| 804 | assertEquals(AM_XML + "employ-id: leaf-list info", emplyIdXml(), xml); |
| 805 | WarehousesupervisorOpParam.WarehousesupervisorBuilder warehsebldr = |
| 806 | WarehousesupervisorOpParam.builder(); |
| 807 | warehsebldr.addToSupervisor("supervisor1"); |
| 808 | warehsebldr.addToSupervisor("supervisor2"); |
| 809 | warehsebldr.addToSupervisor("supervisor3"); |
| 810 | warehsebldr.addToSupervisor("supervisor4"); |
| 811 | warehsebldr.addToSupervisor("supervisor5"); |
| 812 | |
| 813 | object = warehsebldr.build(); |
| 814 | yangModuleList.clear(); |
| 815 | yangModuleList.add(object); |
| 816 | |
| 817 | |
| 818 | // Get the xml string and compare |
| 819 | xml = codecHandler.encodeOperation("config", "ydt.root", null, |
| 820 | yangModuleList, XML, null); |
| 821 | |
| 822 | assertEquals(AM_XML + "warehouse-super: leaf-list info", wareHseXml(), |
| 823 | xml); |
| 824 | } |
| 825 | |
| 826 | /** |
| 827 | * Unit test case in which verifying xml string for multiple module object. |
| 828 | */ |
| 829 | @Test |
| 830 | public void proceessCodecHandlerForMultipleModule() { |
| 831 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 832 | DefaultYangSchemaRegistry schemaRegistry = |
| 833 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 834 | |
| 835 | List<Object> yangModuleList = new ArrayList<>(); |
| 836 | YangCodecRegistry.initializeDefaultCodec(); |
| 837 | DefaultYangCodecHandler codecHandler = |
| 838 | new DefaultYangCodecHandler(schemaRegistry); |
| 839 | |
| 840 | // Creating the object for customssupervisor module |
| 841 | Object object = CustomssupervisorOpParam.builder() |
| 842 | .supervisor("Customssupervisor").build(); |
| 843 | yangModuleList.add(object); |
| 844 | |
| 845 | // Creating the object for merchandisersupervisor module |
| 846 | object = MerchandisersupervisorOpParam.builder() |
| 847 | .supervisor("Merchandisersupervisor").build(); |
| 848 | yangModuleList.add(object); |
| 849 | |
| 850 | // Creating the object for materialsupervisor module |
| 851 | Supervisor supervisor1 = new DefaultSupervisor.SupervisorBuilder() |
| 852 | .name("abc1").departmentId("xyz1").build(); |
| 853 | Supervisor supervisor2 = new DefaultSupervisor.SupervisorBuilder() |
| 854 | .name("abc2").departmentId("xyz2").build(); |
| 855 | Supervisor supervisor3 = new DefaultSupervisor.SupervisorBuilder() |
| 856 | .name("abc3").departmentId("xyz3").build(); |
| 857 | Supervisor supervisor4 = new DefaultSupervisor.SupervisorBuilder() |
| 858 | .name("abc4").departmentId("xyz4").build(); |
| 859 | Supervisor supervisor5 = new DefaultSupervisor.SupervisorBuilder() |
| 860 | .name("abc5").departmentId("xyz5").build(); |
| 861 | |
| 862 | object = MaterialsupervisorOpParam.builder() |
| 863 | .addToSupervisor(supervisor1) |
| 864 | .addToSupervisor(supervisor2) |
| 865 | .addToSupervisor(supervisor3) |
| 866 | .addToSupervisor(supervisor4) |
| 867 | .addToSupervisor(supervisor5).build(); |
| 868 | |
| 869 | yangModuleList.add(object); |
| 870 | |
| 871 | // Creating the object for YchPurchasingsupervisor module |
| 872 | YchPurchasingSupervisor purSupervisor = |
| 873 | new DefaultYchPurchasingSupervisor |
| 874 | .YchPurchasingSupervisorBuilder() |
| 875 | .ychPurchasingSpecialist("purchasingSpecialist") |
| 876 | .ychPurchasingSupport("support").build(); |
| 877 | object = YchPurchasingsupervisorOpParam.builder() |
| 878 | .ychPurchasingSupervisor(purSupervisor).build(); |
| 879 | yangModuleList.add(object); |
| 880 | |
| 881 | // Creating the object for warehousesupervisor module |
| 882 | WarehousesupervisorOpParam.WarehousesupervisorBuilder warehsebldr = |
| 883 | WarehousesupervisorOpParam.builder(); |
| 884 | warehsebldr.addToSupervisor("supervisor1"); |
| 885 | warehsebldr.addToSupervisor("supervisor2"); |
| 886 | warehsebldr.addToSupervisor("supervisor3"); |
| 887 | warehsebldr.addToSupervisor("supervisor4"); |
| 888 | warehsebldr.addToSupervisor("supervisor5"); |
| 889 | |
| 890 | object = warehsebldr.build(); |
| 891 | yangModuleList.add(object); |
| 892 | |
| 893 | // Creating the object for tradingsupervisor module |
| 894 | object = TradingsupervisorOpParam.builder() |
| 895 | .supervisor("Tradingsupervisor").build(); |
| 896 | yangModuleList.add(object); |
| 897 | |
| 898 | List<String> employeeid = EmployeeidOpParam.builder().employeeid(); |
| 899 | if (employeeid == null) { |
| 900 | employeeid = new ArrayList<>(); |
| 901 | } |
| 902 | employeeid.add("Employ1"); |
| 903 | employeeid.add("Employ2"); |
| 904 | employeeid.add("Employ3"); |
| 905 | employeeid.add("Employ4"); |
| 906 | employeeid.add("Employ5"); |
| 907 | |
| 908 | // Creating the object for employeeid module |
| 909 | object = EmployeeidOpParam.builder().employeeid(employeeid).build(); |
| 910 | yangModuleList.add(object); |
| 911 | |
| 912 | // Get the xml string and compare |
| 913 | String xml = codecHandler.encodeOperation("config", "ydt.root", null, |
| 914 | yangModuleList, XML, null); |
| 915 | assertEquals(AM_XML + "multiple: module info", multiModuleXml(), xml); |
| 916 | } |
| 917 | |
| 918 | /** |
| 919 | * Unit test case in which verifying object for xml string with config as |
| 920 | * root name and empty container. |
| 921 | */ |
| 922 | @Test |
| 923 | public void proceessCodecDecodeFunctionForEmptyContainer() { |
| 924 | String path = "src/test/resources/ychTestResourceFiles/getconfigemptycontainer.xml"; |
| 925 | StringBuilder sb = new StringBuilder(); |
| 926 | String sCurrentLine; |
| 927 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 928 | DefaultYangSchemaRegistry schemaRegistry = |
| 929 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 930 | |
| 931 | YangCodecRegistry.initializeDefaultCodec(); |
| 932 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 933 | new DefaultYangCodecHandler(schemaRegistry); |
| 934 | |
| 935 | try (BufferedReader br = new BufferedReader(new FileReader(path))) { |
| 936 | |
| 937 | while ((sCurrentLine = br.readLine()) != null) { |
| 938 | sb.append(sCurrentLine); |
| 939 | } |
| 940 | |
| 941 | } catch (IOException e) { |
| 942 | e.printStackTrace(); |
| 943 | } |
| 944 | |
| 945 | // Verify the received object list |
| 946 | List<Object> objectList = |
| 947 | defaultYangCodecHandler.decode(sb.toString(), |
| 948 | XML, QUERY_CONFIG_REQUEST); |
| 949 | Iterator<Object> iterator = objectList.iterator(); |
| 950 | while (iterator.hasNext()) { |
| 951 | Object object = iterator.next(); |
| 952 | if (object.getClass().getSimpleName() |
| 953 | .equals(EMPTY_CONTAINER)) { |
| 954 | EmptyContainerOpParam emptyContainerOpParam = |
| 955 | (EmptyContainerOpParam) object; |
| 956 | assertNull(AM_OBJ + "empty-container: container value is not" + |
| 957 | "null", |
| 958 | emptyContainerOpParam.emptyContainer()); |
| 959 | } else { |
| 960 | assertEquals(AM_OBJ, EMPTY_CONTAINER, object |
| 961 | .getClass().getSimpleName()); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
| 966 | |
| 967 | /** |
| 968 | * Unit test case in which verifying object for xml string with config as |
| 969 | * root name and multiple module. |
| 970 | */ |
| 971 | @Test |
| 972 | public void proceessCodecDecodeFunctionForListInsideList() { |
| 973 | String path = "src/test/resources/ychTestResourceFiles/combinedrootname.xml"; |
| 974 | StringBuilder sb = new StringBuilder(); |
| 975 | String sCurrentLine; |
| 976 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 977 | DefaultYangSchemaRegistry schemaRegistry = |
| 978 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 979 | |
| 980 | YangCodecRegistry.initializeDefaultCodec(); |
| 981 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 982 | new DefaultYangCodecHandler(schemaRegistry); |
| 983 | |
| 984 | try (BufferedReader br = new BufferedReader(new FileReader(path))) { |
| 985 | |
| 986 | while ((sCurrentLine = br.readLine()) != null) { |
| 987 | sb.append(sCurrentLine); |
| 988 | } |
| 989 | |
| 990 | } catch (IOException e) { |
| 991 | e.printStackTrace(); |
| 992 | } |
| 993 | |
| 994 | // TODO YOB and YTB need to do some changes for binary |
| 995 | // Verify the received object list |
| 996 | /*objectList = defaultYangCodecHandler.decode(sb.toString(), |
| 997 | XML_ENCODING, |
| 998 | EDIT_CONFIG_REQUEST); |
| 999 | Iterator<Object> iterator = objectList.iterator(); |
| 1000 | while (iterator.hasNext()) { |
| 1001 | Object object = iterator.next(); |
| 1002 | if (object.getClass().getSimpleName().equals("CombinedOpParam")) { |
| 1003 | CombinedOpParam combinedOpParam = (CombinedOpParam) object; |
| 1004 | |
| 1005 | PathId pathId = new PathId(123); |
| 1006 | Origin origin = new DefaultOrigin.OriginBuilder() |
| 1007 | .value(pathId).build(); |
| 1008 | assertTrue(combinedOpParam.attributes().origin() |
| 1009 | .equals(origin)); |
| 1010 | |
| 1011 | MultiExitDisc multiExitDisc = new DefaultMultiExitDisc |
| 1012 | .MultiExitDiscBuilder().med(456).build(); |
| 1013 | assertTrue(combinedOpParam.attributes().multiExitDisc() |
| 1014 | .equals(multiExitDisc)); |
| 1015 | |
| 1016 | LocalPref localPref = new DefaultLocalPref.LocalPrefBuilder() |
| 1017 | .pref(23).build(); |
| 1018 | assertTrue(combinedOpParam.attributes().localPref() |
| 1019 | .equals(localPref)); |
| 1020 | |
| 1021 | Metric metric = new Metric(456); |
| 1022 | AigpTlv aigpTlv = new DefaultAigpTlv.AigpTlvBuilder() |
| 1023 | .metric(metric).build(); |
| 1024 | Aigp aigp = new DefaultAigp.AigpBuilder().aigpTlv(aigpTlv) |
| 1025 | .build(); |
| 1026 | assertTrue(combinedOpParam.attributes().aigp().equals(aigp)); |
| 1027 | |
| 1028 | UnrecognizedAttributes unrecognizedAttributes1 = |
| 1029 | new DefaultUnrecognizedAttributes |
| 1030 | .UnrecognizedAttributesBuilder() |
| 1031 | .partial(false).transitive(false).type((short) 1) |
| 1032 | .value("ABC".getBytes()).build(); |
| 1033 | |
| 1034 | UnrecognizedAttributes unrecognizedAttributes2 = |
| 1035 | new DefaultUnrecognizedAttributes |
| 1036 | .UnrecognizedAttributesBuilder() |
| 1037 | .partial(true).transitive(true).type((short) 2) |
| 1038 | .value("BCA".getBytes()).build(); |
| 1039 | |
| 1040 | UnrecognizedAttributes unrecognizedAttributes3 = |
| 1041 | new DefaultUnrecognizedAttributes |
| 1042 | .UnrecognizedAttributesBuilder() |
| 1043 | .partial(true).transitive(false).type((short) 3) |
| 1044 | .value("CAB".getBytes()).build(); |
| 1045 | |
| 1046 | UnrecognizedAttributes unrecognizedAttributes4 = |
| 1047 | new DefaultUnrecognizedAttributes |
| 1048 | .UnrecognizedAttributesBuilder() |
| 1049 | .partial(false).transitive(true).type((short) 4) |
| 1050 | .value("111".getBytes()).build(); |
| 1051 | |
| 1052 | AsNum asNum1 = new AsNum(11); |
| 1053 | As4BytesCapability as4BytesCapability1 = |
| 1054 | new DefaultAs4BytesCapability |
| 1055 | .As4BytesCapabilityBuilder() |
| 1056 | .asNumber(asNum1).build(); |
| 1057 | Cparameters cparameters1 = new DefaultCparameters |
| 1058 | .CparametersBuilder() |
| 1059 | .as4BytesCapability(as4BytesCapability1) |
| 1060 | .build(); |
| 1061 | OptionalCapabilities optionalCapabilities1 = |
| 1062 | new DefaultOptionalCapabilities |
| 1063 | .OptionalCapabilitiesBuilder() |
| 1064 | .cParameters(cparameters1).build(); |
| 1065 | |
| 1066 | AsNum asNum2 = new AsNum(22); |
| 1067 | As4BytesCapability as4BytesCapability2 = |
| 1068 | new DefaultAs4BytesCapability |
| 1069 | .As4BytesCapabilityBuilder() |
| 1070 | .asNumber(asNum2).build(); |
| 1071 | Cparameters cparameters2 = new DefaultCparameters |
| 1072 | .CparametersBuilder() |
| 1073 | .as4BytesCapability(as4BytesCapability2) |
| 1074 | .build(); |
| 1075 | OptionalCapabilities optionalCapabilities2 = |
| 1076 | new DefaultOptionalCapabilities |
| 1077 | .OptionalCapabilitiesBuilder() |
| 1078 | .cParameters(cparameters2).build(); |
| 1079 | |
| 1080 | AsNum asNum3 = new AsNum(33); |
| 1081 | As4BytesCapability as4BytesCapability3 = |
| 1082 | new DefaultAs4BytesCapability |
| 1083 | .As4BytesCapabilityBuilder() |
| 1084 | .asNumber(asNum3).build(); |
| 1085 | Cparameters cparameters3 = |
| 1086 | new DefaultCparameters.CparametersBuilder() |
| 1087 | .as4BytesCapability(as4BytesCapability3) |
| 1088 | .build(); |
| 1089 | OptionalCapabilities optionalCapabilities3 = |
| 1090 | new DefaultOptionalCapabilities |
| 1091 | .OptionalCapabilitiesBuilder() |
| 1092 | .cParameters(cparameters3).build(); |
| 1093 | |
| 1094 | BgpParameters bgpParameters1 = |
| 1095 | new DefaultBgpParameters.BgpParametersBuilder() |
| 1096 | .addToOptionalCapabilities(optionalCapabilities1) |
| 1097 | .addToOptionalCapabilities(optionalCapabilities2) |
| 1098 | .addToOptionalCapabilities(optionalCapabilities3) |
| 1099 | .build(); |
| 1100 | |
| 1101 | AsNum asNum4 = new AsNum(11); |
| 1102 | As4BytesCapability as4BytesCapability4 = |
| 1103 | new DefaultAs4BytesCapability |
| 1104 | .As4BytesCapabilityBuilder() |
| 1105 | .asNumber(asNum4).build(); |
| 1106 | Cparameters cparameters4 = |
| 1107 | new DefaultCparameters.CparametersBuilder() |
| 1108 | .as4BytesCapability(as4BytesCapability4) |
| 1109 | .build(); |
| 1110 | OptionalCapabilities optionalCapabilities4 = |
| 1111 | new DefaultOptionalCapabilities |
| 1112 | .OptionalCapabilitiesBuilder() |
| 1113 | .cParameters(cparameters4).build(); |
| 1114 | |
| 1115 | AsNum asNum5 = new AsNum(22); |
| 1116 | As4BytesCapability as4BytesCapability5 = |
| 1117 | new DefaultAs4BytesCapability |
| 1118 | .As4BytesCapabilityBuilder() |
| 1119 | .asNumber(asNum5).build(); |
| 1120 | Cparameters cparameters5 = |
| 1121 | new DefaultCparameters.CparametersBuilder() |
| 1122 | .as4BytesCapability(as4BytesCapability5) |
| 1123 | .build(); |
| 1124 | OptionalCapabilities optionalCapabilities5 = |
| 1125 | new DefaultOptionalCapabilities |
| 1126 | .OptionalCapabilitiesBuilder() |
| 1127 | .cParameters(cparameters5).build(); |
| 1128 | |
| 1129 | AsNum asNum6 = new AsNum(33); |
| 1130 | As4BytesCapability as4BytesCapability6 = |
| 1131 | new DefaultAs4BytesCapability |
| 1132 | .As4BytesCapabilityBuilder() |
| 1133 | .asNumber(asNum6).build(); |
| 1134 | Cparameters cparameters6 = |
| 1135 | new DefaultCparameters.CparametersBuilder() |
| 1136 | .as4BytesCapability(as4BytesCapability6) |
| 1137 | .build(); |
| 1138 | OptionalCapabilities optionalCapabilities6 = |
| 1139 | new DefaultOptionalCapabilities |
| 1140 | .OptionalCapabilitiesBuilder() |
| 1141 | .cParameters(cparameters6).build(); |
| 1142 | |
| 1143 | BgpParameters bgpParameters2 = |
| 1144 | new DefaultBgpParameters.BgpParametersBuilder() |
| 1145 | .addToOptionalCapabilities(optionalCapabilities4) |
| 1146 | .addToOptionalCapabilities(optionalCapabilities5) |
| 1147 | .addToOptionalCapabilities(optionalCapabilities6) |
| 1148 | .build(); |
| 1149 | |
| 1150 | Attributes attributes = |
| 1151 | new DefaultAttributes.AttributesBuilder() |
| 1152 | .origin(origin) |
| 1153 | .multiExitDisc(multiExitDisc) |
| 1154 | .localPref(localPref) |
| 1155 | .aigp(aigp) |
| 1156 | .addToUnrecognizedAttributes(unrecognizedAttributes1) |
| 1157 | .addToUnrecognizedAttributes(unrecognizedAttributes2) |
| 1158 | .addToUnrecognizedAttributes(unrecognizedAttributes3) |
| 1159 | .addToUnrecognizedAttributes(unrecognizedAttributes4) |
| 1160 | .addToBgpParameters(bgpParameters1) |
| 1161 | .addToBgpParameters(bgpParameters2).build(); |
| 1162 | } else { |
| 1163 | assertTrue(false); |
| 1164 | } |
| 1165 | }*/ |
| 1166 | } |
| 1167 | |
| 1168 | /** |
| 1169 | * Unit test case in which verifying object for xml string with config as root name and |
| 1170 | * operation type. |
| 1171 | */ |
| 1172 | @Test |
| 1173 | public void proceessCodecDecodeFunctionForOperTypeTest() { |
| 1174 | String path = "src/test/resources/ychTestResourceFiles/configrootnameOperationType.xml"; |
| 1175 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 1176 | DefaultYangSchemaRegistry schemaRegistry = |
| 1177 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 1178 | |
| 1179 | YangCodecRegistry.initializeDefaultCodec(); |
| 1180 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 1181 | new DefaultYangCodecHandler(schemaRegistry); |
| 1182 | |
| 1183 | StringBuilder sb = new StringBuilder(); |
| 1184 | String sCurrentLine; |
| 1185 | |
| 1186 | try (BufferedReader br = new BufferedReader(new FileReader(path))) { |
| 1187 | |
| 1188 | while ((sCurrentLine = br.readLine()) != null) { |
| 1189 | sb.append(sCurrentLine); |
| 1190 | } |
| 1191 | |
| 1192 | } catch (IOException e) { |
| 1193 | e.printStackTrace(); |
| 1194 | } |
| 1195 | |
| 1196 | // Verify the received object list |
| 1197 | List<Object> objectList = |
| 1198 | defaultYangCodecHandler.decode(sb.toString(), |
| 1199 | XML, EDIT_CONFIG_REQUEST); |
| 1200 | Iterator<Object> iterator = objectList.iterator(); |
| 1201 | while (iterator.hasNext()) { |
| 1202 | Object object = iterator.next(); |
| 1203 | if (object.getClass().getSimpleName() |
| 1204 | .equals(LOGISTIC_MOD)) { |
| 1205 | LogisticsManagerOpParam logistics = |
| 1206 | (LogisticsManagerOpParam) object; |
| 1207 | DefaultPurchasingSupervisor purchasingSupervisor = |
| 1208 | (DefaultPurchasingSupervisor) logistics |
| 1209 | .purchasingSupervisor(); |
| 1210 | |
| 1211 | assertEquals(AM_OBJ + "purchase-super: operation type", DELETE, |
| 1212 | purchasingSupervisor.onosYangNodeOperationType()); |
| 1213 | assertEquals(AM_OBJ + "customs-super: leaf value", "abc", |
| 1214 | logistics.customsSupervisor()); |
| 1215 | assertEquals(AM_OBJ + "purchase-spec: leaf value", "bcd", |
| 1216 | logistics.purchasingSupervisor() |
| 1217 | .purchasingSpecialist()); |
| 1218 | assertEquals(AM_OBJ + "purchase-support: leaf value", |
| 1219 | "cde", logistics.purchasingSupervisor() |
| 1220 | .support()); |
| 1221 | |
| 1222 | } else if (object.getClass().getSimpleName() |
| 1223 | .equals(MERCHA_MOD)) { |
| 1224 | MerchandisersupervisorOpParam merchandisersupervisorOpParam = |
| 1225 | (MerchandisersupervisorOpParam) object; |
| 1226 | assertEquals(AM_OBJ + "merchandiser-super: leaf value", |
| 1227 | "abc", merchandisersupervisorOpParam.supervisor()); |
| 1228 | } else { |
| 1229 | assertEquals(AM_OBJ, LOGISTIC_MOD, object |
| 1230 | .getClass().getSimpleName()); |
| 1231 | assertEquals(AM_OBJ, MERCHA_MOD, object |
| 1232 | .getClass().getSimpleName()); |
| 1233 | } |
| 1234 | } |
| 1235 | } |
| 1236 | |
| 1237 | /** |
| 1238 | * Validate the leaf value for purchasing specialist. |
| 1239 | * |
| 1240 | * @param objectList object list |
| 1241 | */ |
| 1242 | private void processPurchasingSpecObj(List<Object> objectList) { |
| 1243 | Iterator<Object> iterator = objectList.iterator(); |
| 1244 | while (iterator.hasNext()) { |
| 1245 | Object object = iterator.next(); |
| 1246 | if (object.getClass().getSimpleName() |
| 1247 | .equals("LogisticsManagerOpParam")) { |
| 1248 | LogisticsManagerOpParam logisticsManagerOpParam = |
| 1249 | (LogisticsManagerOpParam) object; |
| 1250 | assertEquals(AM_OBJ + "purchasing-spec: leaf value", "bcd", |
| 1251 | logisticsManagerOpParam.purchasingSupervisor() |
| 1252 | .purchasingSpecialist()); |
| 1253 | } else { |
| 1254 | assertEquals(AM_OBJ, "LogisticsManagerOpParam", object |
| 1255 | .getClass().getSimpleName()); |
| 1256 | } |
| 1257 | } |
| 1258 | |
| 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * Validate the leaf value for merchandiser supervisor. |
| 1263 | * |
| 1264 | * @param objectList object list |
| 1265 | */ |
| 1266 | private void processMerchandiserObj(List<Object> objectList) { |
| 1267 | Iterator<Object> iterator = objectList.iterator(); |
| 1268 | while (iterator.hasNext()) { |
| 1269 | Object object = iterator.next(); |
| 1270 | if (object.getClass().getSimpleName() |
| 1271 | .equals(MERCHA_MOD)) { |
| 1272 | MerchandisersupervisorOpParam merchandisersupervisorOpParam = |
| 1273 | (MerchandisersupervisorOpParam) object; |
| 1274 | assertEquals(AM_OBJ + "merchandiser-super: leaf value", "abc", |
| 1275 | merchandisersupervisorOpParam.supervisor()); |
| 1276 | |
| 1277 | } else { |
| 1278 | assertEquals(AM_OBJ, MERCHA_MOD, object |
| 1279 | .getClass().getSimpleName()); |
| 1280 | } |
| 1281 | } |
| 1282 | } |
| 1283 | |
| 1284 | /** |
| 1285 | * Unit test case in which verifying object for xml string with get and |
| 1286 | * filter as root name. |
| 1287 | */ |
| 1288 | @Test |
| 1289 | public void proceessCodecDecodeFunctionForGet() { |
| 1290 | String path = "src/test/resources/ychTestResourceFiles/getrootname.xml"; |
| 1291 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 1292 | DefaultYangSchemaRegistry schemaRegistry = |
| 1293 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 1294 | |
| 1295 | YangCodecRegistry.initializeDefaultCodec(); |
| 1296 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 1297 | new DefaultYangCodecHandler(schemaRegistry); |
| 1298 | |
| 1299 | StringBuilder sb = new StringBuilder(); |
| 1300 | String sCurrentLine; |
| 1301 | |
| 1302 | try (BufferedReader br = new BufferedReader(new FileReader(path))) { |
| 1303 | |
| 1304 | while ((sCurrentLine = br.readLine()) != null) { |
| 1305 | sb.append(sCurrentLine); |
| 1306 | } |
| 1307 | |
| 1308 | } catch (IOException e) { |
| 1309 | e.printStackTrace(); |
| 1310 | } |
| 1311 | |
| 1312 | // Verify the received object list |
| 1313 | List<Object> objectList = |
| 1314 | defaultYangCodecHandler.decode(sb.toString(), |
| 1315 | XML, QUERY_REQUEST); |
| 1316 | processPurchasingSpecObj(objectList); |
| 1317 | } |
| 1318 | |
| 1319 | /** |
| 1320 | * Unit test case in which verifying object for xml string with get-config |
| 1321 | * and filter as root name. |
| 1322 | */ |
| 1323 | @Test |
| 1324 | public void proceessCodecDecodeFunctionForGetConfig() { |
| 1325 | String path = "src/test/resources/ychTestResourceFiles/getconfigrootname.xml"; |
| 1326 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 1327 | DefaultYangSchemaRegistry schemaRegistry = |
| 1328 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 1329 | |
| 1330 | YangCodecRegistry.initializeDefaultCodec(); |
| 1331 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 1332 | new DefaultYangCodecHandler(schemaRegistry); |
| 1333 | |
| 1334 | StringBuilder sb = new StringBuilder(); |
| 1335 | String sCurrentLine; |
| 1336 | |
| 1337 | try (BufferedReader br = new BufferedReader(new FileReader(path))) { |
| 1338 | |
| 1339 | while ((sCurrentLine = br.readLine()) != null) { |
| 1340 | sb.append(sCurrentLine); |
| 1341 | } |
| 1342 | |
| 1343 | } catch (IOException e) { |
| 1344 | e.printStackTrace(); |
| 1345 | } |
| 1346 | |
| 1347 | // Verify the received object list |
| 1348 | List<Object> objectList = defaultYangCodecHandler.decode( |
| 1349 | sb.toString(), |
| 1350 | XML, QUERY_CONFIG_REQUEST); |
| 1351 | processMerchandiserObj(objectList); |
| 1352 | } |
| 1353 | |
| 1354 | /** |
| 1355 | * Unit test case in which verifying object for xml string with data as |
| 1356 | * root name. |
| 1357 | */ |
| 1358 | @Test |
| 1359 | public void proceessCodecDecodeFunctionForGetData() { |
| 1360 | String path = "src/test/resources/ychTestResourceFiles/getReply.xml"; |
| 1361 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 1362 | DefaultYangSchemaRegistry schemaRegistry = |
| 1363 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 1364 | |
| 1365 | YangCodecRegistry.initializeDefaultCodec(); |
| 1366 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 1367 | new DefaultYangCodecHandler(schemaRegistry); |
| 1368 | |
| 1369 | StringBuilder sb = new StringBuilder(); |
| 1370 | String sCurrentLine; |
| 1371 | |
| 1372 | try (BufferedReader br = new BufferedReader(new FileReader(path))) { |
| 1373 | |
| 1374 | while ((sCurrentLine = br.readLine()) != null) { |
| 1375 | sb.append(sCurrentLine); |
| 1376 | } |
| 1377 | |
| 1378 | } catch (IOException e) { |
| 1379 | e.printStackTrace(); |
| 1380 | } |
| 1381 | |
| 1382 | // Verify the received object list |
| 1383 | List<Object> objectList = defaultYangCodecHandler.decode( |
| 1384 | sb.toString(), |
| 1385 | XML, QUERY_CONFIG_REQUEST); |
| 1386 | processPurchasingSpecObj(objectList); |
| 1387 | } |
| 1388 | |
| 1389 | /** |
| 1390 | * Unit test case in which verifying object for xml string with rpc-reply |
| 1391 | * and data as root name . |
| 1392 | */ |
| 1393 | @Test |
| 1394 | public void proceessCodecDecodeFunctionForGetConfigData() { |
| 1395 | String path = "src/test/resources/ychTestResourceFiles/getconfigReply.xml"; |
| 1396 | testYangSchemaNodeProvider.processSchemaRegistry(null); |
| 1397 | DefaultYangSchemaRegistry schemaRegistry = |
| 1398 | testYangSchemaNodeProvider.getDefaultYangSchemaRegistry(); |
| 1399 | |
| 1400 | YangCodecRegistry.initializeDefaultCodec(); |
| 1401 | DefaultYangCodecHandler defaultYangCodecHandler = |
| 1402 | new DefaultYangCodecHandler(schemaRegistry); |
| 1403 | |
| 1404 | StringBuilder sb = new StringBuilder(); |
| 1405 | String sCurrentLine; |
| 1406 | |
| 1407 | try (BufferedReader br = new BufferedReader(new FileReader(path))) { |
| 1408 | |
| 1409 | while ((sCurrentLine = br.readLine()) != null) { |
| 1410 | sb.append(sCurrentLine); |
| 1411 | } |
| 1412 | |
| 1413 | } catch (IOException e) { |
| 1414 | e.printStackTrace(); |
| 1415 | } |
| 1416 | |
| 1417 | // Verify the received object list |
| 1418 | List<Object> objectList = defaultYangCodecHandler.decode(sb.toString(), |
| 1419 | XML, null); |
| 1420 | processMerchandiserObj(objectList); |
| 1421 | } |
| 1422 | } |