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