@Test public void test() throws IOException, URISyntaxException, SourceException, ReactorException { SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug3799"); assertNotNull(schema); Set<Module> modules = schema.getModules(); assertNotNull(modules); assertEquals(1, modules.size()); Module testModule = modules.iterator().next(); Set<Module> subModules = testModule.getSubmodules(); assertNotNull(subModules); assertEquals(1, subModules.size()); Module testSubmodule = subModules.iterator().next(); Set<NotificationDefinition> notifications = testSubmodule.getNotifications(); assertNotNull(notifications); assertEquals(1, notifications.size()); NotificationDefinition bazNotification = notifications.iterator().next(); Collection<DataSchemaNode> childNodes = bazNotification.getChildNodes(); assertNotNull(childNodes); assertEquals(1, childNodes.size()); DataSchemaNode child = childNodes.iterator().next(); assertTrue(child instanceof LeafSchemaNode); LeafSchemaNode leafBar = (LeafSchemaNode) child; String bar = leafBar.getQName().getLocalName(); assertEquals("bar", bar); }
@Test public void listAndLeavesTest() throws ReactorException { CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); StmtTestUtils.addSources(reactor, LIST_MODULE); EffectiveSchemaContext result = reactor.buildEffective(); assertNotNull(result); Module testModule = result.findModuleByName("list-test", null); assertNotNull(testModule); ListSchemaNode list = (ListSchemaNode) testModule.getDataChildByName("simple-list"); assertNotNull(list); assertTrue(list.isUserOrdered()); assertTrue(list.isConfiguration()); List<QName> keys = list.getKeyDefinition(); assertEquals(2, keys.size()); assertEquals("key1", keys.get(0).getLocalName()); assertEquals("key2", keys.get(1).getLocalName()); assertEquals(1, list.getConstraints().getMinElements().intValue()); assertEquals(10, list.getConstraints().getMaxElements().intValue()); assertEquals(5, list.getChildNodes().size()); LeafSchemaNode leaf = (LeafSchemaNode) list.getDataChildByName("key1"); assertNotNull(leaf); assertTrue(leaf.getConstraints().isMandatory()); assertEquals("int32", leaf.getType().getQName().getLocalName()); leaf = (LeafSchemaNode) list.getDataChildByName("key2"); assertNotNull(leaf); assertTrue(leaf.getConstraints().isMandatory()); assertEquals("int16", leaf.getType().getQName().getLocalName()); leaf = (LeafSchemaNode) list.getDataChildByName("old-leaf"); assertNotNull(leaf); assertFalse(leaf.getConstraints().isMandatory()); assertEquals("string", leaf.getType().getQName().getLocalName()); leaf = (LeafSchemaNode) list.getDataChildByName("young-leaf"); assertNotNull(leaf); assertFalse(leaf.getConstraints().isMandatory()); assertEquals("young-leaf", leaf.getType().getQName().getLocalName()); assertEquals("default-value", leaf.getDefault()); LeafListSchemaNode leafList = (LeafListSchemaNode) list.getDataChildByName("list-of-leaves"); assertNotNull(leafList); assertTrue(leafList.getConstraints().isMandatory()); assertTrue(leafList.isUserOrdered()); assertEquals(2, leafList.getConstraints().getMinElements().intValue()); assertEquals(20, leafList.getConstraints().getMaxElements().intValue()); assertEquals("string", leafList.getType().getQName().getLocalName()); }