Java Code Examples for org.opendaylight.yangtools.yang.model.api.Module#getTypeDefinitions()
The following examples show how to use
org.opendaylight.yangtools.yang.model.api.Module#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: IncludedStmtsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void includedTypedefsTest() { final Module testModule = result.findModules("root-module").iterator().next(); assertNotNull(testModule); final Collection<? extends TypeDefinition<?>> typedefs = testModule.getTypeDefinitions(); assertEquals(2, typedefs.size()); final Iterator<? extends TypeDefinition<?>> typedefsIterator = typedefs.iterator(); TypeDefinition<?> typedef = typedefsIterator.next(); assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type"))); assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32"))); typedef = typedefsIterator.next(); assertThat(typedef.getQName().getLocalName(), anyOf(is("new-string-type"), is("new-int32-type"))); assertThat(typedef.getBaseType().getQName().getLocalName(), anyOf(is("string"), is("int32"))); }
Example 2
Source File: GroupingTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testAddedByUsesLeafTypeQName() throws Exception { final SchemaContext loadModules = TestUtils.loadModules(getClass().getResource("/added-by-uses-leaf-test") .toURI()); assertEquals(2, loadModules.getModules().size()); foo = TestUtils.findModule(loadModules, "foo").get(); final Module imp = TestUtils.findModule(loadModules, "import-module").get(); final LeafSchemaNode leaf = (LeafSchemaNode) ((ContainerSchemaNode) foo.getDataChildByName(QName.create( foo.getQNameModule(), "my-container"))) .getDataChildByName(QName.create(foo.getQNameModule(), "my-leaf")); TypeDefinition<?> impType = null; for (final TypeDefinition<?> typeDefinition : imp.getTypeDefinitions()) { if (typeDefinition.getQName().getLocalName().equals("imp-type")) { impType = typeDefinition; break; } } assertNotNull(impType); assertEquals(leaf.getType().getQName(), impType.getQName()); }
Example 3
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testIpAddress() { Module tested = TestUtils.findModule(context, "ietf-inet-types").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-address"); UnionTypeDefinition baseType = (UnionTypeDefinition) type.getBaseType(); List<TypeDefinition<?>> unionTypes = baseType.getTypes(); StringTypeDefinition ipv4 = (StringTypeDefinition) unionTypes.get(0); assertNotNull(ipv4.getBaseType()); String expectedPattern = "^(?:(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}" + "([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])" + "(%[\\p{N}\\p{L}]+)?)$"; assertEquals(expectedPattern, ipv4.getPatternConstraints().get(0).getJavaPatternString()); StringTypeDefinition ipv6 = (StringTypeDefinition) unionTypes.get(1); assertNotNull(ipv6.getBaseType()); List<PatternConstraint> ipv6Patterns = ipv6.getPatternConstraints(); expectedPattern = "^(?:((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}" + "((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|" + "(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}" + "(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))" + "(%[\\p{N}\\p{L}]+)?)$"; assertEquals(expectedPattern, ipv6Patterns.get(0).getJavaPatternString()); expectedPattern = "^(?:(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|" + "((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)" + "(%.+)?)$"; assertEquals(expectedPattern, ipv6Patterns.get(1).getJavaPatternString()); }
Example 4
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testDomainName() { Module tested = TestUtils.findModule(context, "ietf-inet-types").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); StringTypeDefinition type = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "domain-name"); assertNotNull(type.getBaseType()); List<PatternConstraint> patterns = type.getPatternConstraints(); assertEquals(1, patterns.size()); String expectedPattern = "^(?:((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*" + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.)$"; assertEquals(expectedPattern, patterns.get(0).getJavaPatternString()); LengthConstraint lengths = type.getLengthConstraint().get(); assertEquals(1, lengths.getAllowedRanges().asRanges().size()); Range<Integer> length = lengths.getAllowedRanges().span(); assertEquals(Integer.valueOf(1), length.lowerEndpoint()); assertEquals(Integer.valueOf(253), length.upperEndpoint()); }
Example 5
Source File: LeafrefStatementTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testRequireInstanceInLeafrefs() throws Exception { final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/leafref-stmt/foo.yang"); assertNotNull(schemaContext); final Module foo = schemaContext.findModule("foo", Revision.of("2016-12-20")).get(); final Collection<? extends TypeDefinition<?>> typeDefinitions = foo.getTypeDefinitions(); assertEquals(1, typeDefinitions.size()); final TypeDefinition<?> typeDefinition = typeDefinitions.iterator().next(); final LeafrefTypeDefinition leafrefTypeDefinition = (LeafrefTypeDefinition) typeDefinition; assertTrue(leafrefTypeDefinition.requireInstance()); final LeafSchemaNode leafrefA = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "leafref-a")); assertNotNull(leafrefA); assertRequireInstanceInLeafref(leafrefA, true); final LeafSchemaNode leafrefB = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "leafref-b")); assertNotNull(leafrefB); assertRequireInstanceInLeafref(leafrefB, true); final LeafSchemaNode leafrefC = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "leafref-c")); assertNotNull(leafrefC); assertRequireInstanceInLeafref(leafrefC, true); }
Example 6
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 7
Source File: YinFileTypeDefStmtTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testTypedef() { Module testModule = TestUtils.findModule(context, "config").get(); assertNotNull(testModule); Collection<? extends TypeDefinition<?>> typeDefs = testModule.getTypeDefinitions(); assertEquals(1, typeDefs.size()); Iterator<? extends TypeDefinition<?>> typeDefIterator = typeDefs.iterator(); TypeDefinition<?> typeDef = typeDefIterator.next(); assertEquals("service-type-ref", typeDef.getQName().getLocalName()); assertEquals(Optional.of("Internal type of references to service type identity."), typeDef.getDescription()); assertEquals("identityref", typeDef.getBaseType().getQName().getLocalName()); }
Example 8
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testIPVersion() { Module tested = TestUtils.findModule(context, "ietf-inet-types").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); assertEquals(14, typedefs.size()); TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version"); assertTrue(type.getDescription().get().contains("This value represents the version of the IP protocol.")); assertTrue(type.getReference().get().contains("RFC 2460: Internet Protocol, Version 6 (IPv6) Specification")); EnumTypeDefinition enumType = (EnumTypeDefinition) type.getBaseType(); List<EnumPair> values = enumType.getValues(); assertEquals(3, values.size()); EnumPair value0 = values.get(0); assertEquals("unknown", value0.getName()); assertEquals(0, value0.getValue()); assertEquals(Optional.of("An unknown or unspecified version of the Internet protocol."), value0.getDescription()); EnumPair value1 = values.get(1); assertEquals("ipv4", value1.getName()); assertEquals(1, value1.getValue()); assertEquals(Optional.of("The IPv4 protocol as defined in RFC 791."), value1.getDescription()); EnumPair value2 = values.get(2); assertEquals("ipv6", value2.getName()); assertEquals(2, value2.getValue()); assertEquals(Optional.of("The IPv6 protocol as defined in RFC 2460."), value2.getDescription()); }
Example 9
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testEnumeration() { Module tested = TestUtils.findModule(context, "custom-types-test").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); TypeDefinition<?> type = TestUtils.findTypedef(typedefs, "ip-version"); EnumTypeDefinition enumType = (EnumTypeDefinition) type.getBaseType(); List<EnumPair> values = enumType.getValues(); assertEquals(4, values.size()); EnumPair value0 = values.get(0); assertEquals("unknown", value0.getName()); assertEquals(0, value0.getValue()); assertEquals(Optional.of("An unknown or unspecified version of the Internet protocol."), value0.getDescription()); EnumPair value1 = values.get(1); assertEquals("ipv4", value1.getName()); assertEquals(19, value1.getValue()); assertEquals(Optional.of("The IPv4 protocol as defined in RFC 791."), value1.getDescription()); EnumPair value2 = values.get(2); assertEquals("ipv6", value2.getName()); assertEquals(7, value2.getValue()); assertEquals(Optional.of("The IPv6 protocol as defined in RFC 2460."), value2.getDescription()); EnumPair value3 = values.get(3); assertEquals("default", value3.getName()); assertEquals(20, value3.getValue()); assertEquals(Optional.of("default ip"), value3.getDescription()); }
Example 10
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testBitsType2() { Module tested = TestUtils.findModule(context, "custom-types-test").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "access-operations-type"); BitsTypeDefinition bitsType = (BitsTypeDefinition) testedType.getBaseType(); Iterator<? extends Bit> bits = bitsType.getBits().iterator(); Bit bit0 = bits.next(); assertEquals("create", bit0.getName()); assertEquals(Uint32.ZERO, bit0.getPosition()); Bit bit1 = bits.next(); assertEquals("delete", bit1.getName()); assertEquals(Uint32.valueOf(365), bit1.getPosition()); Bit bit2 = bits.next(); assertEquals("read", bit2.getName()); assertEquals(Uint32.valueOf(500), bit2.getPosition()); Bit bit3 = bits.next(); assertEquals("update", bit3.getName()); assertEquals(Uint32.valueOf(501), bit3.getPosition()); Bit bit4 = bits.next(); assertEquals("exec", bit4.getName()); assertEquals(Uint32.valueOf(502), bit4.getPosition()); assertFalse(bits.hasNext()); }
Example 11
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testIanaTimezones() { Module tested = TestUtils.findModule(context, "iana-timezones").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "iana-timezone"); String expectedDesc = "A timezone location as defined by the IANA timezone"; assertTrue(testedType.getDescription().get().contains(expectedDesc)); assertFalse(testedType.getReference().isPresent()); assertEquals(Status.CURRENT, testedType.getStatus()); QName testedTypeQName = testedType.getQName(); assertEquals(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"), testedTypeQName.getNamespace()); assertEquals(Revision.ofNullable("2012-07-09"), testedTypeQName.getRevision()); assertEquals("iana-timezone", testedTypeQName.getLocalName()); EnumTypeDefinition enumType = (EnumTypeDefinition) testedType.getBaseType(); List<EnumPair> values = enumType.getValues(); // 0-414 assertEquals(415, values.size()); EnumPair enum168 = values.get(168); assertEquals("America/Danmarkshavn", enum168.getName()); assertEquals(168, enum168.getValue()); assertEquals(Optional.of("east coast, north of Scoresbysund"), enum168.getDescription()); EnumPair enum374 = values.get(374); assertEquals("America/Indiana/Winamac", enum374.getName()); assertEquals(374, enum374.getValue()); assertEquals(Optional.of("Eastern Time - Indiana - Pulaski County"), enum374.getDescription()); }
Example 12
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testObjectId128() { Module tested = TestUtils.findModule(context, "ietf-yang-types").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); StringTypeDefinition testedType = (StringTypeDefinition) TestUtils.findTypedef(typedefs, "object-identifier-128"); List<PatternConstraint> patterns = testedType.getPatternConstraints(); assertEquals(1, patterns.size()); PatternConstraint pattern = patterns.get(0); assertEquals("^(?:\\d*(\\.\\d*){1,127})$", pattern.getJavaPatternString()); QName testedTypeQName = testedType.getQName(); assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeQName.getNamespace()); assertEquals(Revision.ofNullable("2010-09-24"), testedTypeQName.getRevision()); assertEquals("object-identifier-128", testedTypeQName.getLocalName()); StringTypeDefinition testedTypeBase = testedType.getBaseType(); patterns = testedTypeBase.getPatternConstraints(); assertEquals(1, patterns.size()); pattern = patterns.get(0); assertEquals("^(?:(([0-1](\\.[1-3]?[0-9]))|(2\\.(0|([1-9]\\d*))))(\\.(0|([1-9]\\d*)))*)$", pattern.getJavaPatternString()); QName testedTypeBaseQName = testedTypeBase.getQName(); assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeBaseQName.getNamespace()); assertEquals(Revision.ofNullable("2010-09-24"), testedTypeBaseQName.getRevision()); assertEquals("object-identifier", testedTypeBaseQName.getLocalName()); }
Example 13
Source File: TypesResolutionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testIdentityref() { Module tested = TestUtils.findModule(context, "custom-types-test").get(); Collection<? extends TypeDefinition<?>> typedefs = tested.getTypeDefinitions(); TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref"); IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType(); QName identity = baseType.getIdentities().iterator().next().getQName(); assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace()); assertEquals(Revision.ofNullable("2012-04-16"), identity.getRevision()); assertEquals("service-type", identity.getLocalName()); LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName(QName.create(tested.getQNameModule(), "type")); assertNotNull(type); }
Example 14
Source File: Bug5712Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static void checkThing2TypeDef(final Module badModule) { TypeDefinition<?> thing2 = null; for (TypeDefinition<?> typeDef : badModule.getTypeDefinitions()) { if (typeDef.getQName().getLocalName().equals("thing2")) { thing2 = typeDef; break; } } assertNotNull(thing2); TypeDefinition<?> baseType = thing2.getBaseType(); assertEquals(QName.create("urn:opendaylight:bad", "2016-04-11", "thing"), baseType.getQName()); }