BUG-4688: Make SourceIdentifier use Revision
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / TypesResolutionTest.java
index 24bc9a2ba5f22edd3b9e8f85b911041e5e617576..fbec329bd5e51f4f2c5800ac5a98a9adc6ca6239 100644 (file)
@@ -15,12 +15,16 @@ import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
 
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Range;
 import java.net.URI;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.Revision;
 import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
@@ -49,7 +53,7 @@ public class TypesResolutionTest {
 
     @Before
     public void init() throws Exception {
-        final StatementStreamSource yangFile = sourceForResource("/types/custom-types-test@2012-4-4.yang");
+        final StatementStreamSource yangFile = sourceForResource("/types/custom-types-test@2012-04-04.yang");
         final StatementStreamSource yangFileDependency1 = sourceForResource("/ietf/iana-timezones@2012-07-09.yang");
         final StatementStreamSource yangFileDependency2 = sourceForResource("/ietf/ietf-inet-types@2010-09-24.yang");
         final StatementStreamSource yangFileDependency3 = sourceForResource("/ietf/ietf-yang-types@2010-09-24.yang");
@@ -157,11 +161,11 @@ public class TypesResolutionTest {
                 + "([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)" + "|\\.$";
         assertEquals(expectedPattern, patterns.get(0).getRegularExpression());
 
-        List<LengthConstraint> lengths = type.getLengthConstraints();
-        assertEquals(1, lengths.size());
-        LengthConstraint length = type.getLengthConstraints().get(0);
-        assertEquals(Integer.valueOf(1), length.getMin());
-        assertEquals(Integer.valueOf(253), length.getMax());
+        LengthConstraint lengths = type.getLengthConstraint().get();
+        assertEquals(1, lengths.getAllowedRanges().asRanges().size());
+        Range<Integer> length = lengths.getAllowedRanges().span();
+        assertEquals(Integer.valueOf(1), length.lowerEndpoint());
+        assertEquals(Integer.valueOf(253), length.upperEndpoint());
     }
 
     @Test
@@ -201,13 +205,13 @@ public class TypesResolutionTest {
             }
         }
         assertNotNull(cryptoAlg);
-        IdentitySchemaNode baseIdentity = cryptoAlg.getBaseIdentity();
+        IdentitySchemaNode baseIdentity = Iterables.getOnlyElement(cryptoAlg.getBaseIdentities());
         assertEquals("crypto-base", baseIdentity.getQName().getLocalName());
         assertTrue(cryptoAlg.getDerivedIdentities().isEmpty());
-        assertNull(baseIdentity.getBaseIdentity());
+        assertTrue(baseIdentity.getBaseIdentities().isEmpty());
 
         assertNotNull(cryptoBase);
-        assertNull(cryptoBase.getBaseIdentity());
+        assertTrue(cryptoBase.getBaseIdentities().isEmpty());
         assertEquals(3, cryptoBase.getDerivedIdentities().size());
 
         assertNotNull(cryptoId);
@@ -280,7 +284,7 @@ public class TypesResolutionTest {
 
         QName testedTypeQName = testedType.getQName();
         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:iana-timezones"), testedTypeQName.getNamespace());
-        assertEquals(TestUtils.createDate("2012-07-09"), testedTypeQName.getRevision());
+        assertEquals(Optional.of(Revision.valueOf("2012-07-09")), testedTypeQName.getRevision());
         assertEquals("iana-timezone", testedTypeQName.getLocalName());
 
         EnumTypeDefinition enumType = (EnumTypeDefinition) testedType.getBaseType();
@@ -312,7 +316,7 @@ public class TypesResolutionTest {
 
         QName testedTypeQName = testedType.getQName();
         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeQName.getNamespace());
-        assertEquals(TestUtils.createDate("2010-09-24"), testedTypeQName.getRevision());
+        assertEquals(Optional.of(Revision.valueOf("2010-09-24")), testedTypeQName.getRevision());
         assertEquals("object-identifier-128", testedTypeQName.getLocalName());
 
         StringTypeDefinition testedTypeBase = testedType.getBaseType();
@@ -325,7 +329,7 @@ public class TypesResolutionTest {
 
         QName testedTypeBaseQName = testedTypeBase.getQName();
         assertEquals(URI.create("urn:ietf:params:xml:ns:yang:ietf-yang-types"), testedTypeBaseQName.getNamespace());
-        assertEquals(TestUtils.createDate("2010-09-24"), testedTypeBaseQName.getRevision());
+        assertEquals(Optional.of(Revision.valueOf("2010-09-24")), testedTypeBaseQName.getRevision());
         assertEquals("object-identifier", testedTypeBaseQName.getLocalName());
     }
 
@@ -337,7 +341,7 @@ public class TypesResolutionTest {
         IdentityrefTypeDefinition baseType = (IdentityrefTypeDefinition) testedType.getBaseType();
         QName identity = baseType.getIdentity().getQName();
         assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace());
-        assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision());
+        assertEquals(Optional.of(Revision.valueOf("2012-04-16")), identity.getRevision());
         assertEquals("service-type", identity.getLocalName());
 
         LeafSchemaNode type = (LeafSchemaNode) tested.getDataChildByName(QName.create(tested.getQNameModule(), "type"));