Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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.yangutils.parser.impl.listeners; |
| 18 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 19 | import java.io.IOException; |
| 20 | import java.util.ListIterator; |
| 21 | |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 22 | import org.junit.Rule; |
| 23 | import org.junit.Test; |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 24 | import org.junit.rules.ExpectedException; |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 25 | import org.onosproject.yangutils.datamodel.YangContainer; |
| 26 | import org.onosproject.yangutils.datamodel.YangDataTypes; |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 27 | import org.onosproject.yangutils.datamodel.YangLeaf; |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 28 | import org.onosproject.yangutils.datamodel.YangLeafList; |
| 29 | import org.onosproject.yangutils.datamodel.YangList; |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 30 | import org.onosproject.yangutils.datamodel.YangModule; |
| 31 | import org.onosproject.yangutils.datamodel.YangNode; |
| 32 | import org.onosproject.yangutils.datamodel.YangNodeType; |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 33 | import org.onosproject.yangutils.datamodel.YangStatusType; |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 34 | import org.onosproject.yangutils.parser.exceptions.ParserException; |
| 35 | import org.onosproject.yangutils.parser.impl.YangUtilsParserManager; |
| 36 | |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 37 | import static org.hamcrest.MatcherAssert.assertThat; |
| 38 | import static org.hamcrest.core.Is.is; |
| 39 | |
| 40 | /** |
| 41 | * Test cases for config listener. |
| 42 | */ |
| 43 | public class ConfigListenerTest { |
| 44 | |
| 45 | @Rule |
| 46 | public ExpectedException thrown = ExpectedException.none(); |
| 47 | |
| 48 | private final YangUtilsParserManager manager = new YangUtilsParserManager(); |
| 49 | |
| 50 | /** |
| 51 | * Checks valid config statement. |
| 52 | */ |
| 53 | @Test |
| 54 | public void processConfigTrue() throws IOException, ParserException { |
| 55 | |
| 56 | YangNode node = manager.getDataModel("src/test/resources/ConfigTrue.yang"); |
| 57 | |
| 58 | // Check whether the data model tree returned is of type module. |
| 59 | assertThat((node instanceof YangModule), is(true)); |
| 60 | |
| 61 | // Check whether the node type is set properly to module. |
| 62 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 63 | |
| 64 | // Check whether the module name is set correctly. |
| 65 | YangModule yangNode = (YangModule) node; |
| 66 | assertThat(yangNode.getName(), is("Test")); |
| 67 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 68 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 69 | YangLeaf leafInfo = leafIterator.next(); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 70 | |
| 71 | // Check whether the Config value is set correctly. |
| 72 | assertThat(leafInfo.getLeafName(), is("invalid-interval")); |
| 73 | assertThat(leafInfo.isConfig(), is(true)); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Checks valid config statement. |
| 78 | */ |
| 79 | @Test |
| 80 | public void processConfigFalse() throws IOException, ParserException { |
| 81 | |
| 82 | YangNode node = manager.getDataModel("src/test/resources/ConfigFalse.yang"); |
| 83 | |
| 84 | // Check whether the data model tree returned is of type module. |
| 85 | assertThat((node instanceof YangModule), is(true)); |
| 86 | |
| 87 | // Check whether the node type is set properly to module. |
| 88 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 89 | |
| 90 | // Check whether the module name is set correctly. |
| 91 | YangModule yangNode = (YangModule) node; |
| 92 | assertThat(yangNode.getName(), is("Test")); |
| 93 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 94 | ListIterator<YangLeaf> leafIterator = yangNode.getListOfLeaf().listIterator(); |
| 95 | YangLeaf leafInfo = leafIterator.next(); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 96 | |
| 97 | // Check whether the Config value is set correctly. |
| 98 | assertThat(leafInfo.getLeafName(), is("invalid-interval")); |
| 99 | assertThat(leafInfo.isConfig(), is(false)); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Checks invalid config statement and expects parser exception. |
| 104 | */ |
| 105 | @Test |
| 106 | public void processConfigWithoutStatementEnd() throws IOException, ParserException { |
| 107 | thrown.expect(ParserException.class); |
| 108 | thrown.expectMessage("missing ';' at '}'"); |
| 109 | YangNode node = manager.getDataModel("src/test/resources/ConfigWithoutStatementEnd.yang"); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * Checks invalid config statement and expects parser exception. |
| 114 | */ |
| 115 | @Test |
| 116 | public void processConfigInvalidValue() throws IOException, ParserException { |
| 117 | thrown.expect(ParserException.class); |
Vidyashree Rama | e68bb19 | 2016-03-15 10:18:25 +0530 | [diff] [blame] | 118 | thrown.expectMessage("YANG file error : config value invalid is not valid."); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 119 | YangNode node = manager.getDataModel("src/test/resources/ConfigInvalidValue.yang"); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Checks invalid config statement and expects parser exception. |
| 124 | */ |
| 125 | @Test |
| 126 | public void processConfigEmptyValue() throws IOException, ParserException { |
| 127 | thrown.expect(ParserException.class); |
Vidyashree Rama | e68bb19 | 2016-03-15 10:18:25 +0530 | [diff] [blame] | 128 | thrown.expectMessage("no viable alternative at input ';'"); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 129 | YangNode node = manager.getDataModel("src/test/resources/ConfigEmptyValue.yang"); |
| 130 | } |
| 131 | |
| 132 | /** |
| 133 | * Checks config statement as sub-statement of module. |
| 134 | */ |
| 135 | @Test |
| 136 | public void processModuleSubStatementConfig() throws IOException, ParserException { |
| 137 | thrown.expect(ParserException.class); |
Bharat saraswal | 9745996 | 2016-02-20 21:57:16 +0530 | [diff] [blame] | 138 | thrown.expectMessage("mismatched input 'config' expecting {'augment', 'choice', 'contact', 'container'," |
| 139 | + " 'description', 'extension', 'deviation', 'feature', 'grouping', 'identity', 'import', 'include', " |
Vidyashree Rama | 07021a2 | 2016-03-09 20:41:44 +0530 | [diff] [blame] | 140 | + "'leaf', 'leaf-list', 'list', 'notification', 'organization', 'reference'," |
| 141 | + " 'revision', 'rpc', 'typedef', 'uses', '}'}"); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 142 | YangNode node = manager.getDataModel("src/test/resources/ModuleSubStatementConfig.yang"); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Checks config statement as sub-statement of container. |
| 147 | */ |
| 148 | @Test |
| 149 | public void processContainerSubStatementConfig() throws IOException, ParserException { |
| 150 | |
| 151 | YangNode node = manager.getDataModel("src/test/resources/ContainerSubStatementConfig.yang"); |
| 152 | |
| 153 | // Check whether the data model tree returned is of type module. |
| 154 | assertThat((node instanceof YangModule), is(true)); |
| 155 | |
| 156 | // Check whether the node type is set properly to module. |
| 157 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 158 | |
| 159 | // Check whether the module name is set correctly. |
| 160 | YangModule yangNode = (YangModule) node; |
| 161 | assertThat(yangNode.getName(), is("Test")); |
| 162 | |
| 163 | // Check whether the config value is set correctly. |
| 164 | YangContainer container = (YangContainer) yangNode.getChild(); |
| 165 | assertThat(container.getName(), is("valid")); |
| 166 | assertThat(container.isConfig(), is(true)); |
| 167 | |
| 168 | // Check whether leaf properties as set correctly. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 169 | ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); |
| 170 | YangLeaf leafInfo = leafIterator.next(); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 171 | |
| 172 | assertThat(leafInfo.getLeafName(), is("invalid-interval")); |
| 173 | assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); |
| 174 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); |
| 175 | assertThat(leafInfo.getUnits(), is("\"seconds\"")); |
| 176 | assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); |
| 177 | assertThat(leafInfo.isMandatory(), is(true)); |
| 178 | assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT)); |
| 179 | assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * Checks config statement as sub-statement of list. |
| 184 | */ |
| 185 | @Test |
| 186 | public void processListSubStatementConfig() throws IOException, ParserException { |
| 187 | |
| 188 | YangNode node = manager.getDataModel("src/test/resources/ListSubStatementConfig.yang"); |
| 189 | |
| 190 | assertThat((node instanceof YangModule), is(true)); |
| 191 | |
| 192 | // Check whether the node type is set properly to module. |
| 193 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 194 | |
| 195 | // Check whether the module name is set correctly. |
| 196 | YangModule yangNode = (YangModule) node; |
| 197 | assertThat(yangNode.getName(), is("Test")); |
| 198 | |
| 199 | // Check whether the list is child of module and config value is set. |
| 200 | YangList yangList = (YangList) yangNode.getChild(); |
| 201 | assertThat(yangList.getName(), is("valid")); |
| 202 | assertThat(yangList.isConfig(), is(true)); |
| 203 | |
| 204 | // Check whether leaf properties as set correctly. |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 205 | ListIterator<YangLeaf> leafIterator = yangList.getListOfLeaf().listIterator(); |
| 206 | YangLeaf leafInfo = leafIterator.next(); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 207 | |
| 208 | assertThat(leafInfo.getLeafName(), is("invalid-interval")); |
| 209 | assertThat(leafInfo.getDataType().getDataTypeName(), is("\"uint16\"")); |
| 210 | assertThat(leafInfo.getDataType().getDataType(), is(YangDataTypes.UINT16)); |
| 211 | assertThat(leafInfo.getUnits(), is("\"seconds\"")); |
| 212 | assertThat(leafInfo.getDescription(), is("\"Interval before a route is declared invalid\"")); |
| 213 | assertThat(leafInfo.isMandatory(), is(true)); |
| 214 | assertThat(leafInfo.getStatus(), is(YangStatusType.CURRENT)); |
| 215 | assertThat(leafInfo.getReference(), is("\"RFC 6020\"")); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * Checks valid config statement as sub-statement of leaf-list. |
| 220 | */ |
| 221 | @Test |
| 222 | public void processLeafListSubStatementConfig() throws IOException, ParserException { |
| 223 | |
| 224 | YangNode node = manager.getDataModel("src/test/resources/LeafListSubStatementConfig.yang"); |
| 225 | |
| 226 | // Check whether the data model tree returned is of type module. |
| 227 | assertThat((node instanceof YangModule), is(true)); |
| 228 | |
| 229 | // Check whether the node type is set properly to module. |
| 230 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 231 | |
| 232 | // Check whether the module name is set correctly. |
| 233 | YangModule yangNode = (YangModule) node; |
| 234 | assertThat(yangNode.getName(), is("Test")); |
| 235 | |
Vinod Kumar S | c26bf19 | 2016-02-23 22:36:57 +0530 | [diff] [blame] | 236 | ListIterator<YangLeafList> leafListIterator = yangNode.getListOfLeafList().listIterator(); |
| 237 | YangLeafList leafListInfo = leafListIterator.next(); |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 238 | |
| 239 | // Check whether config value is set correctly. |
| 240 | assertThat(leafListInfo.getLeafName(), is("invalid-interval")); |
| 241 | assertThat(leafListInfo.isConfig(), is(true)); |
| 242 | } |
Vidyashree Rama | f67c4ba | 2016-02-24 12:28:22 +0530 | [diff] [blame] | 243 | |
| 244 | /** |
| 245 | * Checks config statement's default Value. |
| 246 | */ |
| 247 | @Test |
| 248 | public void processConfigDefaultValue() throws IOException, ParserException { |
| 249 | |
| 250 | YangNode node = manager.getDataModel("src/test/resources/ConfigDefaultValue.yang"); |
| 251 | |
| 252 | assertThat((node instanceof YangModule), is(true)); |
| 253 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 254 | YangModule yangNode = (YangModule) node; |
| 255 | assertThat(yangNode.getName(), is("Test")); |
| 256 | |
| 257 | // Check whether the config value is set correctly. |
| 258 | YangContainer container = (YangContainer) yangNode.getChild(); |
| 259 | assertThat(container.getName(), is("valid")); |
| 260 | assertThat(container.isConfig(), is(true)); |
| 261 | |
| 262 | // Check whether leaf properties as set correctly. |
| 263 | ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); |
| 264 | YangLeaf leafInfo = leafIterator.next(); |
| 265 | |
| 266 | assertThat(leafInfo.getLeafName(), is("invalid-interval")); |
| 267 | assertThat(leafInfo.isConfig(), is(true)); |
| 268 | } |
| 269 | |
| 270 | /** |
| 271 | * Checks whether exception is throw when node's parent config set to false, |
| 272 | * no node underneath it can have config set to true. |
| 273 | */ |
| 274 | @Test |
| 275 | public void processConfigFalseParentContainerChildLeafList() throws IOException, ParserException { |
| 276 | thrown.expect(ParserException.class); |
| 277 | thrown.expectMessage("Internal parser error detected: Unhandled parsed data at container \"valid\" after " |
| 278 | + "processing.\nError Information: If a container has \"config\" set to \"false\", no node underneath " |
| 279 | + "it can have \"config\" set to \"true\"."); |
| 280 | YangNode node = manager.getDataModel("src/test/resources/ConfigFalseParentContainerChildLeafList.yang"); |
| 281 | } |
| 282 | |
| 283 | /** |
| 284 | * Checks whether exception is throw when node's parent config set to false, |
| 285 | * no node underneath it can have config set to true. |
| 286 | */ |
| 287 | @Test |
| 288 | public void processConfigFalseParentContainerChildLeaf() throws IOException, ParserException { |
| 289 | thrown.expect(ParserException.class); |
| 290 | thrown.expectMessage("Internal parser error detected: Unhandled parsed data at container \"valid\" after " |
| 291 | + "processing.\nError Information: If a container has \"config\" set to \"false\", no node underneath " |
| 292 | + "it can have \"config\" set to \"true\"."); |
| 293 | YangNode node = manager.getDataModel("src/test/resources/ConfigFalseParentContainerChildLeaf.yang"); |
| 294 | } |
| 295 | |
| 296 | /** |
| 297 | * Checks whether exception is throw when node's parent config set to false, |
| 298 | * no node underneath it can have config set to true. |
| 299 | */ |
| 300 | @Test |
| 301 | public void processConfigFalseParentListChildLeafList() throws IOException, ParserException { |
| 302 | thrown.expect(ParserException.class); |
| 303 | thrown.expectMessage("Internal parser error detected: Unhandled parsed data at list \"valid\" after" |
| 304 | + " processing.\nError Information: If a list has \"config\" set to \"false\", no node underneath" |
| 305 | + " it can have \"config\" set to \"true\"."); |
| 306 | YangNode node = manager.getDataModel("src/test/resources/ConfigFalseParentListChildLeafList.yang"); |
| 307 | } |
| 308 | |
| 309 | /** |
| 310 | * Checks whether exception is throw when node's parent config set to false, |
| 311 | * no node underneath it can have config set to true. |
| 312 | */ |
| 313 | @Test |
| 314 | public void processConfigFalseParentListChildLeaf() throws IOException, ParserException { |
| 315 | thrown.expect(ParserException.class); |
| 316 | thrown.expectMessage("Internal parser error detected: Unhandled parsed data at list \"valid\" after" |
| 317 | + " processing.\nError Information: If a list has \"config\" set to \"false\", no node underneath" |
| 318 | + " it can have \"config\" set to \"true\"."); |
| 319 | YangNode node = manager.getDataModel("src/test/resources/ConfigFalseParentListChildLeaf.yang"); |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 324 | * config statement's value. |
| 325 | */ |
| 326 | @Test |
| 327 | public void processNoConfigContainerSubStatementContainer() throws IOException, ParserException { |
| 328 | |
| 329 | YangNode node = manager.getDataModel("src/test/resources/NoConfigContainerSubStatementContainer.yang"); |
| 330 | |
| 331 | assertThat((node instanceof YangModule), is(true)); |
| 332 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 333 | YangModule yangNode = (YangModule) node; |
| 334 | assertThat(yangNode.getName(), is("Test")); |
| 335 | |
| 336 | // Check whether the config value is set correctly. |
| 337 | YangContainer container = (YangContainer) yangNode.getChild(); |
| 338 | assertThat(container.getName(), is("hello")); |
| 339 | assertThat(container.isConfig(), is(true)); |
| 340 | |
| 341 | YangNode containerNode = container.getChild(); |
| 342 | assertThat(containerNode instanceof YangContainer, is(true)); |
| 343 | YangContainer childContainer = (YangContainer) containerNode; |
| 344 | assertThat(childContainer.getName(), is("valid")); |
| 345 | assertThat(childContainer.isConfig(), is(true)); |
| 346 | } |
| 347 | |
| 348 | /** |
| 349 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 350 | * config statement's value. |
| 351 | */ |
| 352 | @Test |
| 353 | public void processNoConfigContainerSubStatementLeafList() throws IOException, ParserException { |
| 354 | |
| 355 | YangNode node = manager.getDataModel("src/test/resources/NoConfigContainerSubStatementLeafList.yang"); |
| 356 | |
| 357 | assertThat((node instanceof YangModule), is(true)); |
| 358 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 359 | YangModule yangNode = (YangModule) node; |
| 360 | assertThat(yangNode.getName(), is("Test")); |
| 361 | |
| 362 | // Check whether the config value is set correctly. |
| 363 | YangContainer container = (YangContainer) yangNode.getChild(); |
| 364 | assertThat(container.getName(), is("valid")); |
| 365 | assertThat(container.isConfig(), is(true)); |
| 366 | |
| 367 | ListIterator<YangLeafList> leafListIterator = container.getListOfLeafList().listIterator(); |
| 368 | YangLeafList leafListInfo = leafListIterator.next(); |
| 369 | |
| 370 | // Check whether config value is set correctly. |
| 371 | assertThat(leafListInfo.getLeafName(), is("invalid-interval")); |
| 372 | assertThat(leafListInfo.isConfig(), is(true)); |
| 373 | |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 378 | * config statement's value. |
| 379 | */ |
| 380 | @Test |
| 381 | public void processNoConfigContainerSubStatementLeaf() throws IOException, ParserException { |
| 382 | |
| 383 | YangNode node = manager.getDataModel("src/test/resources/NoConfigContainerSubStatementLeaf.yang"); |
| 384 | |
| 385 | assertThat((node instanceof YangModule), is(true)); |
| 386 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 387 | YangModule yangNode = (YangModule) node; |
| 388 | assertThat(yangNode.getName(), is("Test")); |
| 389 | |
| 390 | // Check whether the config value is set correctly. |
| 391 | YangContainer container = (YangContainer) yangNode.getChild(); |
| 392 | assertThat(container.getName(), is("valid")); |
| 393 | assertThat(container.isConfig(), is(true)); |
| 394 | |
| 395 | // Check whether leaf properties as set correctly. |
| 396 | ListIterator<YangLeaf> leafIterator = container.getListOfLeaf().listIterator(); |
| 397 | YangLeaf leafInfo = leafIterator.next(); |
| 398 | |
| 399 | assertThat(leafInfo.getLeafName(), is("invalid-interval")); |
| 400 | assertThat(leafInfo.isConfig(), is(true)); |
| 401 | } |
| 402 | |
| 403 | /** |
| 404 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 405 | * config statement's value. |
| 406 | */ |
| 407 | @Test |
| 408 | public void processNoConfigContainerSubStatementList() throws IOException, ParserException { |
| 409 | |
| 410 | YangNode node = manager.getDataModel("src/test/resources/NoConfigContainerSubStatementList.yang"); |
| 411 | |
| 412 | assertThat((node instanceof YangModule), is(true)); |
| 413 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 414 | YangModule yangNode = (YangModule) node; |
| 415 | assertThat(yangNode.getName(), is("Test")); |
| 416 | |
| 417 | // Check whether the config value is set correctly. |
| 418 | YangContainer container = (YangContainer) yangNode.getChild(); |
| 419 | assertThat(container.getName(), is("hello")); |
| 420 | assertThat(container.isConfig(), is(true)); |
| 421 | |
| 422 | YangNode listNode = container.getChild(); |
| 423 | assertThat(listNode instanceof YangList, is(true)); |
| 424 | YangList childList = (YangList) listNode; |
| 425 | assertThat(childList.getName(), is("valid")); |
| 426 | assertThat(childList.isConfig(), is(true)); |
| 427 | |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 432 | * config statement's value. |
| 433 | */ |
| 434 | @Test |
| 435 | public void processNoConfigListSubStatementContainer() throws IOException, ParserException { |
| 436 | |
| 437 | YangNode node = manager.getDataModel("src/test/resources/NoConfigListSubStatementContainer.yang"); |
| 438 | |
| 439 | assertThat((node instanceof YangModule), is(true)); |
| 440 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 441 | YangModule yangNode = (YangModule) node; |
| 442 | assertThat(yangNode.getName(), is("Test")); |
| 443 | |
| 444 | // Check whether the config value is set correctly. |
| 445 | YangList list1 = (YangList) yangNode.getChild(); |
| 446 | assertThat(list1.getName(), is("list1")); |
| 447 | assertThat(list1.isConfig(), is(true)); |
| 448 | |
| 449 | YangNode containerNode = list1.getChild(); |
| 450 | assertThat(containerNode instanceof YangContainer, is(true)); |
| 451 | YangContainer childContainer = (YangContainer) containerNode; |
| 452 | assertThat(childContainer.getName(), is("container1")); |
| 453 | assertThat(childContainer.isConfig(), is(true)); |
| 454 | } |
| 455 | |
| 456 | /** |
| 457 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 458 | * config statement's value. |
| 459 | */ |
| 460 | @Test |
| 461 | public void processNoConfigListSubStatementLeafList() throws IOException, ParserException { |
| 462 | |
| 463 | YangNode node = manager.getDataModel("src/test/resources/NoConfigListSubStatementLeafList.yang"); |
| 464 | |
| 465 | assertThat((node instanceof YangModule), is(true)); |
| 466 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 467 | YangModule yangNode = (YangModule) node; |
| 468 | assertThat(yangNode.getName(), is("Test")); |
| 469 | |
| 470 | // Check whether the config value is set correctly. |
| 471 | YangList list1 = (YangList) yangNode.getChild(); |
| 472 | assertThat(list1.getName(), is("valid")); |
| 473 | assertThat(list1.isConfig(), is(true)); |
| 474 | |
| 475 | ListIterator<YangLeafList> leafListIterator = list1.getListOfLeafList().listIterator(); |
| 476 | YangLeafList leafListInfo = leafListIterator.next(); |
| 477 | |
| 478 | // Check whether config value is set correctly. |
| 479 | assertThat(leafListInfo.getLeafName(), is("invalid-interval")); |
| 480 | assertThat(leafListInfo.isConfig(), is(true)); |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 485 | * config statement's value. |
| 486 | */ |
| 487 | @Test |
| 488 | public void processNoConfigListSubStatementLeaf() throws IOException, ParserException { |
| 489 | |
| 490 | YangNode node = manager.getDataModel("src/test/resources/NoConfigListSubStatementLeaf.yang"); |
| 491 | |
| 492 | assertThat((node instanceof YangModule), is(true)); |
| 493 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 494 | YangModule yangNode = (YangModule) node; |
| 495 | assertThat(yangNode.getName(), is("Test")); |
| 496 | |
| 497 | // Check whether the config value is set correctly. |
| 498 | YangList list1 = (YangList) yangNode.getChild(); |
| 499 | assertThat(list1.getName(), is("valid")); |
| 500 | assertThat(list1.isConfig(), is(true)); |
| 501 | |
| 502 | // Check whether leaf properties as set correctly. |
| 503 | ListIterator<YangLeaf> leafIterator = list1.getListOfLeaf().listIterator(); |
| 504 | YangLeaf leafInfo = leafIterator.next(); |
| 505 | |
| 506 | assertThat(leafInfo.getLeafName(), is("invalid-interval")); |
| 507 | assertThat(leafInfo.isConfig(), is(true)); |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * Checks when config is not specified, the default is same as the parent's schema node's |
| 512 | * config statement's value. |
| 513 | */ |
| 514 | @Test |
| 515 | public void processNoConfigListSubStatementList() throws IOException, ParserException { |
| 516 | |
| 517 | YangNode node = manager.getDataModel("src/test/resources/NoConfigListSubStatementList.yang"); |
| 518 | |
| 519 | assertThat((node instanceof YangModule), is(true)); |
| 520 | assertThat(node.getNodeType(), is(YangNodeType.MODULE_NODE)); |
| 521 | YangModule yangNode = (YangModule) node; |
| 522 | assertThat(yangNode.getName(), is("Test")); |
| 523 | |
| 524 | // Check whether the config value is set correctly. |
| 525 | YangList list1 = (YangList) yangNode.getChild(); |
| 526 | assertThat(list1.getName(), is("valid")); |
| 527 | assertThat(list1.isConfig(), is(true)); |
| 528 | |
| 529 | YangNode listNode = list1.getChild(); |
| 530 | assertThat(listNode instanceof YangList, is(true)); |
| 531 | YangList childList = (YangList) listNode; |
| 532 | assertThat(childList.getName(), is("list1")); |
| 533 | assertThat(childList.isConfig(), is(true)); |
| 534 | } |
Vidyashree Rama | 50b73a0 | 2016-02-13 22:22:12 +0530 | [diff] [blame] | 535 | } |