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