Search in sources :

Example 6 with LeafEffectiveStatement

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());
}
Also used : LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) BinaryTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition) Test(org.junit.Test)

Example 7 with LeafEffectiveStatement

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));
}
Also used : DecimalTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) Test(org.junit.Test)

Example 8 with LeafEffectiveStatement

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);
}
Also used : ContainerEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement) GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) NotificationEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Example 9 with LeafEffectiveStatement

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;
}
Also used : UnitsEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)

Example 10 with LeafEffectiveStatement

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());
}
Also used : GroupingEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) ModuleEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement) Test(org.junit.Test)

Aggregations

LeafEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement)16 Test (org.junit.Test)15 GroupingEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.GroupingEffectiveStatement)3 ModuleEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ModuleEffectiveStatement)3 LeafrefTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition)2 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)1 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)1 ContainerEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.ContainerEffectiveStatement)1 NotificationEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.NotificationEffectiveStatement)1 UnitsEffectiveStatement (org.opendaylight.yangtools.yang.model.api.stmt.UnitsEffectiveStatement)1 BinaryTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition)1 BitsTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition)1 Bit (org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit)1 BooleanTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition)1 DecimalTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition)1 EmptyTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition)1 EnumTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition)1 EnumPair (org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair)1 IdentityrefTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition)1 InstanceIdentifierTypeDefinition (org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition)1