Rename ChoiceCaseNode to CaseSchemaNode
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / NormalizedDataBuilderTest.java
index 1409433cad199b2cb8ee4bb62e4ef59ad660058d..dc7f12f1315aaeb48d4310a0bc130ebe17648a20 100644 (file)
@@ -13,9 +13,7 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
 import java.util.Collections;
-import java.util.List;
 import org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
@@ -33,7 +31,8 @@ import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableChoiceNodeSchemaAwareBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeSchemaAwareBuilder;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
@@ -138,7 +137,7 @@ public class NormalizedDataBuilderTest {
         builder.withChild(list);
 
         LeafSchemaNode augmentUint32SchemaNode = (LeafSchemaNode) getSchemaNode(schema, "test", "augmentUint32");
-        AugmentationSchema augmentationSchema = getAugmentationSchemaForChild(containerNode,
+        AugmentationSchemaNode augmentationSchema = getAugmentationSchemaForChild(containerNode,
                 augmentUint32SchemaNode.getQName());
 
         AugmentationNode augmentation = Builders.augmentationBuilder(augmentationSchema)
@@ -168,9 +167,9 @@ public class NormalizedDataBuilderTest {
         // .build());
     }
 
-    private static AugmentationSchema getAugmentationSchemaForChild(final ContainerSchemaNode containerNode,
+    private static AugmentationSchemaNode getAugmentationSchemaForChild(final ContainerSchemaNode containerNode,
             final QName qname) {
-        for (AugmentationSchema augmentationSchema : containerNode.getAvailableAugmentations()) {
+        for (AugmentationSchemaNode augmentationSchema : containerNode.getAvailableAugmentations()) {
             if (augmentationSchema.getDataChildByName(qname) != null) {
                 return augmentationSchema;
             }
@@ -183,8 +182,7 @@ public class NormalizedDataBuilderTest {
     }
 
     private static QName getQName(final String localName) {
-        String namespace = "namespace";
-        return new QName(URI.create(namespace), localName);
+        return QName.create(URI.create("namespace"), localName);
     }
 
     private static NodeIdentifier getNodeIdentifier(final String localName) {
@@ -195,7 +193,7 @@ public class NormalizedDataBuilderTest {
             final String childNodeName) {
         for (Module module : context.getModules()) {
             if (module.getName().equals(moduleName)) {
-                DataSchemaNode found = findChildNode(module.getChildNodes(), childNodeName);
+                DataSchemaNode found = findChildNode(module, childNodeName);
                 checkState(found != null, "Unable to find %s", childNodeName);
                 return found;
             }
@@ -203,27 +201,25 @@ public class NormalizedDataBuilderTest {
         throw new IllegalStateException("Unable to find child node " + childNodeName);
     }
 
-    private static DataSchemaNode findChildNode(final Iterable<DataSchemaNode> children, final String name) {
-        List<DataNodeContainer> containers = new ArrayList<>();
-
-        for (DataSchemaNode dataSchemaNode : children) {
+    private static DataSchemaNode findChildNode(final DataNodeContainer container, final String name) {
+        for (DataSchemaNode dataSchemaNode : container.getChildNodes()) {
             if (dataSchemaNode.getQName().getLocalName().equals(name)) {
                 return dataSchemaNode;
             }
             if (dataSchemaNode instanceof DataNodeContainer) {
-                containers.add((DataNodeContainer) dataSchemaNode);
+                DataSchemaNode retVal = findChildNode((DataNodeContainer) dataSchemaNode, name);
+                if (retVal != null) {
+                    return retVal;
+                }
             } else if (dataSchemaNode instanceof ChoiceSchemaNode) {
-                containers.addAll(((ChoiceSchemaNode) dataSchemaNode).getCases());
+                for (CaseSchemaNode caseNode : ((ChoiceSchemaNode) dataSchemaNode).getCases().values()) {
+                    DataSchemaNode retVal = findChildNode(caseNode, name);
+                    if (retVal != null) {
+                        return retVal;
+                    }
+                }
             }
         }
-
-        for (DataNodeContainer container : containers) {
-            DataSchemaNode retVal = findChildNode(container.getChildNodes(), name);
-            if (retVal != null) {
-                return retVal;
-            }
-        }
-
         return null;
     }
 }