use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.
the class EffectiveStatementTypeTest method testBinary.
@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());
assertNotNull(binaryEff.getUnknownSchemaNodes());
assertFalse(binaryEff.getDescription().isPresent());
assertFalse(binaryEff.getReference().isPresent());
}
use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.
the class EffectiveStatementTypeTest method testDecimal64.
@Test
public void testDecimal64() {
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-decimal64"));
assertNotNull(currentLeaf.getType());
final DecimalTypeDefinition decimal64Eff = (DecimalTypeDefinition) ((TypeDefinitionAware) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
assertNull(decimal64Eff.getBaseType());
assertEquals(Optional.empty(), decimal64Eff.getUnits());
assertEquals(Optional.empty(), decimal64Eff.getDefaultValue());
assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
assertNotNull(decimal64Eff.getUnknownSchemaNodes());
// FIXME: The yang model api is wrong: description/reference/status are not allowed under 'type', how come we
// parse it?
// allowed under 'type', how come we parse it?
assertFalse(decimal64Eff.getDescription().isPresent());
assertFalse(decimal64Eff.getReference().isPresent());
assertEquals(Status.CURRENT, decimal64Eff.getStatus());
assertEquals(3, decimal64Eff.getRangeConstraint().get().getAllowedRanges().asRanges().size());
assertNotNull(decimal64Eff.toString());
assertNotNull(decimal64Eff.hashCode());
assertEquals(2, decimal64Eff.getFractionDigits());
assertFalse(decimal64Eff.equals(null));
assertFalse(decimal64Eff.equals("test"));
assertTrue(decimal64Eff.equals(decimal64Eff));
}
use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.
the class YT1208Test method testLeafStatementReuse.
@Test
public void testLeafStatementReuse() throws Exception {
final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1208/leaf.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
assertNotNull(module);
final NotificationEffectiveStatement notif = module.findFirstEffectiveSubstatement(NotificationEffectiveStatement.class).orElseThrow();
final LeafEffectiveStatement grpBar = notif.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
final LeafEffectiveStatement contBar = notif.findFirstEffectiveSubstatement(ContainerEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
assertSame(contBar, grpBar);
}
use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.
the class Bug6972Test method getEffectiveUnits.
private static UnitsEffectiveStatement getEffectiveUnits(final Module module, final QName containerQName, final QName leafQName) {
UnitsEffectiveStatement units = null;
final ContainerSchemaNode cont = (ContainerSchemaNode) module.getDataChildByName(containerQName);
assertNotNull(cont);
final LeafSchemaNode leaf = (LeafSchemaNode) cont.getDataChildByName(leafQName);
assertNotNull(leaf);
for (EffectiveStatement<?, ?> effStmt : ((LeafEffectiveStatement) leaf).effectiveSubstatements()) {
if (effStmt instanceof UnitsEffectiveStatement) {
units = (UnitsEffectiveStatement) effStmt;
break;
}
}
return units;
}
use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.
the class YT1209Test method testWhenStatementReuse.
@Test
public void testWhenStatementReuse() throws Exception {
final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1209/when.yang").getModuleStatement(QNameModule.create(XMLNamespace.of("foo")));
final LeafEffectiveStatement grpFoo = module.findFirstEffectiveSubstatement(GroupingEffectiveStatement.class).orElseThrow().findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
final LeafEffectiveStatement foo = module.findFirstEffectiveSubstatement(LeafEffectiveStatement.class).orElseThrow();
// The statements should not be the same due SchemaPath being part of LeafSchemaNode
assertNotSame(foo, grpFoo);
// The statements are instantiated in the same module, hence they should have the same argument
assertSame(foo.argument(), grpFoo.argument());
// The statements' when substatement should be reused
assertSame(foo.findFirstEffectiveSubstatement(WhenEffectiveStatement.class).orElseThrow(), grpFoo.findFirstEffectiveSubstatement(WhenEffectiveStatement.class).orElseThrow());
}
Aggregations