Search in sources :

Example 11 with LeafEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.

the class YT1212Test method testLeafStatementReuse.

@Test
public void testLeafStatementReuse() throws Exception {
    final ModuleEffectiveStatement module = StmtTestUtils.parseYangSource("/bugs/YT1212/leaf.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 'type' is not context-independent, but it being copy-insensitive and statements get reused
    assertSame(foo.effectiveSubstatements(), grpFoo.effectiveSubstatements());
}
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)

Example 12 with LeafEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.

the class EffectiveStatementTypeTest method testIdentityRef.

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

Example 13 with LeafEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.

the class EffectiveStatementTypeTest method testBits.

@Test
public void testBits() {
    currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-bits"));
    assertNotNull(currentLeaf.getType());
    final Iterator<? extends Bit> bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits().iterator();
    final Bit bitEff = bitsEffIter.next();
    final Bit bitEffSecond = bitsEffIter.next();
    final BitsTypeDefinition bitsEff = (BitsTypeDefinition) ((TypeDefinitionAware) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
    assertNull(bitsEff.getBaseType());
    assertNotNull(bitsEff.getQName());
    assertEquals("bits", bitsEff.getQName().getLocalName());
    assertNotNull(bitsEff.getUnknownSchemaNodes());
    assertFalse(bitsEff.getDescription().isPresent());
    assertFalse(bitsEff.getReference().isPresent());
    assertEquals(Status.CURRENT, bitsEff.getStatus());
    assertEquals(Optional.empty(), bitsEff.getUnits());
    assertNotNull(bitsEff.toString());
    assertNotNull(bitsEff.hashCode());
    assertFalse(bitsEff.equals(null));
    assertFalse(bitsEff.equals("test"));
    assertTrue(bitsEff.equals(bitsEff));
    assertEquals(3, bitsEff.getBits().size());
    assertEquals(Optional.empty(), bitsEff.getDefaultValue());
    assertNotNull(bitEff.getUnknownSchemaNodes());
    assertEquals(Optional.of("test bit"), bitEff.getDescription());
    assertEquals(Optional.of("test bit ref"), bitEff.getReference());
    assertEquals(Status.CURRENT, bitEff.getStatus());
    assertNotNull(bitEff.hashCode());
    assertFalse(bitEff.equals(null));
    assertFalse(bitEff.equals("test"));
    assertFalse(bitEff.equals(bitEffSecond));
    assertNotNull(bitEff.toString());
    assertEquals("one", bitEff.getName());
    assertEquals(Uint32.ZERO, bitEff.getPosition());
}
Also used : BitsTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) Bit(org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit) Test(org.junit.Test)

Example 14 with LeafEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.

the class EffectiveStatementTypeTest method testEnum.

@Test
public void testEnum() {
    currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-enum"));
    assertNotNull(currentLeaf.getType());
    final List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
    final EnumPair enumEff = enumEffIter.iterator().next();
    final EnumTypeDefinition enumSpecEff = (EnumTypeDefinition) ((TypeDefinitionAware) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
    assertEquals("enumeration", enumSpecEff.getQName().getLocalName());
    assertEquals(Optional.empty(), enumSpecEff.getDefaultValue());
    assertEquals(3, enumSpecEff.getValues().size());
    assertNull(enumSpecEff.getBaseType());
    assertNotNull(enumSpecEff.getUnknownSchemaNodes());
    assertEquals(Status.CURRENT, enumSpecEff.getStatus());
    assertFalse(enumSpecEff.getDescription().isPresent());
    assertFalse(enumSpecEff.getReference().isPresent());
    assertEquals(Optional.empty(), enumSpecEff.getUnits());
    assertNotNull(enumSpecEff.toString());
    assertNotNull(enumSpecEff.hashCode());
    assertFalse(enumSpecEff.equals(null));
    assertFalse(enumSpecEff.equals("test"));
    assertTrue(enumSpecEff.equals(enumSpecEff));
    assertEquals("zero", enumEff.getName());
    assertNotNull(enumEff.getUnknownSchemaNodes());
    assertEquals(Optional.of("test enum"), enumEff.getDescription());
    assertEquals(Optional.of("test enum ref"), enumEff.getReference());
    assertEquals(Status.CURRENT, enumEff.getStatus());
    assertEquals(0, enumEff.getValue());
}
Also used : EnumPair(org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair) EnumTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition) LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) Test(org.junit.Test)

Example 15 with LeafEffectiveStatement

use of org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement in project yangtools by opendaylight.

the class EffectiveStatementTypeTest method testUnion.

@Test
public void testUnion() {
    currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-union"));
    assertNotNull(currentLeaf.getType());
    final UnionTypeDefinition unionEff = (UnionTypeDefinition) ((TypeDefinitionAware) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
    assertEquals(2, unionEff.getTypes().size());
    assertEquals("union", unionEff.getQName().getLocalName());
    assertEquals("CURRENT", unionEff.getStatus().toString());
    assertNotNull(unionEff.getUnknownSchemaNodes());
    assertNull(unionEff.getBaseType());
    assertEquals(Optional.empty(), unionEff.getUnits());
    assertEquals(Optional.empty(), unionEff.getDefaultValue());
    assertFalse(unionEff.getDescription().isPresent());
    assertFalse(unionEff.getReference().isPresent());
    assertNotNull(unionEff.toString());
    assertNotNull(unionEff.hashCode());
    assertFalse(unionEff.equals(null));
    assertFalse(unionEff.equals("test"));
    assertTrue(unionEff.equals(unionEff));
}
Also used : LeafEffectiveStatement(org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement) UnionTypeDefinition(org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition) 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