org.opendaylight.yangtools.yang.model.api.LeafSchemaNode Java Examples
The following examples show how to use
org.opendaylight.yangtools.yang.model.api.LeafSchemaNode.
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: Bug2872Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void test() throws Exception { final SchemaContext schema = StmtTestUtils.parseYangSources("/bugs/bug2872"); assertNotNull(schema); final QNameModule bug2872module = QNameModule.create(URI.create("bug2872"), Revision.of("2016-06-08")); final QName foo = QName.create(bug2872module, "bar"); final DataSchemaNode dataSchemaNode = schema.getDataChildByName(foo); assertTrue(dataSchemaNode instanceof LeafSchemaNode); final LeafSchemaNode myLeaf = (LeafSchemaNode) dataSchemaNode; final TypeDefinition<?> type = myLeaf.getType(); assertTrue(type instanceof EnumTypeDefinition); final EnumTypeDefinition myEnum = (EnumTypeDefinition) type; final List<EnumTypeDefinition.EnumPair> values = myEnum.getValues(); assertEquals(2, values.size()); final List<String> valueNames = new ArrayList<>(); for (EnumTypeDefinition.EnumPair pair : values) { valueNames.add(pair.getName()); } assertTrue(valueNames.contains("value-one")); assertTrue(valueNames.contains("value-two")); }
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: 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 #4
Source File: EffectiveStatementTypeTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testString() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-string")); assertNotNull(currentLeaf.getType()); final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) .getTypeDefinition(); assertEquals("string", stringEff.getQName().getLocalName()); assertEquals(Status.CURRENT, stringEff.getStatus()); assertEquals(Optional.empty(), stringEff.getUnits()); assertEquals(Optional.empty(), stringEff.getDefaultValue()); assertNotNull(stringEff.getUnknownSchemaNodes()); assertNull(stringEff.getBaseType()); assertFalse(stringEff.getDescription().isPresent()); assertFalse(stringEff.getReference().isPresent()); assertNotNull(stringEff.toString()); assertNotNull(stringEff.hashCode()); assertFalse(stringEff.equals(null)); assertFalse(stringEff.equals("test")); assertTrue(stringEff.equals(stringEff)); assertEquals("string", stringEff.getPath().getLastComponent().getLocalName()); assertFalse(stringEff.getLengthConstraint().isPresent()); assertNotNull(stringEff.getPatternConstraints()); }
Example #5
Source File: InstanceIdToNodes.java From yangtools with Eclipse Public License 1.0 | 6 votes |
static InstanceIdToNodes<?> fromDataSchemaNode(final DataSchemaNode potential) { if (potential instanceof ContainerSchemaNode) { return new InstanceIdToCompositeNodes.ContainerTransformation((ContainerSchemaNode) potential); } else if (potential instanceof ListSchemaNode) { return fromListSchemaNode((ListSchemaNode) potential); } else if (potential instanceof LeafSchemaNode) { return new InstanceIdToSimpleNodes.LeafNormalization((LeafSchemaNode) potential); } else if (potential instanceof ChoiceSchemaNode) { return new InstanceIdToCompositeNodes.ChoiceNodeNormalization((ChoiceSchemaNode) potential); } else if (potential instanceof LeafListSchemaNode) { return fromLeafListSchemaNode((LeafListSchemaNode) potential); } else if (potential instanceof AnydataSchemaNode) { return new AnydataNormalization((AnydataSchemaNode) potential); } else if (potential instanceof AnyxmlSchemaNode) { return new AnyXmlNormalization((AnyxmlSchemaNode) potential); } return null; }
Example #6
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkInterfacesModuleSimpleTest(final SchemaContext context, final Revision rev20100924, final QName dateTimeTypeDef20100924) { URI interfacesNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-interfaces"); Revision rev20121115 = Revision.of("2012-11-15"); final QNameModule interfacesNS20121115 = QNameModule.create(interfacesNS, rev20121115); QName lastChange = QName.create(interfacesNS20121115, "last-change"); Module interfacesModule20121115 = context.findModule("ietf-interfaces", rev20121115).get(); DataSchemaNode leafLastChange = interfacesModule20121115.getDataChildByName(lastChange); assertNotNull(leafLastChange); assertTrue(leafLastChange instanceof LeafSchemaNode); QName lastChangeTypeQName = ((LeafSchemaNode) leafLastChange).getType().getQName(); assertEquals(dateTimeTypeDef20100924, lastChangeTypeQName); Collection<? extends ModuleImport> imports = interfacesModule20121115.getImports(); assertEquals(1, imports.size()); ModuleImport interfacesImport = imports.iterator().next(); assertEquals("ietf-yang-types", interfacesImport.getModuleName()); assertEquals(Optional.of(rev20100924), interfacesImport.getRevision()); }
Example #7
Source File: MoreRevisionsTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
private static void checkNetconfMonitoringModuleSimpleTest(final SchemaContext context, final Revision rev20130715, final QName dateTimeTypeDef20130715) { URI monitoringNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring"); final QNameModule monitoring19700101 = QNameModule.create(monitoringNS); QName lockedTime = QName.create(monitoring19700101, "locked-time"); Module monitoringModule19700101 = context.findModule("ietf-netconf-monitoring").get(); DataSchemaNode leafLockedTime = monitoringModule19700101.getDataChildByName(lockedTime); assertNotNull(leafLockedTime); assertTrue(leafLockedTime instanceof LeafSchemaNode); QName lockedTimeTypeQName = ((LeafSchemaNode) leafLockedTime).getType().getQName(); assertEquals(dateTimeTypeDef20130715, lockedTimeTypeQName); Collection<? extends ModuleImport> imports = monitoringModule19700101.getImports(); assertEquals(1, imports.size()); ModuleImport monitoringImport = imports.iterator().next(); assertEquals("ietf-yang-types", monitoringImport.getModuleName()); assertEquals(Optional.of(rev20130715), monitoringImport.getRevision()); }
Example #8
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 #9
Source File: YT1097Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testBooleanStringUnion() { final Module module = YangParserTestUtils.parseYangResource("/yt1097.yang").findModule("yt1097").orElseThrow(); final DataSchemaNode foo = module.findDataChildByName(QName.create(module.getQNameModule(), "foo")) .orElseThrow(); assertThat(foo, instanceOf(LeafSchemaNode.class)); final TypeDefinitionAwareCodec<?, ?> codec = TypeDefinitionAwareCodec.from(((LeafSchemaNode) foo).getType()); assertThat(codec, instanceOf(UnionStringCodec.class)); assertDecoded(codec, Boolean.TRUE, "true"); assertDecoded(codec, Boolean.FALSE, "false"); assertDecoded(codec, "True"); assertDecoded(codec, "TRUE"); assertDecoded(codec, "False"); assertDecoded(codec, "FALSE"); }
Example #10
Source File: EffectiveStatementTypeTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testEmpty() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-empty")); assertNotNull(currentLeaf.getType()); final EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) .getTypeDefinition(); assertEquals(Optional.empty(), emptyEff.getUnits()); assertEquals(Optional.empty(), emptyEff.getDefaultValue()); assertNull(emptyEff.getBaseType()); assertEquals("empty", emptyEff.getQName().getLocalName()); assertNull(emptyEff.getPath().getParent().getParent()); assertNotNull(emptyEff.getUnknownSchemaNodes()); assertFalse(emptyEff.getDescription().isPresent()); assertFalse(emptyEff.getReference().isPresent()); assertEquals("CURRENT", emptyEff.getStatus().toString()); assertNotNull(emptyEff.toString()); }
Example #11
Source File: EffectiveStatementTypeTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testLeafref() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-leafref")); assertNotNull(currentLeaf.getType()); final LeafrefTypeDefinition leafrefEff = (LeafrefTypeDefinition) ((TypeDefinitionAware) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) .getTypeDefinition(); assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().getOriginalString()); assertNull(leafrefEff.getBaseType()); assertEquals(Optional.empty(), leafrefEff.getUnits()); assertEquals(Optional.empty(), leafrefEff.getDefaultValue()); assertNotNull(leafrefEff.toString()); assertEquals("leafref", leafrefEff.getQName().getLocalName()); assertEquals(Status.CURRENT, leafrefEff.getStatus()); assertNotNull(leafrefEff.getUnknownSchemaNodes()); assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName()); assertFalse(leafrefEff.getDescription().isPresent()); assertFalse(leafrefEff.getReference().isPresent()); assertNotNull(leafrefEff.hashCode()); assertFalse(leafrefEff.equals(null)); assertFalse(leafrefEff.equals("test")); assertTrue(leafrefEff.equals(leafrefEff)); }
Example #12
Source File: YT971Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testEscapeLexer() throws URISyntaxException, IOException, YangSyntaxErrorException, ReactorException { final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/bugs/YT971/test.yang"); assertNotNull(schemaContext); final DataSchemaNode someContainer = schemaContext.findDataChildByName( QName.create(NAMESPACE, "some-container")).get(); assertThat(someContainer, instanceOf(ContainerSchemaNode.class)); final ContainerSchemaNode containerSchemaNode = (ContainerSchemaNode) someContainer; final DataSchemaNode someLeaf = containerSchemaNode.findDataChildByName(QName.create(NAMESPACE, "some-leaf")) .get(); assertThat(someLeaf, instanceOf(LeafSchemaNode.class)); final LeafSchemaNode leafSchemaNode = (LeafSchemaNode) someLeaf; assertEquals(Optional.of("Some string that ends with a backslash (with escape backslash too) \\"), leafSchemaNode.getDescription()); assertThat(leafSchemaNode.getType(), instanceOf(Int16TypeDefinition.class)); final DataSchemaNode someOtherLeaf = containerSchemaNode.findDataChildByName( QName.create(NAMESPACE, "some-other-leaf")).get(); assertThat(someOtherLeaf, instanceOf(LeafSchemaNode.class)); final LeafSchemaNode otherLeafSchemaNode = (LeafSchemaNode) someOtherLeaf; assertEquals(Optional.of("Some string after the double backslash"), otherLeafSchemaNode.getDescription()); assertThat(otherLeafSchemaNode.getType(), instanceOf(Int32TypeDefinition.class)); }
Example #13
Source File: Bug9244Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testDeviateReplaceOfImplicitSubstatements() throws Exception { final SchemaContext schemaContext = StmtTestUtils.parseYangSources("/bugs/bug9244/"); assertNotNull(schemaContext); final Module barModule = schemaContext.findModule("bar", Revision.of("2017-10-13")).get(); final ContainerSchemaNode barCont = (ContainerSchemaNode) barModule.getDataChildByName( QName.create(barModule.getQNameModule(), "bar-cont")); assertNotNull(barCont); assertFalse(barCont.isConfiguration()); final LeafListSchemaNode barLeafList = (LeafListSchemaNode) barModule.getDataChildByName( QName.create(barModule.getQNameModule(), "bar-leaf-list")); assertNotNull(barLeafList); final ElementCountConstraint constraint = barLeafList.getElementCountConstraint().get(); assertEquals(5, constraint.getMinElements().intValue()); assertEquals(10, constraint.getMaxElements().intValue()); final LeafSchemaNode barLeaf = (LeafSchemaNode) barModule.getDataChildByName( QName.create(barModule.getQNameModule(), "bar-leaf")); assertNotNull(barLeaf); assertTrue(barLeaf.isMandatory()); }
Example #14
Source File: EffectiveStatementTypeTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testBinary() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-binary")); assertNotNull(currentLeaf.getType()); final BinaryTypeDefinition binaryEff = (BinaryTypeDefinition) ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf) .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(binaryEff.getBaseType()); assertEquals(Optional.empty(), binaryEff.getUnits()); assertEquals(Optional.empty(), binaryEff.getDefaultValue()); assertEquals("binary", binaryEff.getQName().getLocalName()); assertFalse(binaryEff.getLengthConstraint().isPresent()); assertEquals(Status.CURRENT, binaryEff.getStatus()); assertEquals("binary", binaryEff.getPath().getPathFromRoot().iterator().next().getLocalName()); assertNotNull(binaryEff.getUnknownSchemaNodes()); assertFalse(binaryEff.getDescription().isPresent()); assertFalse(binaryEff.getReference().isPresent()); }
Example #15
Source File: EffectiveStatementTypeTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testIdentityRef() { currentLeaf = (LeafSchemaNode) types .getDataChildByName(QName.create(types.getQNameModule(), "leaf-identityref")); assertNotNull(currentLeaf.getType()); final IdentityrefTypeDefinition identityRefEff = (IdentityrefTypeDefinition) ((TypeDefinitionAware) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) .getTypeDefinition(); assertEquals(Optional.empty(), identityRefEff.getDefaultValue()); assertEquals("identityref", identityRefEff.getQName().getLocalName()); assertEquals("identityref", identityRefEff.getPath().getLastComponent().getLocalName()); assertNull(identityRefEff.getBaseType()); assertNotNull(identityRefEff.getUnknownSchemaNodes()); assertEquals(Status.CURRENT, identityRefEff.getStatus()); assertEquals("test-identity", identityRefEff.getIdentities().iterator().next().getQName().getLocalName()); assertFalse(identityRefEff.getDescription().isPresent()); assertFalse(identityRefEff.getReference().isPresent()); assertNotNull(identityRefEff.toString()); // FIXME: the model is wrong, but we accept units in 'type' statement assertEquals(Optional.empty(), identityRefEff.getUnits()); }
Example #16
Source File: DataSchemaContextNode.java From yangtools with Eclipse Public License 1.0 | 6 votes |
public static @Nullable DataSchemaContextNode<?> fromDataSchemaNode(final DataSchemaNode potential) { if (potential instanceof ContainerSchemaNode) { return new ContainerContextNode((ContainerSchemaNode) potential); } else if (potential instanceof ListSchemaNode) { return fromListSchemaNode((ListSchemaNode) potential); } else if (potential instanceof LeafSchemaNode) { return new LeafContextNode((LeafSchemaNode) potential); } else if (potential instanceof ChoiceSchemaNode) { return new ChoiceNodeContextNode((ChoiceSchemaNode) potential); } else if (potential instanceof LeafListSchemaNode) { return fromLeafListSchemaNode((LeafListSchemaNode) potential); } else if (potential instanceof AnydataSchemaNode) { return new AnydataContextNode((AnydataSchemaNode) potential); } else if (potential instanceof AnyxmlSchemaNode) { return new AnyXmlContextNode((AnyxmlSchemaNode) potential); } return null; }
Example #17
Source File: YangParserTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testTypedefDecimal2() { final LeafSchemaNode testleaf = (LeafSchemaNode) foo.getDataChildByName(QName.create(foo.getQNameModule(), "decimal-leaf2")); assertTrue(testleaf.getType() instanceof DecimalTypeDefinition); final DecimalTypeDefinition type = (DecimalTypeDefinition) testleaf.getType(); assertEquals(QName.create(BAR, "my-decimal-type"), type.getQName()); assertEquals(Optional.empty(), type.getUnits()); assertEquals(Optional.empty(), type.getDefaultValue()); assertEquals(6, type.getFractionDigits()); assertEquals(1, type.getRangeConstraint().get().getAllowedRanges().asRanges().size()); final DecimalTypeDefinition baseTypeDecimal = type.getBaseType(); assertEquals(6, baseTypeDecimal.getFractionDigits()); }
Example #18
Source File: YT1100Test.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testChoiceCaseRelativeLeafref() { final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/yt1100.yang"); final Module module = context.findModule("yt1100").orElseThrow(); final QNameModule qnm = module.getQNameModule(); final DataSchemaNode leaf = module.findDataTreeChild( QName.create(qnm, "foo"), QName.create(qnm, "scheduler-node"), QName.create(qnm, "child-scheduler-nodes"), QName.create(qnm, "name")).orElseThrow(); assertThat(leaf, instanceOf(LeafSchemaNode.class)); final TypeDefinition<?> type = ((LeafSchemaNode) leaf).getType(); assertThat(type, instanceOf(LeafrefTypeDefinition.class)); final PathExpression leafref = ((LeafrefTypeDefinition) type).getPathStatement(); final SchemaNode ref = SchemaContextUtil.findDataSchemaNodeForRelativeXPath(context, module, leaf, leafref); assertThat(ref, instanceOf(LeafSchemaNode.class)); final LeafSchemaNode targetLeaf = (LeafSchemaNode) ref; assertEquals(QName.create(qnm, "name"), targetLeaf.getQName()); assertThat(targetLeaf.getType(), instanceOf(StringTypeDefinition.class)); }
Example #19
Source File: EffectiveBuildTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void extensionsTest() throws ReactorException { SchemaContext result = RFC7950Reactors.defaultReactor().newBuild().addSource(YANG_EXT).buildEffective(); assertNotNull(result); Collection<? extends GroupingDefinition> groupings = result.getGroupings(); assertEquals(1, groupings.size()); GroupingDefinition grp = groupings.iterator().next(); Collection<? extends DataSchemaNode> childNodes = grp.getChildNodes(); assertEquals(1, childNodes.size()); DataSchemaNode child = childNodes.iterator().next(); assertTrue(child instanceof LeafSchemaNode); LeafSchemaNode leaf = (LeafSchemaNode) child; assertNotNull(leaf.getType()); }
Example #20
Source File: LeafInterner.java From yangtools with Eclipse Public License 1.0 | 5 votes |
/** * Return a {@link LeafInterner} for a particular schema. Interner instances must not be reused for leaves of * different types, otherwise they may produce unexpected results. * * @param schema The leaf node's schema * @return An interner instance, if applicable */ public static <T extends LeafNode<?>> @NonNull Optional<Interner<T>> forSchema( final @Nullable LeafSchemaNode schema) { if (schema != null && isLowCardinality(schema.getType())) { return Optional.of(LeafInterner::intern); } return Optional.empty(); }
Example #21
Source File: Bug6669Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testValidAugment2() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6669/valid/test2"); assertNotNull(context); final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, ROOT, BAR, BAR_1, BAR_2, M)); assertTrue(findDataSchemaNode instanceof LeafSchemaNode); }
Example #22
Source File: Bug6887Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testRestrictedEnumeration() throws Exception { final SchemaContext schemaContext = StmtTestUtils.parseYangSource("/rfc7950/bug6887/foo.yang"); assertNotNull(schemaContext); final Module foo = schemaContext.findModule("foo", Revision.of("2017-01-26")).get(); final LeafSchemaNode myEnumerationLeaf = (LeafSchemaNode) foo.getDataChildByName( QName.create(foo.getQNameModule(), "my-enumeration-leaf")); assertNotNull(myEnumerationLeaf); EnumTypeDefinition enumerationType = (EnumTypeDefinition) myEnumerationLeaf.getType(); List<EnumPair> enums = enumerationType.getValues(); assertEquals(2, enums.size()); final EnumPair yellowEnum = createEnumPair("yellow", 2); final EnumPair redEnum = createEnumPair("red", 3); assertContainsEnums(enums, yellowEnum, redEnum); enumerationType = enumerationType.getBaseType(); enums = enumerationType.getValues(); assertEquals(3, enums.size()); final EnumPair blackEnum = createEnumPair("black", 4); assertContainsEnums(enums, yellowEnum, redEnum, blackEnum); enumerationType = enumerationType.getBaseType(); enums = enumerationType.getValues(); assertEquals(4, enums.size()); final EnumPair whiteEnum = createEnumPair("white", 1); assertContainsEnums(enums, whiteEnum, yellowEnum, redEnum, blackEnum); final LeafSchemaNode myEnumerationLeaf2 = (LeafSchemaNode) foo.getDataChildByName( QName.create(foo.getQNameModule(), "my-enumeration-leaf-2")); assertNotNull(myEnumerationLeaf2); enumerationType = (EnumTypeDefinition) myEnumerationLeaf2.getType(); enums = enumerationType.getValues(); assertEquals(3, enums.size()); assertContainsEnums(enums, yellowEnum, redEnum, blackEnum); }
Example #23
Source File: YT1050Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Before public void before() { context = YangParserTestUtils.parseYangResource("/yt1050.yang"); module = context.getModules().iterator().next(); final ListSchemaNode grpUses = (ListSchemaNode) module.findDataChildByName(GRP_USES).get(); primaryType = (LeafSchemaNode) grpUses.findDataChildByName(TYPE).get(); final GroupingDefinition grp = module.getGroupings().iterator().next(); secondaryType = (LeafSchemaNode) ((ListSchemaNode) grp.findDataChildByName(SECONDARY).get()) .findDataChildByName(TYPE).get(); }
Example #24
Source File: Bug8126Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8126"); assertNotNull(context); assertTrue(findNode(context, foo("root"), bar("my-container"), bar("my-choice"), bar("one"), bar("one"), bar("mandatory-leaf")) instanceof LeafSchemaNode); assertTrue(findNode(context, foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2")) instanceof LeafSchemaNode); assertNull(findNode(context, foo("root"), bar("mandatory-list"))); assertNull(findNode(context, foo("root"), bar("mandatory-container"), bar("mandatory-choice"))); assertNull(findNode(context, foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3"))); }
Example #25
Source File: Bug5410Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static PatternConstraint getPatternConstraintOf(final SchemaContext context, final String leafName) { final DataSchemaNode dataChildByName = context.getDataChildByName(foo(leafName)); assertTrue(dataChildByName instanceof LeafSchemaNode); final LeafSchemaNode leaf = (LeafSchemaNode) dataChildByName; final TypeDefinition<? extends TypeDefinition<?>> type = leaf.getType(); assertTrue(type instanceof StringTypeDefinition); final StringTypeDefinition strType = (StringTypeDefinition) type; return strType.getPatternConstraints().iterator().next(); }
Example #26
Source File: EffectiveStatementTypeTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testLeafrefWithDeref() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName .create(types.getQNameModule(), "leaf-leafref-deref")); assertNotNull(currentLeaf.getType()); final LeafrefTypeDefinition leafrefEff = (LeafrefTypeDefinition) ((TypeDefinitionAware) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) .getTypeDefinition(); assertEquals("deref(../container-test)/leaf-test", leafrefEff.getPathStatement().getOriginalString()); assertNull(leafrefEff.getBaseType()); assertEquals(Optional.empty(), leafrefEff.getUnits()); assertEquals(Optional.empty(), leafrefEff.getDefaultValue()); assertNotNull(leafrefEff.toString()); assertEquals("leafref", leafrefEff.getQName().getLocalName()); assertEquals(Status.CURRENT, leafrefEff.getStatus()); assertNotNull(leafrefEff.getUnknownSchemaNodes()); assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName()); assertFalse(leafrefEff.getDescription().isPresent()); assertFalse(leafrefEff.getReference().isPresent()); assertNotNull(leafrefEff.hashCode()); assertFalse(leafrefEff.equals(null)); assertFalse(leafrefEff.equals("test")); assertTrue(leafrefEff.equals(leafrefEff)); }
Example #27
Source File: XmlStreamUtilsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static LeafrefTypeDefinition findLeafrefType(final LeafSchemaNode schemaNode) { final TypeDefinition<?> type = schemaNode.getType(); if (type instanceof LeafrefTypeDefinition) { return (LeafrefTypeDefinition) type; } return null; }
Example #28
Source File: Bug5437Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void test() throws Exception { SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5437"); assertNotNull(context); QName root = QName.create(NS, REV, "root"); QName leafRef2 = QName.create(NS, REV, "leaf-ref-2"); QName conGrp = QName.create(NS, REV, "con-grp"); QName leafRef = QName.create(NS, REV, "leaf-ref"); SchemaPath leafRefPath = SchemaPath.create(true, root, conGrp, leafRef); SchemaPath leafRef2Path = SchemaPath.create(true, root, leafRef2); SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, leafRefPath); SchemaNode findDataSchemaNode2 = SchemaContextUtil.findDataSchemaNode(context, leafRef2Path); assertThat(findDataSchemaNode, isA(LeafSchemaNode.class)); assertThat(findDataSchemaNode2, isA(LeafSchemaNode.class)); LeafSchemaNode leafRefNode = (LeafSchemaNode) findDataSchemaNode; LeafSchemaNode leafRefNode2 = (LeafSchemaNode) findDataSchemaNode2; assertThat(leafRefNode.getType(), isA(LeafrefTypeDefinition.class)); assertThat(leafRefNode2.getType(), isA(LeafrefTypeDefinition.class)); TypeDefinition<?> baseTypeForLeafRef = SchemaContextUtil.getBaseTypeForLeafRef( (LeafrefTypeDefinition) leafRefNode.getType(), context, leafRefNode); TypeDefinition<?> baseTypeForLeafRef2 = SchemaContextUtil.getBaseTypeForLeafRef( (LeafrefTypeDefinition) leafRefNode2.getType(), context, leafRefNode2); assertThat(baseTypeForLeafRef, isA(BinaryTypeDefinition.class)); assertThat(baseTypeForLeafRef2, isA(Int16TypeDefinition.class)); }
Example #29
Source File: XmlStreamUtilsTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private TypeDefinition<?> getTargetNodeForLeafRef(final String nodeName, final Class<?> clas) { final LeafSchemaNode schemaNode = findSchemaNodeWithLeafrefType(leafRefModule, nodeName); assertNotNull(schemaNode); final LeafrefTypeDefinition leafrefTypedef = findLeafrefType(schemaNode); assertNotNull(leafrefTypedef); final TypeDefinition<?> targetBaseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypedef, schemaContext, schemaNode); assertTrue("Wrong class found.", clas.isInstance(targetBaseType)); return targetBaseType; }
Example #30
Source File: Bug5481Test.java From yangtools with Eclipse Public License 1.0 | 5 votes |
private static void verifyExtendedLeaf(final ContainerSchemaNode topContainer) { DataSchemaNode dataChildByName2 = topContainer.getDataChildByName(QName.create("http://example.com/module2", "2016-03-09", "extended-leaf")); assertTrue(dataChildByName2 instanceof LeafSchemaNode); LeafSchemaNode extendedLeaf = (LeafSchemaNode) dataChildByName2; assertEquals(Status.DEPRECATED, extendedLeaf.getStatus()); assertEquals(Optional.of("text"), extendedLeaf.getDescription()); assertEquals(Optional.of("ref"), extendedLeaf.getReference()); RevisionAwareXPath whenConditionExtendedLeaf = extendedLeaf.getWhenCondition().get(); assertFalse(whenConditionExtendedLeaf.isAbsolute()); assertThat(whenConditionExtendedLeaf, instanceOf(WithExpression.class)); assertEquals("module1:top = 'extended'", whenConditionExtendedLeaf.getOriginalString()); }