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