Propagate EffectiveModelContext to more places
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / leafref / context / LeafRefContextTest.java
index b76940c5ae5c0c99c0b8a1d7a5295e2e054f1570..e9c650fb05f9b22caed7b999f1cf56f1ca04352a 100644 (file)
@@ -12,22 +12,20 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
 
 import java.util.Map;
-import java.util.Set;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContext;
 import org.opendaylight.yangtools.yang.data.impl.leafref.LeafRefContextUtils;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class LeafRefContextTest {
-
-    private static SchemaContext context;
+    private static EffectiveModelContext context;
     private static Module rootMod;
     private static QNameModule root;
     private static LeafRefContext rootLeafRefContext;
@@ -36,8 +34,7 @@ public class LeafRefContextTest {
     public static void init() {
         context = YangParserTestUtils.parseYangResourceDirectory("/leafref-context-test/correct-modules");
 
-        final Set<Module> modules = context.getModules();
-        for (final Module module : modules) {
+        for (final Module module : context.getModules()) {
             if (module.getName().equals("leafref-test2")) {
                 rootMod = module;
             }
@@ -47,6 +44,14 @@ public class LeafRefContextTest {
         rootLeafRefContext = LeafRefContext.create(context);
     }
 
+    @AfterClass
+    public static void cleanup() {
+        context = null;
+        root = null;
+        rootMod = null;
+        rootLeafRefContext = null;
+    }
+
     @Test
     public void test() {
 
@@ -57,12 +62,11 @@ public class LeafRefContextTest {
         final QName q5 = QName.create(root, "list1");
         final QName q6 = QName.create(root, "name");
 
-        final DataSchemaNode leafRefNode = rootMod.getDataChildByName(q1);
-        final DataSchemaNode targetNode = rootMod.getDataChildByName(q2);
-        final DataSchemaNode cont1Node = rootMod.getDataChildByName(q3);
-        final DataSchemaNode cont2Node = rootMod.getDataChildByName(q4);
-        final DataSchemaNode name1Node = ((DataNodeContainer) ((DataNodeContainer) rootMod.getDataChildByName(q3))
-                .getDataChildByName(q5)).getDataChildByName(q6);
+        final DataSchemaNode leafRefNode = rootMod.findDataChildByName(q1).get();
+        final DataSchemaNode targetNode = rootMod.findDataChildByName(q2).get();
+        final DataSchemaNode cont1Node = rootMod.findDataChildByName(q3).get();
+        final DataSchemaNode cont2Node = rootMod.findDataChildByName(q4).get();
+        final DataSchemaNode name1Node = rootMod.findDataChildByName(q3, q5, q6).get();
 
         assertTrue(LeafRefContextUtils.isLeafRef(leafRefNode, rootLeafRefContext));
         assertFalse(LeafRefContextUtils.isLeafRef(targetNode, rootLeafRefContext));