import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import java.util.List;
import org.junit.Before;
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;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
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.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
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.YangStatementSourceImpl;
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.BitEffectiveStatementImpl;
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.EnumEffectiveStatementImpl;
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;
public class EffectiveStatementTypeTest {
- private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl(
- "/type-tests/types.yang", false);
+ private static final StatementStreamSource IMPORTED_MODULE = sourceForResource("/type-tests/types.yang");
private static EffectiveSchemaContext effectiveSchemaContext;
private static LeafSchemaNode currentLeaf;
private static Module types;
assertNotNull(currentLeaf.getType());
final List<BitsTypeDefinition.Bit> bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits();
- final BitEffectiveStatementImpl bitEff = (BitEffectiveStatementImpl) bitsEffIter.get(0);
- final BitEffectiveStatementImpl bitEffSecond = (BitEffectiveStatementImpl) bitsEffIter.get(1);
+ final Bit bitEff = bitsEffIter.get(0);
+ final Bit bitEffSecond = bitsEffIter.get(1);
final BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
.effectiveSubstatements().iterator().next()).getTypeDefinition();
assertNotNull(bitEff.toString());
assertEquals("one", bitEff.getName());
assertNotNull(bitEff.getQName());
- assertEquals("0", bitEff.getPosition().toString());
- assertEquals(0, bitEff.getPosition().longValue());
+ assertEquals(0, bitEff.getPosition());
}
@Test
assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
assertNotNull(decimal64Eff.getUnknownSchemaNodes());
- // FIXME: The model is wrong: description/reference/status are not
+ // 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());
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-enum"));
assertNotNull(currentLeaf.getType());
final List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
- final EnumEffectiveStatementImpl enumEff = (EnumEffectiveStatementImpl) enumEffIter.iterator().next();
+ final EnumPair enumEff = enumEffIter.iterator().next();
final EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
.effectiveSubstatements().iterator().next()).getTypeDefinition();
assertEquals("test enum", enumEff.getDescription());
assertEquals("test enum ref", enumEff.getReference());
assertEquals("CURRENT", enumEff.getStatus().toString());
- assertEquals("0", enumEff.getValue().toString());
+ assertEquals(0, enumEff.getValue());
}
@Test
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
"leaf-length-pattern"));
assertNotNull(currentLeaf.getType());
- final PatternConstraintEffectiveImpl lengthConstraint = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf
+ final PatternConstraintEffectiveImpl patternConstraint = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf
.getType())).getPatternConstraints().get(0);
- final PatternConstraintEffectiveImpl lengthConstraintThird = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf
+ final PatternConstraintEffectiveImpl patternConstraintThird = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf
.getType())).getPatternConstraints().get(0);
currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
"leaf-length-pattern-second"));
assertNotNull(currentLeaf.getType());
- final PatternConstraintEffectiveImpl lengthConstraintSecond = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf
+ final PatternConstraintEffectiveImpl patternConstraintSecond = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf
.getType())).getPatternConstraints().get(0);
- assertEquals("^[0-9a-fA-F]*$", lengthConstraint.getRegularExpression());
- assertNull(lengthConstraint.getReference());
- assertNull(lengthConstraint.getDescription());
- assertEquals("String ^[0-9a-fA-F]*$ is not valid regular expression.", lengthConstraint.getErrorMessage());
- assertEquals("invalid-regular-expression", lengthConstraint.getErrorAppTag());
- assertNotNull(lengthConstraint.toString());
- assertNotNull(lengthConstraint.hashCode());
- assertFalse(lengthConstraint.equals(null));
- assertFalse(lengthConstraint.equals("test"));
- assertFalse(lengthConstraint.equals(lengthConstraintSecond));
- assertTrue(lengthConstraint.equals(lengthConstraintThird));
+ 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());
+ assertNotNull(patternConstraint.toString());
+ assertNotNull(patternConstraint.hashCode());
+ assertFalse(patternConstraint.equals(null));
+ assertFalse(patternConstraint.equals("test"));
+ assertFalse(patternConstraint.equals(patternConstraintSecond));
+ assertTrue(patternConstraint.equals(patternConstraintThird));
}
@Test