Java Code Examples for org.opendaylight.yangtools.yang.model.api.SchemaContext#getTypeDefinitions()
The following examples show how to use
org.opendaylight.yangtools.yang.model.api.SchemaContext#getTypeDefinitions() .
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: TypedefSubStmtsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void typedefSubStmtsTest() throws ReactorException { SchemaContext result = RFC7950Reactors.defaultReactor().newBuild() .addSource(sourceForResource("/typedef-substmts-test/typedef-substmts-test.yang")) .buildEffective(); assertNotNull(result); Collection<? extends TypeDefinition<?>> typedefs = result.getTypeDefinitions(); assertEquals(1, typedefs.size()); TypeDefinition<?> typedef = typedefs.iterator().next(); assertEquals("time-of-the-day", typedef.getQName().getLocalName()); assertEquals("string", typedef.getBaseType().getQName().getLocalName()); assertEquals(Optional.of("24-hour-clock"), typedef.getUnits()); assertEquals("1am", typedef.getDefaultValue().map(Object::toString).orElse(null)); }
Example 2
Source File: Bug6180Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void verifyDoubleQuotesExpression(final SchemaContext schemaContext) { final DataSchemaNode dataNodeBar = schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar")); assertTrue(dataNodeBar instanceof ContainerSchemaNode); final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar; final RevisionAwareXPath whenCondition = bar.getWhenCondition().get(); assertEquals("/foo != \"bar\"", whenCondition.getOriginalString()); final Collection<? extends TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions(); assertEquals(1, typeDefinitions.size()); final TypeDefinition<?> type = typeDefinitions.iterator().next(); assertTrue(type instanceof StringTypeDefinition); final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints(); assertEquals(1, patternConstraints.size()); final PatternConstraint pattern = patternConstraints.iterator().next(); assertEquals("^(?:\".*\")$", pattern.getJavaPatternString()); assertTrue(Pattern.compile(pattern.getJavaPatternString()).matcher("\"enclosed string in quotes\"").matches()); }
Example 3
Source File: Bug6180Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void verifySingleQuotesExpression(final SchemaContext schemaContext) { final DataSchemaNode dataNodeBar = schemaContext.getDataChildByName(QName.create("foo", "2016-07-11", "bar")); assertTrue(dataNodeBar instanceof ContainerSchemaNode); final ContainerSchemaNode bar = (ContainerSchemaNode) dataNodeBar; final RevisionAwareXPath whenCondition = bar.getWhenCondition().get(); assertEquals("/foo != 'bar'", whenCondition.getOriginalString()); final Collection<? extends TypeDefinition<?>> typeDefinitions = schemaContext.getTypeDefinitions(); assertEquals(1, typeDefinitions.size()); final TypeDefinition<?> type = typeDefinitions.iterator().next(); assertTrue(type instanceof StringTypeDefinition); final List<PatternConstraint> patternConstraints = ((StringTypeDefinition) type).getPatternConstraints(); assertEquals(1, patternConstraints.size()); final PatternConstraint pattern = patternConstraints.iterator().next(); assertEquals("^(?:'.*')$", pattern.getJavaPatternString()); assertTrue(Pattern.compile(pattern.getJavaPatternString()).matcher("'enclosed string in quotes'").matches()); }
Example 4
Source File: TypedefConstraintsTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
@Test public void decimalRangeConstraintsTest() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/stmt-test/constraints"); assertNotNull(context); final Collection<? extends TypeDefinition<?>> typeDefinitions = context.getTypeDefinitions(); assertNotNull(typeDefinitions); assertEquals(1, typeDefinitions.size()); final TypeDefinition<?> myDecimal = typeDefinitions.iterator().next(); assertNotNull(myDecimal); assertTrue(myDecimal instanceof DecimalTypeDefinition); final Set<? extends Range<?>> rangeConstraints = ((DecimalTypeDefinition) myDecimal).getRangeConstraint() .get().getAllowedRanges().asRanges(); assertNotNull(rangeConstraints); assertEquals(1, rangeConstraints.size()); final DataSchemaNode dataNode = context.getDataChildByName(QName.create("urn:opendaylight.foo", "2013-10-08", "id-decimal64")); assertNotNull(dataNode); assertTrue(dataNode instanceof LeafSchemaNode); final LeafSchemaNode leafDecimal = (LeafSchemaNode) dataNode; final TypeDefinition<?> type = leafDecimal.getType(); assertTrue(type instanceof DecimalTypeDefinition); final DecimalTypeDefinition decType = (DecimalTypeDefinition) type; final Set<? extends Range<?>> decRangeConstraints = decType.getRangeConstraint().get().getAllowedRanges() .asRanges(); assertEquals(1, decRangeConstraints.size()); final Range<?> range = decRangeConstraints.iterator().next(); assertEquals(new BigDecimal(1.5), range.lowerEndpoint()); assertEquals(new BigDecimal(5.5), range.upperEndpoint()); assertTrue(decType.getQName().getModule().equals(leafDecimal.getQName().getModule())); assertTrue(decType.getQName().getLocalName().equals(BaseTypes.DECIMAL64_QNAME.getLocalName())); assertNull(decType.getBaseType()); }