BUG-576: fixed bug in parsing of union types.
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / TypesResolutionTest.java
index 9a88a8671351af30686d9e9e34c49c305667b037..022cda45a59eae835f5989e2597f6e492bcbc2ad 100644 (file)
@@ -7,14 +7,18 @@
  */
 package org.opendaylight.yangtools.yang.parser.impl;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+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 java.io.File;
-import java.io.FileNotFoundException;
+import java.math.BigInteger;
 import java.net.URI;
+import java.util.Arrays;
 import java.util.List;
 import java.util.Set;
-
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -28,7 +32,7 @@ import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPai
 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.parser.api.YangModelParser;
+import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
 import org.opendaylight.yangtools.yang.model.util.BitsType;
 import org.opendaylight.yangtools.yang.model.util.EnumerationType;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
@@ -40,11 +44,11 @@ public class TypesResolutionTest {
     private Set<Module> testedModules;
 
     @Before
-    public void init() throws FileNotFoundException {
-        File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath());
-        File dependenciesDir = new File(getClass().getResource("/ietf").getPath());
-        YangModelParser parser = new YangParserImpl();
-        testedModules = parser.parseYangModels(yangFile, dependenciesDir);
+    public void init() throws Exception {
+        File yangFile = new File(getClass().getResource("/types/custom-types-test@2012-4-4.yang").toURI());
+        File dependenciesDir = new File(getClass().getResource("/ietf").toURI());
+        YangContextParser parser = new YangParserImpl();
+        testedModules = parser.parseFile(yangFile, dependenciesDir).getModules();
         assertEquals(4, testedModules.size());
     }
 
@@ -151,8 +155,8 @@ public class TypesResolutionTest {
         List<LengthConstraint> lengths = type.getLengthConstraints();
         assertEquals(1, lengths.size());
         LengthConstraint length = type.getLengthConstraints().get(0);
-        assertEquals(1L, length.getMin());
-        assertEquals(253L, length.getMax());
+        assertEquals(BigInteger.ONE, length.getMin());
+        assertEquals(BigInteger.valueOf(253), length.getMax());
     }
 
     @Test
@@ -161,6 +165,7 @@ public class TypesResolutionTest {
         LeafSchemaNode leaf = (LeafSchemaNode) tested.getDataChildByName("inst-id-leaf1");
         InstanceIdentifier leafType = (InstanceIdentifier) leaf.getType();
         assertFalse(leafType.requireInstance());
+        assertEquals(1, leaf.getUnknownSchemaNodes().size());
     }
 
     @Test
@@ -178,11 +183,14 @@ public class TypesResolutionTest {
         assertEquals(5, identities.size());
         IdentitySchemaNode cryptoAlg = null;
         IdentitySchemaNode cryptoBase = null;
+        IdentitySchemaNode cryptoId = null;
         for (IdentitySchemaNode id : identities) {
             if (id.getQName().getLocalName().equals("crypto-alg")) {
                 cryptoAlg = id;
             } else if ("crypto-base".equals(id.getQName().getLocalName())) {
                 cryptoBase = id;
+            } else if ("crypto-id".equals(id.getQName().getLocalName())) {
+                cryptoId = id;
             }
         }
         assertNotNull(cryptoAlg);
@@ -194,6 +202,9 @@ public class TypesResolutionTest {
         assertNotNull(cryptoBase);
         assertNull(cryptoBase.getBaseIdentity());
         assertEquals(3, cryptoBase.getDerivedIdentities().size());
+
+        assertNotNull(cryptoId);
+        assertEquals(1, cryptoId.getUnknownSchemaNodes().size());
     }
 
     @Test
@@ -323,4 +334,13 @@ public class TypesResolutionTest {
         assertNotNull(type);
     }
 
+    @Test
+    public void testUnionWithExt() throws Exception {
+        File extdef = new File(getClass().getResource("/types/union-with-ext/extdef.yang").toURI());
+        File unionbug = new File(getClass().getResource("/types/union-with-ext/unionbug.yang").toURI());
+        File inet = new File(getClass().getResource("/ietf/ietf-inet-types@2010-09-24.yang").toURI());
+        YangContextParser parser = new YangParserImpl();
+        parser.parseFiles(Arrays.asList(extdef, unionbug, inet));
+    }
+
 }