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());
}
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());
}
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());
}
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());
}
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));
}
Aggregations