org.opendaylight.yangtools.yang.model.api.Module Java Examples
The following examples show how to use
org.opendaylight.yangtools.yang.model.api.Module.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActionStatementTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testActionStatementInDataContainers() throws Exception { final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/action-stmt/foo.yang"); assertNotNull(schemaContext); assertContainsActions(schemaContext, "root", "grp-action", "aug-action"); assertContainsActions(schemaContext, "top-list", "top-list-action"); assertContainsActions(schemaContext, "top", "top-action"); final Collection<? extends GroupingDefinition> groupings = schemaContext.getGroupings(); assertEquals(1, groupings.size()); assertContainsActions(groupings.iterator().next(), "grp-action"); final Collection<? extends Module> modules = schemaContext.getModules(); assertEquals(1, modules.size()); final Module foo = modules.iterator().next(); final Collection<? extends AugmentationSchemaNode> augmentations = foo.getAugmentations(); assertEquals(1, augmentations.size()); assertContainsActions(augmentations.iterator().next(), "aug-action", "grp-action"); }
Example #2
Source File: AbstractDataObjectBuilder.java From yang2swagger with Eclipse Public License 1.0 | 6 votes |
/** * Traverse model to collect all verbs from YANG nodes that will constitute Swagger models * @param module to traverse */ @Override public void processModule(Module module) { HashSet<String> cache = new HashSet<>(names.values()); log.debug("processing data nodes defined in {}", module.getName()); processNode(module, cache); log.debug("processing rpcs defined in {}", module.getName()); module.getRpcs().forEach(r -> { if(r.getInput() != null) processNode(r.getInput(), null, cache); if(r.getOutput() != null) processNode(new RpcContainerSchemaNode(r), null, cache); }); log.debug("processing augmentations defined in {}", module.getName()); module.getAugmentations().forEach(r -> processNode(r, cache)); }
Example #3
Source File: Bug8083Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testInstanceIdentifierPathWithIdentityrefListKey() throws Exception { final EffectiveModelContext schemaContext = YangParserTestUtils.parseYangResource("/bug8083/yang/zab.yang"); final Module zabModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode topCont = (ContainerSchemaNode) zabModule.findDataChildByName( QName.create(zabModule.getQNameModule(), "top-cont")).get(); final InputStream resourceAsStream = Bug8083Test.class.getResourceAsStream("/bug8083/xml/zab.xml"); final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream); // deserialization final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, topCont); xmlParser.parse(reader); final NormalizedNode<?, ?> transformedInput = result.getResult(); assertNotNull(transformedInput); }
Example #4
Source File: SchemaContextProxyTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testBasicRevisionChange() throws Exception { Module moduleConfig = mockModule(CONFIG_NAME); Module module2 = mockModule(MODULE2_NAME); Module module3 = mockModule(MODULE3_NAME); Module module4 = mockModule(MODULE3_NAME, Revision.of("2015-10-10")); mockModuleImport(module2, moduleConfig); mockModuleImport(module3, module2, moduleConfig); SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4); FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3); }
Example #5
Source File: YangParserTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkOrder(final Collection<Module> modules) { final Iterator<Module> it = modules.iterator(); Module module = it.next(); assertEquals("m2", module.getName()); module = it.next(); assertEquals("m4", module.getName()); module = it.next(); assertEquals("m6", module.getName()); module = it.next(); assertEquals("m8", module.getName()); module = it.next(); assertEquals("m7", module.getName()); module = it.next(); assertEquals("m5", module.getName()); module = it.next(); assertEquals("m3", module.getName()); module = it.next(); assertEquals("m1", module.getName()); }
Example #6
Source File: SchemaContextProxyTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testChainDependMulti() { Module moduleConfig = mockModule(CONFIG_NAME); Module module2 = mockModule(MODULE2_NAME); Module module3 = mockModule(MODULE3_NAME); Module module4 = mockModule(MODULE4_NAME); Module module5 = mockModule(MODULE5_NAME); mockModuleImport(module2, moduleConfig, module3); mockModuleImport(module3, module4); mockModuleImport(module4, module5); SchemaContext schemaContext = mockSchema(moduleConfig, module2, module3, module4, module5); FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, module2, module3, module4, module5); }
Example #7
Source File: Bug5396Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private void testInputXML(final String xmlPath, final String expectedValue) throws Exception { final InputStream resourceAsStream = XmlToNormalizedNodesTest.class.getResourceAsStream(xmlPath); final Module fooModule = schemaContext.getModules().iterator().next(); final ContainerSchemaNode rootCont = (ContainerSchemaNode) fooModule.findDataChildByName( QName.create(fooModule.getQNameModule(), "root")).get(); final XMLStreamReader reader = UntrustedXML.createXMLStreamReader(resourceAsStream); final NormalizedNodeResult result = new NormalizedNodeResult(); final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result); final XmlParserStream xmlParser = XmlParserStream.create(streamWriter, schemaContext, rootCont); xmlParser.parse(reader); assertNotNull(result.getResult()); assertTrue(result.getResult() instanceof ContainerNode); final ContainerNode rootContainer = (ContainerNode) result.getResult(); Optional<DataContainerChild<? extends PathArgument, ?>> myLeaf = rootContainer.getChild(new NodeIdentifier( QName.create(fooModuleQName, "my-leaf"))); assertTrue(myLeaf.orElse(null) instanceof LeafNode); assertEquals(expectedValue, myLeaf.get().getValue()); }
Example #8
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkContentSimpleTest(final SchemaContext context) { URI yangTypesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"); final Revision rev20100924 = Revision.of("2010-09-24"); final Revision rev20130516 = Revision.of("2013-05-16"); final Revision rev20130715 = Revision.of("2013-07-15"); final QNameModule yangTypes20100924 = QNameModule.create(yangTypesNS, rev20100924); final QNameModule yangTypes20130516 = QNameModule.create(yangTypesNS, rev20130516); final QNameModule yangTypes20130715 = QNameModule.create(yangTypesNS, rev20130715); final QName dateTimeTypeDef20100924 = QName.create(yangTypes20100924, "date-and-time"); final QName dateTimeTypeDef20130516 = QName.create(yangTypes20130516, "date-and-time"); final QName dateTimeTypeDef20130715 = QName.create(yangTypes20130715, "date-and-time"); Module yangTypesModule20100924 = context.findModule("ietf-yang-types", rev20100924).get(); Module yangTypesModule20130516 = context.findModule("ietf-yang-types", rev20130516).get(); Module yangTypesModule20130715 = context.findModule("ietf-yang-types", rev20130715).get(); assertTrue(findTypeDef(yangTypesModule20100924, dateTimeTypeDef20100924)); assertTrue(findTypeDef(yangTypesModule20130516, dateTimeTypeDef20130516)); assertTrue(findTypeDef(yangTypesModule20130715, dateTimeTypeDef20130715)); checkNetconfMonitoringModuleSimpleTest(context, rev20130715, dateTimeTypeDef20130715); checkInterfacesModuleSimpleTest(context, rev20100924, dateTimeTypeDef20100924); }
Example #9
Source File: Bug8597Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void test() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8597"); assertNotNull(context); final Module foo = context.findModule("foo").get(); for (final ModuleImport moduleImport : foo.getImports()) { switch (moduleImport.getModuleName()) { case "bar": assertEquals(Revision.ofNullable("1970-01-01"), moduleImport.getRevision()); assertEquals(Optional.of("bar-ref"), moduleImport.getReference()); assertEquals(Optional.of("bar-desc"), moduleImport.getDescription()); break; case "baz": assertEquals(Revision.ofNullable("2010-10-10"), moduleImport.getRevision()); assertEquals(Optional.of("baz-ref"), moduleImport.getReference()); assertEquals(Optional.of("baz-desc"), moduleImport.getDescription()); break; default: fail("Module 'foo' should only contains import of module 'bar' and 'baz'"); } } }
Example #10
Source File: SchemaContextUtil.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Transforms part of Prefixed Path as java String to QName. <br> * If the string contains module prefix separated by ":" (i.e. * mod:container) this module is provided from from Parent Module list of * imports. If the Prefixed module is present in Schema Context the QName * can be constructed. <br> * If the Prefixed Path Part does not contains prefix the Parent's Module * namespace is taken for construction of QName. <br> * * @param context Schema Context * @param parentModule Parent Module * @param prefixedPathPart Prefixed Path Part string * @return QName from prefixed Path Part String. * @throws NullPointerException if any arguments are null */ private static QName stringPathPartToQName(final SchemaContext context, final Module parentModule, final String prefixedPathPart) { requireNonNull(context, "context"); if (prefixedPathPart.indexOf(':') != -1) { final Iterator<String> prefixedName = COLON_SPLITTER.split(prefixedPathPart).iterator(); final String modulePrefix = prefixedName.next(); final Module module = resolveModuleForPrefix(context, parentModule, modulePrefix); checkArgument(module != null, "Failed to resolve xpath: no module found for prefix %s in module %s", modulePrefix, parentModule.getName()); return QName.create(module.getQNameModule(), prefixedName.next()); } return QName.create(parentModule.getNamespace(), parentModule.getRevision(), prefixedPathPart); }
Example #11
Source File: IoCGeneratorHelper.java From yang2swagger with Eclipse Public License 1.0 | 6 votes |
public static IoCSwaggerGenerator getGenerator(File dir, Predicate<Module> toSelect) throws Exception { final PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:*.yang"); Predicate<Path> acc = p -> matcher.matches(p.getFileName()); final SchemaContext ctx = dir == null ? getFromClasspath(acc) : getFromDir(dir.toPath(), acc); if(ctx.getModules().isEmpty()) throw new IllegalArgumentException(String.format("No YANG modules found in %s", dir == null ? "classpath" : dir.toString())); log.info("Context parsed {}", ctx); final Set<Module> toGenerate = ctx.getModules().stream().filter(toSelect).collect(Collectors.toSet()); return swaggerGeneratorFactory.createSwaggerGenerator(ctx, toGenerate) .defaultConfig() .format(IoCSwaggerGenerator.Format.YAML) .consumes("application/xml") .produces("application/xml") .host("localhost:1234") .elements(IoCSwaggerGenerator.Elements.DATA, IoCSwaggerGenerator.Elements.RCP); }
Example #12
Source File: SchemaContextUtilTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void findDataSchemaNodeTest() { final Module importedModule = context.findModule(URI.create("uri:imported-module"), Revision.of("2014-10-07")).get(); final SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName(QName.create( importedModule.getQNameModule(), "my-imported-container"))).getDataChildByName(QName.create( importedModule.getQNameModule(), "my-imported-leaf")); final PathExpression xpath = new PathExpressionImpl("imp:my-imported-container/imp:my-imported-leaf", true); final SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, myModule, xpath); assertNotNull(foundNode); assertNotNull(testNode); assertEquals(testNode, foundNode); }
Example #13
Source File: YT1060Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Before public void before() { context = YangParserTestUtils.parseYangResourceDirectory("/yt1060"); final Module module = context.findModule(CONT.getModule()).get(); final ContainerSchemaNode cont = (ContainerSchemaNode) module.findDataChildByName(CONT).get(); final LeafSchemaNode leaf1 = (LeafSchemaNode) cont.findDataChildByName(LEAF1).get(); path = ((LeafrefTypeDefinition) leaf1.getType()).getPathStatement(); // Quick checks before we get to the point final Steps pathSteps = path.getSteps(); assertThat(pathSteps, isA(LocationPathSteps.class)); final YangLocationPath locationPath = ((LocationPathSteps) pathSteps).getLocationPath(); assertTrue(locationPath.isAbsolute()); final ImmutableList<Step> steps = locationPath.getSteps(); assertEquals(2, steps.size()); steps.forEach(step -> assertThat(step, isA(ResolvedQNameStep.class))); }
Example #14
Source File: IdentityrefStatementTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testIdentityrefWithMultipleBaseIdentities() throws Exception { final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/identityref-stmt/foo.yang"); assertNotNull(schemaContext); final Module foo = schemaContext.findModule("foo", Revision.of("2017-01-11")).get(); final Collection<? extends IdentitySchemaNode> identities = foo.getIdentities(); assertEquals(3, identities.size()); final LeafSchemaNode idrefLeaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "idref-leaf")); assertNotNull(idrefLeaf); final IdentityrefTypeDefinition idrefType = (IdentityrefTypeDefinition) idrefLeaf.getType(); final Set<? extends IdentitySchemaNode> referencedIdentities = idrefType.getIdentities(); assertEquals(3, referencedIdentities.size()); assertEquals(identities, referencedIdentities); assertEquals("id-a", idrefType.getIdentities().iterator().next().getQName().getLocalName()); }
Example #15
Source File: SchemaContextProxyTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testConfigDifferentRevisions() { Module moduleConfigNullRevision = mockModule(CONFIG_NAME, null); Module moduleConfig = mockModule(CONFIG_NAME, REVISION); Module moduleConfig2 = mockModule(CONFIG_NAME, REVISION2); Module module2 = mockModule(MODULE2_NAME); Module module3 = mockModule(MODULE3_NAME); mockModuleImport(module2, moduleConfig); mockModuleImport(module3, module2, moduleConfigNullRevision); SchemaContext schemaContext = mockSchema(moduleConfig, moduleConfig2, module2, module3); FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, null, moduleConfig); assertProxyContext(filteringSchemaContextProxy, moduleConfig, moduleConfig2, module2, module3); }
Example #16
Source File: YangParserWithContextTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testIdentity() throws ReactorException { final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild() .addSources(IETF) .addSource(sourceForResource("/types/[email protected]")) .addSource(sourceForResource("/context-test/test3.yang")) .buildEffective(); final Module module = context.findModule("test3", Revision.of("2013-06-18")).get(); final Collection<? extends IdentitySchemaNode> identities = module.getIdentities(); assertEquals(1, identities.size()); final IdentitySchemaNode identity = identities.iterator().next(); final QName idQName = identity.getQName(); assertEquals(URI.create("urn:simple.demo.test3"), idQName.getNamespace()); assertEquals(Revision.ofNullable("2013-06-18"), idQName.getRevision()); assertEquals("pt", idQName.getLocalName()); final IdentitySchemaNode baseIdentity = Iterables.getOnlyElement(identity.getBaseIdentities()); final QName idBaseQName = baseIdentity.getQName(); assertEquals(URI.create("urn:custom.types.demo"), idBaseQName.getNamespace()); assertEquals(Revision.ofNullable("2012-04-16"), idBaseQName.getRevision()); assertEquals("service-type", idBaseQName.getLocalName()); }
Example #17
Source File: LeafRefUtils.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Create an absolute leafref path. * * @param leafRefPath leafRefPath * @param contextNodeSchemaPath contextNodeSchemaPath * @param module module * @return LeafRefPath object */ public static LeafRefPath createAbsoluteLeafRefPath( final LeafRefPath leafRefPath, final SchemaPath contextNodeSchemaPath, final Module module) { if (leafRefPath.isAbsolute()) { return leafRefPath; } final Deque<QNameWithPredicate> absoluteLeafRefTargetPathList = schemaPathToXPathQNames( contextNodeSchemaPath, module); final Iterator<QNameWithPredicate> leafRefTgtPathFromRootIterator = leafRefPath.getPathFromRoot().iterator(); while (leafRefTgtPathFromRootIterator.hasNext()) { final QNameWithPredicate qname = leafRefTgtPathFromRootIterator.next(); if (qname.equals(QNameWithPredicate.UP_PARENT)) { absoluteLeafRefTargetPathList.removeLast(); } else { absoluteLeafRefTargetPathList.add(qname); } } return LeafRefPath.create(absoluteLeafRefTargetPathList, true); }
Example #18
Source File: Bug6856Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testExplicitInputAndOutputInRpc() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(Bug6856Test.class, "/bugs/bug6856/bar.yang"); assertNotNull(schemaContext); final OutputStream byteArrayOutputStream = new ByteArrayOutputStream(); final BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream); final Module barModule = schemaContext.findModule("bar", Revision.of("2017-02-28")).get(); YinExportUtils.writeModuleAsYinText(barModule, bufferedOutputStream); final String output = byteArrayOutputStream.toString(); assertNotNull(output); assertFalse(output.isEmpty()); assertTrue(output.contains("<input>")); assertTrue(output.contains("<output>")); }
Example #19
Source File: YinFileAugmentStmtTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testAugment() { final Module testModule = TestUtils.findModule(context, "main-impl").get(); assertNotNull(testModule); final Collection<? extends AugmentationSchemaNode> augmentations = testModule.getAugmentations(); assertEquals(1, augmentations.size()); final Iterator<? extends AugmentationSchemaNode> augmentIterator = augmentations.iterator(); final AugmentationSchemaNode augment = augmentIterator.next(); assertNotNull(augment); assertThat(augment.getTargetPath().toString(), containsString( "(urn:opendaylight:params:xml:ns:yang:controller:config?revision=2013-04-05)modules, module, " + "configuration")); assertEquals(1, augment.getChildNodes().size()); final DataSchemaNode caseNode = augment.findDataChildByName( QName.create(testModule.getQNameModule(), "main-impl")).get(); assertThat(caseNode, isA(CaseSchemaNode.class)); }
Example #20
Source File: SchemaContextUtil.java From yangtools with Eclipse Public License 1.0 | 6 votes |
/** * Method will attempt to resolve and provide Module reference for specified module prefix. Each Yang module could * contains multiple imports which MUST be associated with corresponding module prefix. The method simply looks into * module imports and returns the module that is bounded with specified prefix. If the prefix is not present * in module or the prefixed module is not present in specified Schema Context, the method will return {@code null}. * <br> * If String prefix is the same as prefix of the specified Module the reference to this module is returned.<br> * * @param context Schema Context * @param module Yang Module * @param prefix Module Prefix * @return Module for given prefix in specified Schema Context if is present, otherwise returns <code>null</code> * @throws NullPointerException if any arguments are null */ private static Module resolveModuleForPrefix(final SchemaContext context, final Module module, final String prefix) { requireNonNull(context, "context"); if (prefix.equals(module.getPrefix())) { return module; } for (final ModuleImport mi : module.getImports()) { if (prefix.equals(mi.getPrefix())) { return context.findModule(mi.getModuleName(), mi.getRevision()).orElse(null); } } return null; }
Example #21
Source File: YangDataExtensionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testIfFeatureStatementBeingIgnoredInYangDataBody() throws Exception { final SchemaContext schemaContext = reactor.newBuild().setSupportedFeatures(ImmutableSet.of()) .addSources(FOOBAR_MODULE, IETF_RESTCONF_MODULE).buildEffective(); assertNotNull(schemaContext); final Module foobar = schemaContext.findModule("foobar", REVISION).get(); final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = foobar.getUnknownSchemaNodes(); assertEquals(1, unknownSchemaNodes.size()); final UnknownSchemaNode unknownSchemaNode = unknownSchemaNodes.iterator().next(); assertTrue(unknownSchemaNode instanceof YangDataSchemaNode); final YangDataSchemaNode myYangDataNode = (YangDataSchemaNode) unknownSchemaNode; assertNotNull(myYangDataNode); final ContainerSchemaNode contInYangData = myYangDataNode.getContainerSchemaNode(); assertNotNull(contInYangData); final ContainerSchemaNode innerCont = (ContainerSchemaNode) contInYangData.findDataChildByName( QName.create(foobar.getQNameModule(), "inner-cont")).get(); assertNotNull(innerCont); final ContainerSchemaNode grpCont = (ContainerSchemaNode) contInYangData.findDataChildByName( QName.create(foobar.getQNameModule(), "grp-cont")).get(); assertNotNull(grpCont); }
Example #22
Source File: AugmentTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testAugmentInUsesResolving() throws Exception { final SchemaContext context = TestUtils.loadModules(getClass().getResource("/augment-test/augment-in-uses") .toURI()); assertEquals(1, context.getModules().size()); final Module test = context.getModules().iterator().next(); final DataNodeContainer links = (DataNodeContainer) test.getDataChildByName(QName.create(test.getQNameModule(), "links")); final DataNodeContainer link = (DataNodeContainer) links.getDataChildByName(QName.create(test.getQNameModule(), "link")); final DataNodeContainer nodes = (DataNodeContainer) link.getDataChildByName(QName.create(test.getQNameModule(), "nodes")); final ContainerSchemaNode node = (ContainerSchemaNode) nodes.getDataChildByName(QName.create( test.getQNameModule(), "node")); final Collection<? extends AugmentationSchemaNode> augments = node.getAvailableAugmentations(); assertEquals(1, augments.size()); assertEquals(1, node.getChildNodes().size()); final LeafSchemaNode id = (LeafSchemaNode) node.getDataChildByName(QName.create(test.getQNameModule(), "id")); assertTrue(id.isAugmenting()); }
Example #23
Source File: SchemaContextUtilTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void findParentModuleTest() { final DataSchemaNode node = myModule.getDataChildByName(QName.create(myModule.getQNameModule(), "my-container")); final Module foundModule = SchemaContextUtil.findParentModule(context, node); assertEquals(myModule, foundModule); }
Example #24
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static boolean findTypeDef(final Module module, final QName typedef) { for (TypeDefinition<?> typeDefinition : module.getTypeDefinitions()) { if (typeDefinition.getQName().equals(typedef)) { return true; } } return false; }
Example #25
Source File: SchemaContextProxyTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static FilteringSchemaContextProxy createProxySchemaCtx(final SchemaContext schemaContext, final Set<Module> additionalModules, final Module... modules) { Set<Module> modulesSet = new HashSet<>(); if (modules != null) { modulesSet = ImmutableSet.copyOf(modules); } return new FilteringSchemaContextProxy(schemaContext, createModuleIds(modulesSet), createModuleIds(additionalModules)); }
Example #26
Source File: SubmoduleEffectiveStatementImpl.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Override public void seal() { if (!sealed) { submodules = ImmutableSet.copyOf(Iterables.transform(submoduleContexts, ctx -> (Module) ctx.buildEffective())); submoduleContexts = ImmutableSet.of(); sealed = true; } }
Example #27
Source File: YangParserWithContextTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testAugment() throws ReactorException { final StatementStreamSource resource = sourceForResource("/context-augment-test/test4.yang"); final StatementStreamSource test1 = sourceForResource("/context-augment-test/test1.yang"); final StatementStreamSource test2 = sourceForResource("/context-augment-test/test2.yang"); final StatementStreamSource test3 = sourceForResource("/context-augment-test/test3.yang"); final SchemaContext context = TestUtils.parseYangSources(resource, test1, test2, test3); final Module t4 = TestUtils.findModule(context, "test4").get(); final ContainerSchemaNode interfaces = (ContainerSchemaNode) t4.getDataChildByName(QName.create( t4.getQNameModule(), "interfaces")); final ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName(QName.create(t4.getQNameModule(), "ifEntry")); // test augmentation process final ContainerSchemaNode augmentHolder = (ContainerSchemaNode) ifEntry.getDataChildByName(QName.create(T3_NS, REV, "augment-holder")); assertNotNull(augmentHolder); final DataSchemaNode ds0 = augmentHolder.getDataChildByName(QName.create(T2_NS, REV, "ds0ChannelNumber")); assertNotNull(ds0); final DataSchemaNode interfaceId = augmentHolder.getDataChildByName(QName.create(T2_NS, REV, "interface-id")); assertNotNull(interfaceId); final DataSchemaNode higherLayerIf = augmentHolder.getDataChildByName(QName.create(T2_NS, REV, "higher-layer-if")); assertNotNull(higherLayerIf); final ContainerSchemaNode schemas = (ContainerSchemaNode) augmentHolder.getDataChildByName(QName.create(T2_NS, REV, "schemas")); assertNotNull(schemas); assertNotNull(schemas.getDataChildByName(QName.create(T1_NS, REV, "id"))); // test augment target after augmentation: check if it is same instance final ListSchemaNode ifEntryAfterAugment = (ListSchemaNode) interfaces.getDataChildByName(QName.create( t4.getQNameModule(), "ifEntry")); assertTrue(ifEntry == ifEntryAfterAugment); }
Example #28
Source File: SchemaContextProxyTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testGetChildNodes() { final Module moduleConfig = mockModule(CONFIG_NAME); final SchemaContext schemaContext = mockSchema(moduleConfig); final FilteringSchemaContextProxy filteringSchemaContextProxy = createProxySchemaCtx(schemaContext, new HashSet<>(), moduleConfig); final ContainerSchemaNode mockedContainer = mock(ContainerSchemaNode.class); final Set<DataSchemaNode> childNodes = Collections.singleton(mockedContainer); doReturn(childNodes).when(moduleConfig).getChildNodes(); final Collection<? extends DataSchemaNode> schemaContextProxyChildNodes = filteringSchemaContextProxy.getChildNodes(); assertTrue(schemaContextProxyChildNodes.contains(mockedContainer)); }
Example #29
Source File: OpenconfigVersionBorderCaseTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void borderCaseValidPatchTest() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources( "/openconfig-version/border-case/border-case-valid-patch", StatementParserMode.SEMVER_MODE); assertNotNull(context); Module foo = context.findModules(URI.create("foo")).iterator().next(); Module semVer = context.findModules(URI.create("http://openconfig.net/yang/openconfig-ext")).iterator().next(); assertEquals(SemVer.valueOf("0.0.1"), semVer.getSemanticVersion().get()); assertEquals(SemVer.valueOf("0.1.1"), foo.getSemanticVersion().get()); Module bar = StmtTestUtils.findImportedModule(context, foo, "bar"); assertEquals(SemVer.valueOf("5.5.6"), bar.getSemanticVersion().get()); }
Example #30
Source File: LeafRefUtils.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static Deque<QNameWithPredicate> schemaPathToXPathQNames(final SchemaPath nodePath, final Module module) { final Deque<QNameWithPredicate> xpath = new LinkedList<>(); final Iterator<QName> nodePathIterator = nodePath.getPathFromRoot().iterator(); DataNodeContainer currenDataNodeContainer = module; while (nodePathIterator.hasNext()) { final QName qname = nodePathIterator.next(); final DataSchemaNode child = currenDataNodeContainer.getDataChildByName(qname); if (child instanceof DataNodeContainer) { if (!(child instanceof CaseSchemaNode)) { xpath.add(new SimpleQNameWithPredicate(qname)); } currenDataNodeContainer = (DataNodeContainer) child; } else if (child instanceof ChoiceSchemaNode) { if (nodePathIterator.hasNext()) { currenDataNodeContainer = ((ChoiceSchemaNode) child).findCase(nodePathIterator.next()).orElse(null); } else { break; } } else if (child instanceof LeafSchemaNode || child instanceof LeafListSchemaNode) { xpath.add(new SimpleQNameWithPredicate(qname)); break; } else if (child == null) { throw new IllegalArgumentException("No child " + qname + " found in node container " + currenDataNodeContainer + " in module " + module.getName()); } else { throw new IllegalStateException("Illegal schema node type in the path: " + child.getClass()); } } return xpath; }