Fixed incorrect path construction in JUnit tests.
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / impl / TypesResolutionTest.java
index 70e7ea229fd226523dc8fcdad9259ad60915de06..224d91aae791d8808f82b695211a942b66765be0 100644 (file)
@@ -9,7 +9,7 @@ package org.opendaylight.yangtools.yang.parser.impl;
 
 import static org.junit.Assert.*;
 
-import java.io.FileNotFoundException;
+import java.io.File;
 import java.net.URI;
 import java.util.List;
 import java.util.Set;
@@ -27,6 +27,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.util.BitsType;
 import org.opendaylight.yangtools.yang.model.util.EnumerationType;
 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
@@ -38,8 +39,12 @@ public class TypesResolutionTest {
     private Set<Module> testedModules;
 
     @Before
-    public void init() throws FileNotFoundException {
-        testedModules = TestUtils.loadModules(getClass().getResource("/types").getPath());
+    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());
+        YangModelParser parser = new YangParserImpl();
+        testedModules = parser.parseYangModels(yangFile, dependenciesDir);
+        assertEquals(4, testedModules.size());
     }
 
     @Test
@@ -155,6 +160,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
@@ -169,16 +175,31 @@ public class TypesResolutionTest {
     public void testIdentity() {
         Module tested = TestUtils.findModule(testedModules, "custom-types-test");
         Set<IdentitySchemaNode> identities = tested.getIdentities();
-        IdentitySchemaNode testedIdentity = null;
+        assertEquals(5, identities.size());
+        IdentitySchemaNode cryptoAlg = null;
+        IdentitySchemaNode cryptoBase = null;
+        IdentitySchemaNode cryptoId = null;
         for (IdentitySchemaNode id : identities) {
             if (id.getQName().getLocalName().equals("crypto-alg")) {
-                testedIdentity = id;
-                IdentitySchemaNode baseIdentity = id.getBaseIdentity();
-                assertEquals("crypto-base", baseIdentity.getQName().getLocalName());
-                assertNull(baseIdentity.getBaseIdentity());
+                cryptoAlg = id;
+            } else if ("crypto-base".equals(id.getQName().getLocalName())) {
+                cryptoBase = id;
+            } else if ("crypto-id".equals(id.getQName().getLocalName())) {
+                cryptoId = id;
             }
         }
-        assertNotNull(testedIdentity);
+        assertNotNull(cryptoAlg);
+        IdentitySchemaNode baseIdentity = cryptoAlg.getBaseIdentity();
+        assertEquals("crypto-base", baseIdentity.getQName().getLocalName());
+        assertTrue(cryptoAlg.getDerivedIdentities().isEmpty());
+        assertNull(baseIdentity.getBaseIdentity());
+
+        assertNotNull(cryptoBase);
+        assertNull(cryptoBase.getBaseIdentity());
+        assertEquals(3, cryptoBase.getDerivedIdentities().size());
+
+        assertNotNull(cryptoId);
+        assertEquals(1, cryptoId.getUnknownSchemaNodes().size());
     }
 
     @Test
@@ -298,7 +319,7 @@ public class TypesResolutionTest {
         Set<TypeDefinition<?>> typedefs = tested.getTypeDefinitions();
         TypeDefinition<?> testedType = TestUtils.findTypedef(typedefs, "service-type-ref");
         IdentityrefType baseType = (IdentityrefType) testedType.getBaseType();
-        QName identity = baseType.getIdentity();
+        QName identity = baseType.getIdentity().getQName();
         assertEquals(URI.create("urn:custom.types.demo"), identity.getNamespace());
         assertEquals(TestUtils.createDate("2012-04-16"), identity.getRevision());
         assertEquals("iit", identity.getPrefix());