Bug 4640: Change semantic-version to openconfig-version
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / EffectiveStatementTypeTest.java
index c6b76d0a8bbc4826951a270890c1f5adba3f6ca5..669e7d3d6bc04d4a47b8cdf1aa2a63e57b39e543 100644 (file)
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertFalse;
 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;
@@ -23,10 +24,12 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 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;
@@ -34,15 +37,13 @@ import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
 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;
@@ -51,8 +52,7 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionS
 
 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;
@@ -92,8 +92,8 @@ public class EffectiveStatementTypeTest {
         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();
@@ -127,8 +127,7 @@ public class EffectiveStatementTypeTest {
         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
@@ -163,7 +162,7 @@ public class EffectiveStatementTypeTest {
         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());
@@ -203,7 +202,7 @@ public class EffectiveStatementTypeTest {
         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();
@@ -229,7 +228,7 @@ public class EffectiveStatementTypeTest {
         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
@@ -414,27 +413,27 @@ public class EffectiveStatementTypeTest {
         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