X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-parser-impl%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fstmt%2FEffectiveStatementTypeTest.java;h=0cdbc4b0e295d6253552efc2085f220d0efc8133;hb=3b445156dfea75955b98f40208ffea51fe252209;hp=669e7d3d6bc04d4a47b8cdf1aa2a63e57b39e543;hpb=b81b12961e1d021c241e285e32ef20595a3098bd;p=yangtools.git diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java index 669e7d3d6b..0cdbc4b0e2 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java @@ -15,12 +15,17 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource; +import com.google.common.collect.Range; import java.util.List; -import org.junit.Before; +import java.util.Optional; +import org.junit.BeforeClass; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.Status; +import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; @@ -34,35 +39,30 @@ import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint; +import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint; import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; +import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors; +import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.BitsSpecificationEffectiveStatement; +import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.Decimal64SpecificationEffectiveStatement; +import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.EnumSpecificationEffectiveStatement; +import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.IdentityRefSpecificationEffectiveStatement; +import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.LeafrefSpecificationEffectiveStatement; +import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.UnionSpecificationEffectiveStatement; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; -import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource; -import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitsSpecificationEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Decimal64SpecificationEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumSpecificationEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IdentityRefSpecificationEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.PatternConstraintEffectiveImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionSpecificationEffectiveStatementImpl; public class EffectiveStatementTypeTest { - - private static final StatementStreamSource IMPORTED_MODULE = sourceForResource("/type-tests/types.yang"); - private static EffectiveSchemaContext effectiveSchemaContext; - private static LeafSchemaNode currentLeaf; + private static SchemaContext effectiveSchemaContext; private static Module types; - @Before - public void setup() throws ReactorException { - final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); - reactor.addSource(IMPORTED_MODULE); - effectiveSchemaContext = reactor.buildEffective(); - types = effectiveSchemaContext.findModuleByName("types", null); + private LeafSchemaNode currentLeaf; + + @BeforeClass + public static void setup() throws ReactorException { + effectiveSchemaContext = RFC7950Reactors.defaultReactor().newBuild() + .addSource(sourceForResource("/type-tests/types.yang")) + .buildEffective(); + types = effectiveSchemaContext.findModules("types").iterator().next(); assertNotNull(types); } @@ -71,19 +71,20 @@ public class EffectiveStatementTypeTest { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-binary")); assertNotNull(currentLeaf.getType()); - final BinaryTypeDefinition binaryEff = (BinaryTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + final BinaryTypeDefinition binaryEff = (BinaryTypeDefinition) + ((TypeEffectiveStatement) ((LeafEffectiveStatement) currentLeaf) .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(binaryEff.getBaseType()); - assertNull(binaryEff.getUnits()); - assertNull(binaryEff.getDefaultValue()); + assertEquals(Optional.empty(), binaryEff.getUnits()); + assertEquals(Optional.empty(), binaryEff.getDefaultValue()); assertEquals("binary", binaryEff.getQName().getLocalName()); - assertEquals(0, binaryEff.getLengthConstraints().size()); - assertEquals("CURRENT", binaryEff.getStatus().toString()); + assertFalse(binaryEff.getLengthConstraint().isPresent()); + assertEquals(Status.CURRENT, binaryEff.getStatus()); assertEquals("binary", binaryEff.getPath().getPathFromRoot().iterator().next().getLocalName()); assertNotNull(binaryEff.getUnknownSchemaNodes()); - assertNull(binaryEff.getDescription()); - assertNull(binaryEff.getReference()); + assertFalse(binaryEff.getDescription().isPresent()); + assertFalse(binaryEff.getReference().isPresent()); } @Test @@ -95,31 +96,32 @@ public class EffectiveStatementTypeTest { final Bit bitEff = bitsEffIter.get(0); final Bit bitEffSecond = bitsEffIter.get(1); - final BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); assertNull(bitsEff.getBaseType()); assertNotNull(bitsEff.getQName()); assertEquals("bits", bitsEff.getQName().getLocalName()); assertEquals("bits", bitsEff.getPath().getLastComponent().getLocalName()); assertNotNull(bitsEff.getUnknownSchemaNodes()); - assertNull(bitsEff.getDescription()); - assertNull(bitsEff.getReference()); - assertEquals("CURRENT", bitsEff.getStatus().toString()); - assertNull(bitsEff.getUnits()); + 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()); - assertNull(bitsEff.getDefaultValue()); + assertEquals(Optional.empty(), bitsEff.getDefaultValue()); assertNotNull(bitEff.getPath()); assertNotNull(bitEff.getUnknownSchemaNodes()); - assertEquals("test bit", bitEff.getDescription()); - assertEquals("test bit ref", bitEff.getReference()); - assertEquals("CURRENT", bitEff.getStatus().toString()); + 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")); @@ -134,18 +136,19 @@ public class EffectiveStatementTypeTest { public void testBoolean() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-boolean")); assertNotNull(currentLeaf.getType()); - final BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); assertNull(booleanEff.getBaseType()); - assertNull(booleanEff.getUnits()); - assertNull(booleanEff.getDefaultValue()); + assertEquals(Optional.empty(), booleanEff.getUnits()); + assertEquals(Optional.empty(), booleanEff.getDefaultValue()); assertEquals("boolean", booleanEff.getQName().getLocalName()); assertNull(booleanEff.getPath().getParent().getParent()); assertNotNull(booleanEff.getUnknownSchemaNodes()); - assertNull(booleanEff.getDescription()); - assertNull(booleanEff.getReference()); - assertEquals("CURRENT", booleanEff.getStatus().toString()); + assertFalse(booleanEff.getDescription().isPresent()); + assertFalse(booleanEff.getReference().isPresent()); + assertEquals(Status.CURRENT, booleanEff.getStatus()); assertNotNull(booleanEff.toString()); } @@ -153,25 +156,27 @@ public class EffectiveStatementTypeTest { public void testDecimal64() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-decimal64")); assertNotNull(currentLeaf.getType()); - final DecimalTypeDefinition decimal64Eff = ((Decimal64SpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final DecimalTypeDefinition decimal64Eff = ((Decimal64SpecificationEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); assertNull(decimal64Eff.getBaseType()); - assertNull(decimal64Eff.getUnits()); - assertNull(decimal64Eff.getDefaultValue()); + 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? + // 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? - assertNull(decimal64Eff.getDescription()); - assertNull(decimal64Eff.getReference()); - assertEquals("CURRENT", decimal64Eff.getStatus().toString()); + assertFalse(decimal64Eff.getDescription().isPresent()); + assertFalse(decimal64Eff.getReference().isPresent()); + assertEquals(Status.CURRENT, decimal64Eff.getStatus()); - assertEquals(3, decimal64Eff.getRangeConstraints().size()); + assertEquals(3, decimal64Eff.getRangeConstraint().get().getAllowedRanges().asRanges().size()); assertNotNull(decimal64Eff.toString()); assertNotNull(decimal64Eff.hashCode()); - assertTrue(decimal64Eff.getFractionDigits().equals(2)); + assertEquals(2, decimal64Eff.getFractionDigits()); assertFalse(decimal64Eff.equals(null)); assertFalse(decimal64Eff.equals("test")); assertTrue(decimal64Eff.equals(decimal64Eff)); @@ -182,17 +187,18 @@ public class EffectiveStatementTypeTest { public void testEmpty() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-empty")); assertNotNull(currentLeaf.getType()); - final EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); - assertNull(emptyEff.getUnits()); - assertNull(emptyEff.getDefaultValue()); + 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()); - assertNull(emptyEff.getDescription()); - assertNull(emptyEff.getReference()); + assertFalse(emptyEff.getDescription().isPresent()); + assertFalse(emptyEff.getReference().isPresent()); assertEquals("CURRENT", emptyEff.getStatus().toString()); assertNotNull(emptyEff.toString()); } @@ -204,19 +210,20 @@ public class EffectiveStatementTypeTest { final List enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues(); final EnumPair enumEff = enumEffIter.iterator().next(); - final EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); assertEquals("enumeration", enumSpecEff.getQName().getLocalName()); assertEquals("enumeration", enumSpecEff.getPath().getLastComponent().getLocalName()); - assertNull(enumSpecEff.getDefaultValue()); + assertEquals(Optional.empty(), enumSpecEff.getDefaultValue()); assertEquals(3, enumSpecEff.getValues().size()); assertNull(enumSpecEff.getBaseType()); assertNotNull(enumSpecEff.getUnknownSchemaNodes()); - assertEquals("CURRENT", enumSpecEff.getStatus().toString()); - assertNull(enumSpecEff.getDescription()); - assertNull(enumSpecEff.getReference()); - assertNull(enumSpecEff.getUnits()); + 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)); @@ -225,9 +232,9 @@ public class EffectiveStatementTypeTest { assertEquals("zero", enumEff.getName()); assertNotNull(enumEff.getUnknownSchemaNodes()); - assertEquals("test enum", enumEff.getDescription()); - assertEquals("test enum ref", enumEff.getReference()); - assertEquals("CURRENT", enumEff.getStatus().toString()); + assertEquals(Optional.of("test enum"), enumEff.getDescription()); + assertEquals(Optional.of("test enum ref"), enumEff.getReference()); + assertEquals(Status.CURRENT, enumEff.getStatus()); assertEquals(0, enumEff.getValue()); } @@ -236,22 +243,23 @@ public class EffectiveStatementTypeTest { currentLeaf = (LeafSchemaNode) types .getDataChildByName(QName.create(types.getQNameModule(), "leaf-identityref")); assertNotNull(currentLeaf.getType()); - final IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); - assertNull(identityRefEff.getDefaultValue()); + assertEquals(Optional.empty(), identityRefEff.getDefaultValue()); assertEquals("identityref", identityRefEff.getQName().getLocalName()); assertEquals("identityref", identityRefEff.getPath().getLastComponent().getLocalName()); assertNull(identityRefEff.getBaseType()); assertNotNull(identityRefEff.getUnknownSchemaNodes()); - assertEquals("CURRENT", identityRefEff.getStatus().toString()); - assertEquals("test-identity", identityRefEff.getIdentity().getQName().getLocalName()); - assertNull(identityRefEff.getDescription()); - assertNull(identityRefEff.getReference()); + 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 - assertNull(identityRefEff.getUnits()); + assertEquals(Optional.empty(), identityRefEff.getUnits()); } @Test @@ -259,20 +267,21 @@ public class EffectiveStatementTypeTest { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-instance-identifier")); assertNotNull(currentLeaf.getType()); - final InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition) + ((TypeEffectiveStatement) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements() + .iterator().next()).getTypeDefinition(); assertNotNull(instanceIdentEff.toString()); assertFalse(instanceIdentEff.requireInstance()); assertEquals("instance-identifier", instanceIdentEff.getQName().getLocalName()); assertEquals("instance-identifier", instanceIdentEff.getPath().getLastComponent().getLocalName()); assertNull(instanceIdentEff.getBaseType()); - assertNull(instanceIdentEff.getDefaultValue()); + assertEquals(Optional.empty(), instanceIdentEff.getDefaultValue()); assertNotNull(instanceIdentEff.getUnknownSchemaNodes()); - assertNull(instanceIdentEff.getDescription()); - assertNull(instanceIdentEff.getReference()); - assertNull(instanceIdentEff.getUnits()); - assertEquals("CURRENT", instanceIdentEff.getStatus().toString()); + assertFalse(instanceIdentEff.getDescription().isPresent()); + assertFalse(instanceIdentEff.getReference().isPresent()); + assertEquals(Optional.empty(), instanceIdentEff.getUnits()); + assertEquals(Status.CURRENT, instanceIdentEff.getStatus()); assertNotNull(instanceIdentEff.hashCode()); assertFalse(instanceIdentEff.equals(null)); assertFalse(instanceIdentEff.equals("test")); @@ -284,20 +293,21 @@ public class EffectiveStatementTypeTest { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-leafref")); assertNotNull(currentLeaf.getType()); - final LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().toString()); assertNull(leafrefEff.getBaseType()); - assertNull(leafrefEff.getUnits()); - assertNull(leafrefEff.getDefaultValue()); + assertEquals(Optional.empty(), leafrefEff.getUnits()); + assertEquals(Optional.empty(), leafrefEff.getDefaultValue()); assertNotNull(leafrefEff.toString()); assertEquals("leafref", leafrefEff.getQName().getLocalName()); - assertEquals("CURRENT", leafrefEff.getStatus().toString()); + assertEquals(Status.CURRENT, leafrefEff.getStatus()); assertNotNull(leafrefEff.getUnknownSchemaNodes()); assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName()); - assertNull(leafrefEff.getDescription()); - assertNull(leafrefEff.getReference()); + assertFalse(leafrefEff.getDescription().isPresent()); + assertFalse(leafrefEff.getReference().isPresent()); assertNotNull(leafrefEff.hashCode()); assertFalse(leafrefEff.equals(null)); assertFalse(leafrefEff.equals("test")); @@ -308,50 +318,50 @@ public class EffectiveStatementTypeTest { public void testIntAll() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int8")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement int8Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement int8Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(int8Eff.toString()); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int16")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement int16Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement int16Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(int16Eff.toString()); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int32")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement int32Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement int32Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(int32Eff.toString()); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int64")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement int64Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement int64Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(int64Eff.toString()); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint8")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement uint8Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement uint8Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(uint8Eff.toString()); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint16")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement uint16Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement uint16Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(uint16Eff.toString()); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint32")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement uint32Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement uint32Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(uint32Eff.toString()); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint64")); assertNotNull(currentLeaf.getType()); - final TypeEffectiveStatement uint64Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next(); + final TypeEffectiveStatement uint64Eff = (TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next(); assertNotNull(uint64Eff.toString()); } @@ -359,18 +369,19 @@ public class EffectiveStatementTypeTest { public void testUnion() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-union")); assertNotNull(currentLeaf.getType()); - final UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatement) + ((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()); - assertNull(unionEff.getUnits()); - assertNull(unionEff.getDefaultValue()); - assertNull(unionEff.getDescription()); - assertNull(unionEff.getReference()); + 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)); @@ -383,29 +394,29 @@ public class EffectiveStatementTypeTest { public void testLengthConstraint() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-length-pattern")); - assertNotNull(currentLeaf.getType()); - final LengthConstraint lengthConstraint = ((StringTypeDefinition) (currentLeaf.getType())) - .getLengthConstraints().get(0); - final LengthConstraint lengthConstraintThird = ((StringTypeDefinition) (currentLeaf.getType())) - .getLengthConstraints().get(0); - currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), - "leaf-length-pattern-second")); - assertNotNull(currentLeaf.getType()); - final LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) (currentLeaf.getType())) - .getLengthConstraints().get(0); - - assertEquals(1, lengthConstraint.getMin().intValue()); - assertEquals(255, lengthConstraint.getMax().intValue()); - assertNull(lengthConstraint.getReference()); - assertNull(lengthConstraint.getDescription()); - assertEquals("The argument is out of bounds <1, 255>", lengthConstraint.getErrorMessage()); - assertEquals("length-out-of-specified-bounds", lengthConstraint.getErrorAppTag()); + + final StringTypeDefinition leafType = (StringTypeDefinition) currentLeaf.getType(); + assertNotNull(leafType); + final LengthConstraint lengthConstraint = leafType.getLengthConstraint().get(); + + final Range span = lengthConstraint.getAllowedRanges().span(); + assertEquals(1, span.lowerEndpoint().intValue()); + assertEquals(255, span.upperEndpoint().intValue()); + assertFalse(lengthConstraint.getReference().isPresent()); + assertFalse(lengthConstraint.getDescription().isPresent()); + assertFalse(lengthConstraint.getErrorMessage().isPresent()); + assertFalse(lengthConstraint.getErrorAppTag().isPresent()); assertNotNull(lengthConstraint.toString()); assertNotNull(lengthConstraint.hashCode()); assertFalse(lengthConstraint.equals(null)); assertFalse(lengthConstraint.equals("test")); + + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), + "leaf-length-pattern-second")); + assertNotNull(currentLeaf.getType()); + final LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) currentLeaf.getType()) + .getLengthConstraint().get(); assertFalse(lengthConstraint.equals(lengthConstraintSecond)); - assertTrue(lengthConstraint.equals(lengthConstraintThird)); } @Test @@ -413,21 +424,22 @@ public class EffectiveStatementTypeTest { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-length-pattern")); assertNotNull(currentLeaf.getType()); - final PatternConstraintEffectiveImpl patternConstraint = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf - .getType())).getPatternConstraints().get(0); - final PatternConstraintEffectiveImpl patternConstraintThird = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf - .getType())).getPatternConstraints().get(0); + final PatternConstraint patternConstraint = ((StringTypeDefinition) currentLeaf.getType()) + .getPatternConstraints().get(0); + final PatternConstraint patternConstraintThird = ((StringTypeDefinition) currentLeaf.getType()) + .getPatternConstraints().get(0); currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-length-pattern-second")); assertNotNull(currentLeaf.getType()); - final PatternConstraintEffectiveImpl patternConstraintSecond = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf - .getType())).getPatternConstraints().get(0); - - assertEquals("^[0-9a-fA-F]*$", patternConstraint.getRegularExpression()); - assertNull(patternConstraint.getReference()); - assertNull(patternConstraint.getDescription()); - assertEquals("Supplied value does not match the regular expression ^[0-9a-fA-F]*$.", patternConstraint.getErrorMessage()); - assertEquals("invalid-regular-expression", patternConstraint.getErrorAppTag()); + final PatternConstraint patternConstraintSecond = ((StringTypeDefinition) currentLeaf.getType()) + .getPatternConstraints().get(0); + + assertEquals("^[0-9a-fA-F]*$", patternConstraint.getJavaPatternString()); + assertFalse(patternConstraint.getReference().isPresent()); + assertFalse(patternConstraint.getDescription().isPresent()); + assertEquals(Optional.of("Supplied value does not match the regular expression ^[0-9a-fA-F]*$."), + patternConstraint.getErrorMessage()); + assertEquals(Optional.of("invalid-regular-expression"), patternConstraint.getErrorAppTag()); assertNotNull(patternConstraint.toString()); assertNotNull(patternConstraint.hashCode()); assertFalse(patternConstraint.equals(null)); @@ -440,24 +452,25 @@ public class EffectiveStatementTypeTest { public void testString() { currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-string")); assertNotNull(currentLeaf.getType()); - final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement) + ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next()) + .getTypeDefinition(); assertEquals("string", stringEff.getQName().getLocalName()); - assertEquals("CURRENT", stringEff.getStatus().toString()); - assertNull(stringEff.getUnits()); - assertNull(stringEff.getDefaultValue()); + assertEquals(Status.CURRENT, stringEff.getStatus()); + assertEquals(Optional.empty(), stringEff.getUnits()); + assertEquals(Optional.empty(), stringEff.getDefaultValue()); assertNotNull(stringEff.getUnknownSchemaNodes()); assertNull(stringEff.getBaseType()); - assertNull(stringEff.getDescription()); - assertNull(stringEff.getReference()); + 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()); - assertEquals(0, stringEff.getLengthConstraints().size()); + assertFalse(stringEff.getLengthConstraint().isPresent()); assertNotNull(stringEff.getPatternConstraints()); } }