Merge "Added more tests for yang parser. Updated current tests."
authorAlessandro Boch <aboch@cisco.com>
Tue, 9 Jul 2013 14:53:42 +0000 (14:53 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 9 Jul 2013 14:53:42 +0000 (14:53 +0000)
23 files changed:
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/AbstractDataNodeContainerBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/api/DataNodeContainerBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/AugmentationSchemaBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/DeviationBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/GroupingBuilderImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/builder/impl/ModuleBuilder.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/impl/YangParserListenerImpl.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/ParserListenerUtils.java [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/YangModelBuilderUtil.java with 98% similarity]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/parser/util/TypeConstraints.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/main/java/org/opendaylight/controller/yang/validator/ValidationUtil.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/AugmentTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/GroupingTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/YangParserWithContextTest.java
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/context-test/deviation-test.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/context-test/test2.yang
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/custom.yang [moved from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile3.yang with 63% similarity]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/nodes.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang [deleted file]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang [deleted file]
opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/types.yang [new file with mode: 0644]
opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/ExtendedType.java

index 6e804a199d3a829646cfa951120910543128d9c5..116f82e8d8ce6d51ef7011d94518675b361f61ee 100644 (file)
@@ -64,6 +64,16 @@ public abstract class AbstractDataNodeContainerBuilder implements DataNodeContai
         return addedChildNodes;
     }
 
+    @Override
+    public DataSchemaNodeBuilder getDataChildByName(final String name) {
+        for(DataSchemaNodeBuilder child : addedChildNodes) {
+            if(child.getQName().getLocalName().equals(name)) {
+                return child;
+            }
+        }
+        return null;
+    }
+
     @Override
     public void addChildNode(DataSchemaNodeBuilder childNode) {
         addedChildNodes.add(childNode);
index 13b7e4874e533b0290b09592950b86a3d19e4c59..4271776d63f4bca6dd11d5f1cff262abdfeebb55 100644 (file)
@@ -28,6 +28,8 @@ public interface DataNodeContainerBuilder extends Builder {
 
     Set<DataSchemaNodeBuilder> getChildNodeBuilders();
 
+    DataSchemaNodeBuilder getDataChildByName(String name);
+
     void addChildNode(DataSchemaNodeBuilder childNode);
 
     Set<GroupingDefinition> getGroupings();
index b534ba4f6013bb91056e30e1294486ec5b3e5086..d3082e882407714b631f8f3edbd1e110d2afe154 100644 (file)
@@ -34,7 +34,7 @@ import org.opendaylight.controller.yang.parser.builder.api.GroupingBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.TypeDefinitionBuilder;
 import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.controller.yang.parser.util.Comparators;
-import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
+import org.opendaylight.controller.yang.parser.util.ParserListenerUtils;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
 public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBuilder {
@@ -61,7 +61,7 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
     AugmentationSchemaBuilderImpl(final int line, final String augmentTargetStr) {
         this.augmentTargetStr = augmentTargetStr;
         this.line = line;
-        final SchemaPath targetPath = YangModelBuilderUtil.parseAugmentPath(augmentTargetStr);
+        final SchemaPath targetPath = ParserListenerUtils.parseAugmentPath(augmentTargetStr);
         dirtyAugmentTarget = targetPath;
         instance = new AugmentationSchemaImpl(targetPath);
     }
@@ -91,6 +91,16 @@ public final class AugmentationSchemaBuilderImpl implements AugmentationSchemaBu
         return Collections.emptySet();
     }
 
+    @Override
+    public DataSchemaNodeBuilder getDataChildByName(final String name) {
+        for(DataSchemaNodeBuilder child : childNodes) {
+            if(child.getQName().getLocalName().equals(name)) {
+                return child;
+            }
+        }
+        return null;
+    }
+
     @Override
     public Set<DataSchemaNodeBuilder> getChildNodeBuilders() {
         return childNodes;
index 9b52d61c88085e822a780f569e97be05003f1ed9..aee5587a365ffbb2b34ecf5428c7457ead0c8ee1 100644 (file)
@@ -17,31 +17,48 @@ import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
 import org.opendaylight.controller.yang.parser.builder.api.Builder;
 import org.opendaylight.controller.yang.parser.util.Comparators;
-import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
+import org.opendaylight.controller.yang.parser.util.ParserListenerUtils;
 import org.opendaylight.controller.yang.parser.util.YangParseException;
 
 public final class DeviationBuilder implements Builder {
     private final int line;
     private Builder parent;
+    private boolean isBuilt;
     private final DeviationImpl instance;
+
+    private SchemaPath targetPath;
+    private String reference;
     private final List<UnknownSchemaNodeBuilder> addedUnknownNodes = new ArrayList<UnknownSchemaNodeBuilder>();
 
-    DeviationBuilder(final String targetPathStr, final int line) {
+    DeviationBuilder(final int line, final String targetPathStr) {
+        if(!targetPathStr.startsWith("/")) {
+            throw new YangParseException(line, "Deviation argument string must be an absolute schema node identifier.");
+        }
         this.line = line;
-        final SchemaPath targetPath = YangModelBuilderUtil
-                .parseAugmentPath(targetPathStr);
-        instance = new DeviationImpl(targetPath);
+        this.targetPath = ParserListenerUtils.parseAugmentPath(targetPathStr);
+        instance = new DeviationImpl();
     }
 
     @Override
     public Deviation build() {
-        // UNKNOWN NODES
-        List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
-        for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
-            unknownNodes.add(b.build());
+        if(targetPath == null) {
+            throw new YangParseException(line, "Unresolved deviation target");
+        }
+
+        if(!isBuilt) {
+            instance.setTargetPath(targetPath);
+            instance.setReference(reference);
+
+            // UNKNOWN NODES
+            List<UnknownSchemaNode> unknownNodes = new ArrayList<UnknownSchemaNode>();
+            for (UnknownSchemaNodeBuilder b : addedUnknownNodes) {
+                unknownNodes.add(b.build());
+            }
+            Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
+            instance.setUnknownSchemaNodes(unknownNodes);
+
+            isBuilt = true;
         }
-        Collections.sort(unknownNodes, Comparators.SCHEMA_NODE_COMP);
-        instance.setUnknownSchemaNodes(unknownNodes);
 
         return instance;
     }
@@ -66,6 +83,14 @@ public final class DeviationBuilder implements Builder {
         addedUnknownNodes.add(unknownNode);
     }
 
+    public SchemaPath getTargetPath() {
+        return targetPath;
+    }
+
+    public void setTargetPath(final SchemaPath targetPath) {
+        this.targetPath = targetPath;
+    }
+
     public void setDeviate(final String deviate) {
         if ("not-supported".equals(deviate)) {
             instance.setDeviate(Deviate.NOT_SUPPORTED);
@@ -82,17 +107,16 @@ public final class DeviationBuilder implements Builder {
     }
 
     public void setReference(final String reference) {
-        instance.setReference(reference);
+        this.reference = reference;
     }
 
     private final class DeviationImpl implements Deviation {
-        private final SchemaPath targetPath;
+        private SchemaPath targetPath;
         private Deviate deviate;
         private String reference;
         private List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
 
-        private DeviationImpl(final SchemaPath targetPath) {
-            this.targetPath = targetPath;
+        private DeviationImpl() {
         }
 
         @Override
@@ -100,6 +124,10 @@ public final class DeviationBuilder implements Builder {
             return targetPath;
         }
 
+        private void setTargetPath(final SchemaPath targetPath) {
+            this.targetPath = targetPath;
+        }
+
         @Override
         public Deviate getDeviate() {
             return deviate;
index 0f7179e791eeb761cf1b7528e94a96728eff348c..0099b4f54b0d8b44a882d496039f04436190b424 100644 (file)
@@ -258,6 +258,16 @@ public final class GroupingBuilderImpl implements GroupingBuilder {
         return addedChildNodes;
     }
 
+    @Override
+    public DataSchemaNodeBuilder getDataChildByName(final String name) {
+        for(DataSchemaNodeBuilder child : addedChildNodes) {
+            if(child.getQName().getLocalName().equals(name)) {
+                return child;
+            }
+        }
+        return null;
+    }
+
     public void setChildNodes(final Set<DataSchemaNode> childNodes) {
         this.childNodes = childNodes;
     }
index 57e87b33ad855bb345bcd0cf5d1459ac8304ca62..484461e4e35f6c1cb08db849f876b3530dc8385e 100644 (file)
@@ -81,7 +81,7 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
     private final Set<NotificationBuilder> addedNotifications = new HashSet<NotificationBuilder>();
     private final Set<IdentitySchemaNodeBuilder> addedIdentities = new HashSet<IdentitySchemaNodeBuilder>();
     private final Set<FeatureBuilder> addedFeatures = new HashSet<FeatureBuilder>();
-    private final Map<List<String>, DeviationBuilder> addedDeviations = new HashMap<List<String>, DeviationBuilder>();
+    private final Set<DeviationBuilder> addedDeviations = new HashSet<DeviationBuilder>();
     private final Set<TypeDefinitionBuilder> addedTypedefs = new HashSet<TypeDefinitionBuilder>();
     private final Map<List<String>, UnionTypeBuilder> addedUnionTypes = new HashMap<List<String>, UnionTypeBuilder>();
     private final List<ExtensionBuilder> addedExtensions = new ArrayList<ExtensionBuilder>();
@@ -165,8 +165,8 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
 
         // DEVIATIONS
         final Set<Deviation> deviations = new HashSet<Deviation>();
-        for (Map.Entry<List<String>, DeviationBuilder> entry : addedDeviations.entrySet()) {
-            deviations.add(entry.getValue().build());
+        for (DeviationBuilder entry : addedDeviations) {
+            deviations.add(entry.build());
         }
         instance.setDeviations(deviations);
 
@@ -265,6 +265,16 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         return childNodes;
     }
 
+    @Override
+    public DataSchemaNodeBuilder getDataChildByName(final String name) {
+        for(DataSchemaNodeBuilder child : childNodes) {
+            if(child.getQName().getLocalName().equals(name)) {
+                return child;
+            }
+        }
+        return null;
+    }
+
     public Map<List<String>, TypeAwareBuilder> getDirtyNodes() {
         return dirtyNodes;
     }
@@ -281,6 +291,10 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         return allUsesNodes;
     }
 
+    public Set<DeviationBuilder> getDeviations() {
+        return addedDeviations;
+    }
+
     public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
         List<UnknownSchemaNodeBuilder> result = new ArrayList<UnknownSchemaNodeBuilder>();
         for (List<UnknownSchemaNodeBuilder> entry : addedUnknownNodes.values()) {
@@ -754,16 +768,14 @@ public class ModuleBuilder implements DataNodeContainerBuilder {
         }
     }
 
-    public DeviationBuilder addDeviation(final String targetPath, final List<String> parentPath, final int line) {
+    public DeviationBuilder addDeviation(final int line, final String targetPath) {
         Builder parent = getActualNode();
         if (parent != null) {
             throw new YangParseException(name, line, "deviation can be defined only in module or submodule");
         }
 
-        final List<String> pathToDeviation = new ArrayList<String>(parentPath);
-        pathToDeviation.add(targetPath);
-        final DeviationBuilder builder = new DeviationBuilder(targetPath, line);
-        addedDeviations.put(pathToDeviation, builder);
+        final DeviationBuilder builder = new DeviationBuilder(line, targetPath);
+        addedDeviations.add(builder);
         return builder;
     }
 
index 6adc29b2271ce956fed15035084b1a3f9f7f77b0..712c84fad15e58bc9b0f1d06bcfc4158add6396c 100644 (file)
@@ -39,6 +39,7 @@ import org.opendaylight.controller.yang.common.QName;
 import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.controller.yang.model.api.ChoiceNode;
 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataNodeContainer;
 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
 import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
@@ -47,6 +48,7 @@ import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
 import org.opendaylight.controller.yang.model.api.Module;
 import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.api.SchemaNode;
 import org.opendaylight.controller.yang.model.api.SchemaPath;
 import org.opendaylight.controller.yang.model.api.TypeDefinition;
 import org.opendaylight.controller.yang.model.api.UnknownSchemaNode;
@@ -68,6 +70,7 @@ import org.opendaylight.controller.yang.parser.builder.api.UsesNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.AnyXmlBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ChoiceBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
+import org.opendaylight.controller.yang.parser.builder.impl.DeviationBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.GroupingBuilderImpl;
 import org.opendaylight.controller.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
 import org.opendaylight.controller.yang.parser.builder.impl.IdentityrefTypeBuilder;
@@ -305,6 +308,7 @@ public final class YangParserImpl implements YangModelParser {
             }
         }
         resolveAugments(modules);
+        resolveDeviations(modules);
 
         // build
         // LinkedHashMap MUST be used otherwise the values will not maintain
@@ -333,6 +337,7 @@ public final class YangParserImpl implements YangModelParser {
             }
         }
         resolveAugmentsWithContext(modules, context);
+        resolveDeviationsWithContext(modules, context);
 
         // build
         // LinkedHashMap MUST be used otherwise the values will not maintain
@@ -1218,7 +1223,7 @@ public final class YangParserImpl implements YangModelParser {
     }
 
     private void resolveUnknownNodesWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
-            final ModuleBuilder module, SchemaContext context) {
+            final ModuleBuilder module, final SchemaContext context) {
         for (UnknownSchemaNodeBuilder unknownNodeBuilder : module.getUnknownNodes()) {
             QName nodeType = unknownNodeBuilder.getNodeType();
             if (nodeType.getNamespace() == null || nodeType.getRevision() == null) {
@@ -1246,4 +1251,115 @@ public final class YangParserImpl implements YangModelParser {
         }
     }
 
+    private void resolveDeviations(final Map<String, TreeMap<Date, ModuleBuilder>> modules) {
+        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+            for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+                ModuleBuilder b = inner.getValue();
+                resolveDeviation(modules, b);
+            }
+        }
+    }
+
+    private void resolveDeviation(final Map<String, TreeMap<Date, ModuleBuilder>> modules, final ModuleBuilder module) {
+        for (DeviationBuilder dev : module.getDeviations()) {
+            int line = dev.getLine();
+            SchemaPath targetPath = dev.getTargetPath();
+            List<QName> path = targetPath.getPath();
+            QName q0 = path.get(0);
+            String prefix = q0.getPrefix();
+            if (prefix == null) {
+                prefix = module.getPrefix();
+            }
+
+            ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module, prefix, line);
+            processDeviation(dev, dependentModuleBuilder, path, module);
+        }
+    }
+
+    private void resolveDeviationsWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            final SchemaContext context) {
+        for (Map.Entry<String, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+            for (Map.Entry<Date, ModuleBuilder> inner : entry.getValue().entrySet()) {
+                ModuleBuilder b = inner.getValue();
+                resolveDeviationWithContext(modules, b, context);
+            }
+        }
+    }
+
+    private void resolveDeviationWithContext(final Map<String, TreeMap<Date, ModuleBuilder>> modules,
+            final ModuleBuilder module, final SchemaContext context) {
+        for (DeviationBuilder dev : module.getDeviations()) {
+            int line = dev.getLine();
+            SchemaPath targetPath = dev.getTargetPath();
+            List<QName> path = targetPath.getPath();
+            QName q0 = path.get(0);
+            String prefix = q0.getPrefix();
+            if (prefix == null) {
+                prefix = module.getPrefix();
+            }
+            String name = null;
+
+            ModuleBuilder dependentModuleBuilder = findDependentModuleBuilder(modules, module, prefix, line);
+            if (dependentModuleBuilder == null) {
+                Module dependentModule = findModuleFromContext(context, module, prefix, line);
+                Object currentParent = dependentModule;
+
+                for (int i = 0; i < path.size(); i++) {
+                    if (currentParent == null) {
+                        throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+                    }
+                    QName q = path.get(i);
+                    name = q.getLocalName();
+                    if (currentParent instanceof DataNodeContainer) {
+                        currentParent = ((DataNodeContainer) currentParent).getDataChildByName(name);
+                    }
+                }
+
+                if (currentParent == null) {
+                    throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+                }
+                if (currentParent instanceof SchemaNode) {
+                    dev.setTargetPath(((SchemaNode) currentParent).getPath());
+                }
+
+            } else {
+                processDeviation(dev, dependentModuleBuilder, path, module);
+            }
+        }
+    }
+
+    /**
+     * Correct deviation target path in deviation builder.
+     *
+     * @param dev
+     *            deviation
+     * @param dependentModuleBuilder
+     *            module containing deviation target
+     * @param path
+     *            current deviation target path
+     * @param module
+     *            current module
+     */
+    private void processDeviation(final DeviationBuilder dev, final ModuleBuilder dependentModuleBuilder,
+            final List<QName> path, final ModuleBuilder module) {
+        final int line = dev.getLine();
+        Builder currentParent = dependentModuleBuilder;
+
+        for (int i = 0; i < path.size(); i++) {
+            if (currentParent == null) {
+                throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+            }
+            QName q = path.get(i);
+            String name = q.getLocalName();
+            if (currentParent instanceof DataNodeContainerBuilder) {
+                currentParent = ((DataNodeContainerBuilder) currentParent).getDataChildByName(name);
+            }
+        }
+
+        if (currentParent == null || !(currentParent instanceof SchemaNodeBuilder)) {
+            throw new YangParseException(module.getName(), line, "Failed to find deviation target.");
+        }
+        dev.setTargetPath(((SchemaNodeBuilder) currentParent).getPath());
+    }
+
 }
index f806c94a30909c9a507c9eb3d6a3b4d948a532b5..73462b22dac918fd68c9c38536f5ff6209108ef7 100644 (file)
@@ -7,7 +7,7 @@
  */
 package org.opendaylight.controller.yang.parser.impl;
 
-import static org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil.*;
+import static org.opendaylight.controller.yang.parser.util.ParserListenerUtils.*;
 
 import java.net.URI;
 import java.text.DateFormat;
@@ -331,6 +331,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
         builder.setPath(createActualSchemaPath(actualPath, namespace, revision, yangModelPrefix));
         parseSchemaNodeArgs(ctx, builder);
         builder.setUnits(parseUnits(ctx));
+        builder.setDefaultValue(parseDefault(ctx));
     }
 
     @Override
@@ -854,7 +855,7 @@ public final class YangParserListenerImpl extends YangParserBaseListener {
 
         String reference = null;
         String deviate = null;
-        DeviationBuilder builder = moduleBuilder.addDeviation(targetPath, actualPath, line);
+        DeviationBuilder builder = moduleBuilder.addDeviation(line, targetPath);
         moduleBuilder.enterNode(builder);
         actualPath.push(targetPath);
 
@@ -118,10 +118,10 @@ import org.opendaylight.controller.yang.parser.builder.impl.UnionTypeBuilder;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public final class YangModelBuilderUtil {
-    private static final Logger logger = LoggerFactory.getLogger(YangModelBuilderUtil.class);
+public final class ParserListenerUtils {
+    private static final Logger logger = LoggerFactory.getLogger(ParserListenerUtils.class);
 
-    private YangModelBuilderUtil() {
+    private ParserListenerUtils() {
     }
 
     /**
@@ -216,6 +216,26 @@ public final class YangModelBuilderUtil {
         return units;
     }
 
+    /**
+     * Parse given tree and returns default statement as string.
+     *
+     * @param ctx
+     *            context to parse
+     * @return value of default statement as string or null if there is no
+     *         default statement
+     */
+    public static String parseDefault(final ParseTree ctx) {
+        String defaultValue = null;
+        for (int i = 0; i < ctx.getChildCount(); i++) {
+            ParseTree child = ctx.getChild(i);
+            if (child instanceof Default_stmtContext) {
+                defaultValue = stringFromNode(child);
+                break;
+            }
+        }
+        return defaultValue;
+    }
+
     /**
      * Create SchemaPath from actualPath and names.
      *
@@ -926,8 +946,8 @@ public final class YangModelBuilderUtil {
                 ChoiceCaseBuilder choiceCase = (ChoiceCaseBuilder) parent;
                 Builder choice = choiceCase.getParent();
                 Boolean parentConfig = null;
-                if(choice instanceof ChoiceBuilder) {
-                    parentConfig = ((ChoiceBuilder)choice).isConfiguration();
+                if (choice instanceof ChoiceBuilder) {
+                    parentConfig = ((ChoiceBuilder) choice).isConfiguration();
                 } else {
                     parentConfig = true;
                 }
@@ -1019,17 +1039,14 @@ public final class YangModelBuilderUtil {
                 TypeDefinition<?> baseType = unknownType.build();
                 TypeDefinition<?> result = null;
                 QName qname = new QName(namespace, revision, prefix, typeName);
-                ExtendedType.Builder typeBuilder = null;
-
                 SchemaPath schemaPath = createTypeSchemaPath(actualPath, namespace, revision, prefix, typeName, false,
                         false);
-                typeBuilder = new ExtendedType.Builder(qname, baseType, "", "", schemaPath);
 
+                ExtendedType.Builder typeBuilder = new ExtendedType.Builder(qname, baseType, null, null, schemaPath);
                 typeBuilder.ranges(rangeStatements);
                 typeBuilder.lengths(lengthStatements);
                 typeBuilder.patterns(patternStatements);
                 typeBuilder.fractionDigits(fractionDigits);
-
                 result = typeBuilder.build();
 
                 return result;
index 17307b46ee29f8aedc8a8dcc58e4113a1d9c84f2..4d2c5b582321c907860b801edeb57499a2ab9f6b 100644 (file)
@@ -24,7 +24,7 @@ public final class TypeConstraints {
     private final int line;
     private final List<List<RangeConstraint>> ranges = new ArrayList<List<RangeConstraint>>();
     private final List<List<LengthConstraint>> lengths = new ArrayList<List<LengthConstraint>>();
-    private final List<PatternConstraint> patterns = new ArrayList<PatternConstraint>();
+    private final List<List<PatternConstraint>> patterns = new ArrayList<List<PatternConstraint>>();
     private final List<Integer> fractionDigits = new ArrayList<Integer>();
 
     public TypeConstraints(final String moduleName, final int line) {
@@ -195,11 +195,14 @@ public final class TypeConstraints {
     }
 
     public List<PatternConstraint> getPatterns() {
-        return patterns;
+        if(patterns.isEmpty()) {
+            return Collections.emptyList();
+        }
+        return patterns.get(0);
     }
 
     public void addPatterns(final List<PatternConstraint> patterns) {
-        this.patterns.addAll(patterns);
+        this.patterns.add(patterns);
     }
 
     public Integer getFractionDigits() {
index d697201f217029316ba35afdb35d1d9bee39e514..cb5af9f34928ee22548d6d0a135db6d0b53209f7 100644 (file)
@@ -16,7 +16,7 @@ import java.util.Set;
 import org.antlr.v4.runtime.tree.ParseTree;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Module_stmtContext;
 import org.opendaylight.controller.antlrv4.code.gen.YangParser.Submodule_stmtContext;
-import org.opendaylight.controller.yang.parser.util.YangModelBuilderUtil;
+import org.opendaylight.controller.yang.parser.util.ParserListenerUtils;
 import org.opendaylight.controller.yang.parser.util.YangValidationException;
 
 /**
@@ -60,7 +60,7 @@ final class ValidationUtil {
     }
 
     static String getName(ParseTree child) {
-        return YangModelBuilderUtil.stringFromNode(child);
+        return ParserListenerUtils.stringFromNode(child);
     }
 
     static String f(String base, Object... args) {
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/AugmentTest.java b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/java/org/opendaylight/controller/yang/parser/impl/AugmentTest.java
new file mode 100644 (file)
index 0000000..d6f6356
--- /dev/null
@@ -0,0 +1,360 @@
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.yang.parser.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.FileNotFoundException;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.yang.common.QName;
+import org.opendaylight.controller.yang.model.api.AugmentationSchema;
+import org.opendaylight.controller.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.controller.yang.model.api.ChoiceNode;
+import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
+import org.opendaylight.controller.yang.model.api.ListSchemaNode;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaPath;
+import org.opendaylight.controller.yang.model.api.TypeDefinition;
+import org.opendaylight.controller.yang.model.util.ExtendedType;
+import org.opendaylight.controller.yang.model.util.Leafref;
+
+import com.google.common.collect.Lists;
+
+public class AugmentTest {
+
+    private final URI types1NS = URI.create("urn:simple.nodes.test");
+    private final URI types2NS = URI.create("urn:simple.types.test");
+    private final URI types3NS = URI.create("urn:custom.nodes.test");
+    private Date types1Rev;
+    private Date types2Rev;
+    private Date types3Rev;
+    private final String t1 = "n";
+    private final String t2 = "t";
+    private final String t3 = "c";
+    private QName q0;
+    private QName q1;
+    private QName q2;
+
+    private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+    private Set<Module> modules;
+
+    @Before
+    public void init() throws FileNotFoundException, ParseException {
+        types1Rev = simpleDateFormat.parse("2013-02-27");
+        types2Rev = simpleDateFormat.parse("2013-07-03");
+        types3Rev = simpleDateFormat.parse("2013-02-27");
+
+        q0 = new QName(types2NS, types2Rev, t2, "interfaces");
+        q1 = new QName(types2NS, types2Rev, t2, "ifEntry");
+        q2 = new QName(types3NS, types3Rev, t3, "augment-holder");
+
+        modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
+        assertEquals(3, modules.size());
+    }
+
+    @Test
+    public void testAugmentParsing() {
+        SchemaPath expectedPath = null;
+        QName[] qnames = null;
+
+        // testfile1
+        Module module1 = TestUtils.findModule(modules, "nodes");
+        Set<AugmentationSchema> augmentations = module1.getAugmentations();
+        assertEquals(1, augmentations.size());
+        AugmentationSchema augment = augmentations.iterator().next();
+
+        Set<DataSchemaNode> augmentChildren = augment.getChildNodes();
+        assertEquals(5, augmentChildren.size());
+        for(DataSchemaNode dsn : augmentChildren) {
+            assertTrue(dsn.isAugmenting());
+        }
+
+        LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augment.getDataChildByName("ds0ChannelNumber");
+        LeafSchemaNode interfaceId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
+        LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type");
+        ContainerSchemaNode schemas = (ContainerSchemaNode) augment.getDataChildByName("schemas");
+        ChoiceNode odl = (ChoiceNode)augment.getDataChildByName("odl");
+
+        assertNotNull(ds0ChannelNumber);
+        assertNotNull(interfaceId);
+        assertNotNull(myType);
+        assertNotNull(schemas);
+        assertNotNull(odl);
+
+        qnames = new QName[4];
+        qnames[0] = q0;
+        qnames[1] = q1;
+        qnames[2] = q2;
+
+        // leaf ds0ChannelNumber
+        qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, ds0ChannelNumber.getPath());
+
+        // leaf interface-id
+        qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, interfaceId.getPath());
+
+        // leaf my-type
+        qnames[3] = new QName(types1NS, types1Rev, t1, "my-type");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, myType.getPath());
+
+        // container schemas
+        qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, schemas.getPath());
+
+        // choice odl
+        qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, odl.getPath());
+
+
+        // testfile3
+        Module module3 = TestUtils.findModule(modules, "custom");
+        augmentations = module3.getAugmentations();
+        assertEquals(3, augmentations.size());
+        AugmentationSchema augment1 = null;
+        AugmentationSchema augment2 = null;
+        AugmentationSchema augment3 = null;
+        for (AugmentationSchema as : augmentations) {
+            if("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+                augment1 = as;
+            } else if("if:ifType='ds2'".equals(as.getWhenCondition().toString())) {
+                augment2 = as;
+            } else if ("if:leafType='ds1'".equals(as.getWhenCondition().toString())) {
+                augment3 = as;
+            }
+        }
+        assertNotNull(augment1);
+        assertNotNull(augment2);
+        assertNotNull(augment3);
+
+        assertEquals(1, augment1.getChildNodes().size());
+        ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment1.getDataChildByName("augment-holder");
+        assertTrue(augmentHolder.isAugmenting());
+
+        assertEquals(1, augment2.getChildNodes().size());
+        ContainerSchemaNode augmentHolder2 = (ContainerSchemaNode) augment2.getDataChildByName("augment-holder2");
+        assertTrue(augmentHolder2.isAugmenting());
+
+        assertEquals(1, augment3.getChildNodes().size());
+        LeafSchemaNode linkleaf = (LeafSchemaNode) augment3.getDataChildByName("linkleaf");
+        assertTrue(linkleaf.isAugmenting());
+    }
+
+    @Test
+    public void testAugmentResolving() throws ParseException {
+        SchemaPath expectedPath = null;
+        QName[] qnames = null;
+
+        Module module2 = TestUtils.findModule(modules, "types");
+        ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
+        ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
+        ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder");
+
+        // testfile1.yang
+        // augment "/data:interfaces/data:ifEntry/t3:augment-holder"
+        LeafSchemaNode ds0ChannelNumber = (LeafSchemaNode) augmentedContainer.getDataChildByName("ds0ChannelNumber");
+        LeafSchemaNode interfaceId = (LeafSchemaNode) augmentedContainer.getDataChildByName("interface-id");
+        LeafSchemaNode myType = (LeafSchemaNode) augmentedContainer.getDataChildByName("my-type");
+        ContainerSchemaNode schemas = (ContainerSchemaNode) augmentedContainer.getDataChildByName("schemas");
+        ChoiceNode odl = (ChoiceNode)augmentedContainer.getDataChildByName("odl");
+
+        assertNotNull(ds0ChannelNumber);
+        assertNotNull(interfaceId);
+        assertNotNull(myType);
+        assertNotNull(schemas);
+        assertNotNull(odl);
+
+        qnames = new QName[4];
+        qnames[0] = q0;
+        qnames[1] = q1;
+        qnames[2] = q2;
+
+        // leaf ds0ChannelNumber
+        qnames[3] = new QName(types1NS, types1Rev, t1, "ds0ChannelNumber");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, ds0ChannelNumber.getPath());
+
+        // leaf interface-id
+        qnames[3] = new QName(types1NS, types1Rev, t1, "interface-id");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, interfaceId.getPath());
+
+        // leaf my-type
+        qnames[3] = new QName(types1NS, types1Rev, t1, "my-type");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, myType.getPath());
+
+        // container schemas
+        qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, schemas.getPath());
+
+        // choice odl
+        qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, odl.getPath());
+
+        // testfile3.yang
+        // augment "/data:interfaces/data:ifEntry/t3:augment-holder/t1:schemas"
+        LeafSchemaNode linkleaf = (LeafSchemaNode) schemas.getDataChildByName("linkleaf");
+        assertNotNull(linkleaf);
+
+        qnames = new QName[5];
+        qnames[0] = q0;
+        qnames[1] = q1;
+        qnames[2] = q2;
+        qnames[3] = new QName(types1NS, types1Rev, t1, "schemas");
+        qnames[4] = new QName(types3NS, types3Rev, t3, "linkleaf");
+        expectedPath = new SchemaPath(Arrays.asList(qnames), true);
+        assertEquals(expectedPath, linkleaf.getPath());
+    }
+
+    @Test
+    public void testAugmentChoice() throws ParseException {
+        SchemaPath expectedPath = null;
+        QName[] qnames = null;
+
+        Module module2 = TestUtils.findModule(modules, "types");
+        ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
+        ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
+        ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder");
+
+        // testfile1.yang
+        // augment "/data:interfaces/data:ifEntry/t3:augment-holder"
+        ChoiceNode odl = (ChoiceNode)augmentedContainer.getDataChildByName("odl");
+        assertNotNull(odl);
+        Set<ChoiceCaseNode> cases = odl.getCases();
+        assertEquals(4, cases.size());
+
+        ChoiceCaseNode id = null;
+        ChoiceCaseNode node1 = null;
+        ChoiceCaseNode node2 = null;
+        ChoiceCaseNode node3 = null;
+
+        for(ChoiceCaseNode ccn : cases) {
+            if("id".equals(ccn.getQName().getLocalName())) {
+                id = ccn;
+            } else if("node1".equals(ccn.getQName().getLocalName())) {
+                node1 = ccn;
+            } else if("node2".equals(ccn.getQName().getLocalName())) {
+                node2 = ccn;
+            } else if("node3".equals(ccn.getQName().getLocalName())) {
+                node3 = ccn;
+            }
+        }
+
+        assertNotNull(id);
+        assertNotNull(node1);
+        assertNotNull(node2);
+        assertNotNull(node3);
+
+        qnames = new QName[5];
+        qnames[0] = q0;
+        qnames[1] = q1;
+        qnames[2] = q2;
+        qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+
+        // case id
+        qnames[4] = new QName(types1NS, types1Rev, t1, "id");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, id.getPath());
+        Set<DataSchemaNode> idChildren = id.getChildNodes();
+        assertEquals(1, idChildren.size());
+
+        // case node1
+        qnames[4] = new QName(types1NS, types1Rev, t1, "node1");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, node1.getPath());
+        Set<DataSchemaNode> node1Children = node1.getChildNodes();
+        assertTrue(node1Children.isEmpty());
+
+        // case node2
+        qnames[4] = new QName(types1NS, types1Rev, t1, "node2");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, node2.getPath());
+        Set<DataSchemaNode> node2Children = node2.getChildNodes();
+        assertTrue(node2Children.isEmpty());
+
+        // case node3
+        qnames[4] = new QName(types1NS, types1Rev, t1, "node3");
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, node3.getPath());
+        Set<DataSchemaNode> node3Children = node3.getChildNodes();
+        assertEquals(1, node3Children.size());
+
+        // test cases
+        qnames = new QName[6];
+        qnames[0] = q0;
+        qnames[1] = q1;
+        qnames[2] = q2;
+        qnames[3] = new QName(types1NS, types1Rev, t1, "odl");
+
+        // case id child
+        qnames[4] = new QName(types1NS, types1Rev, t1, "id");
+        qnames[5] = new QName(types1NS, types1Rev, t1, "id");
+        LeafSchemaNode caseIdChild = (LeafSchemaNode)idChildren.iterator().next();
+        assertNotNull(caseIdChild);
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, caseIdChild.getPath());
+
+        // case node3 child
+        qnames[4] = new QName(types1NS, types1Rev, t1, "node3");
+        qnames[5] = new QName(types1NS, types1Rev, t1, "node3");
+        ContainerSchemaNode caseNode3Child = (ContainerSchemaNode)node3Children.iterator().next();
+        assertNotNull(caseNode3Child);
+        expectedPath = new SchemaPath(Lists.newArrayList(qnames), true);
+        assertEquals(expectedPath, caseNode3Child.getPath());
+    }
+
+    @Test
+    public void testAugmentNodesTypeSchemaPath() throws Exception {
+        Module testModule = TestUtils.findModule(modules, "nodes");
+        Set<AugmentationSchema> augments = testModule.getAugmentations();
+        assertEquals(1, augments.size());
+        AugmentationSchema augment = augments.iterator().next();
+
+        LeafSchemaNode ifcId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
+        Leafref ifcIdType = (Leafref) ifcId.getType();
+        SchemaPath ifcIdTypeSchemaPath = ifcIdType.getPath();
+        List<QName> ifcIdTypePath = ifcIdTypeSchemaPath.getPath();
+
+        Date expectedDate = simpleDateFormat.parse("2013-02-27");
+
+        QName q3 = new QName(types1NS, expectedDate, "data", "interface-id");
+        assertEquals(q0, ifcIdTypePath.get(0));
+        assertEquals(q1, ifcIdTypePath.get(1));
+        assertEquals(q2, ifcIdTypePath.get(2));
+        assertEquals(q3, ifcIdTypePath.get(3));
+
+        LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type");
+        ExtendedType leafType = (ExtendedType) myType.getType();
+
+        testModule = TestUtils.findModule(modules, "types");
+        TypeDefinition<?> typedef = TestUtils.findTypedef(testModule.getTypeDefinitions(), "int32-ext2");
+
+        assertEquals(typedef, leafType);
+    }
+
+}
index 2442f51da3d62f90fb521eb2339477d31e4314e3..88d7543520cf79b5b6446c11deaf52fb11b1582b 100644 (file)
@@ -43,7 +43,7 @@ public class GroupingTest {
 
     @Test
     public void testRefine() {
-        Module testModule = TestUtils.findModule(modules, "types2");
+        Module testModule = TestUtils.findModule(modules, "nodes");
 
         ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
         ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
@@ -119,7 +119,7 @@ public class GroupingTest {
 
     @Test
     public void testGrouping() {
-        Module testModule = TestUtils.findModule(modules, "types2");
+        Module testModule = TestUtils.findModule(modules, "custom");
         Set<GroupingDefinition> groupings = testModule.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition grouping = groupings.iterator().next();
@@ -132,13 +132,15 @@ public class GroupingTest {
         // suffix _u = added by uses
         // suffix _g = defined in grouping
 
-        Module testModule = TestUtils.findModule(modules, "types2");
+        Module testModule = TestUtils.findModule(modules, "custom");
 
         // get grouping
         Set<GroupingDefinition> groupings = testModule.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition grouping = groupings.iterator().next();
 
+        testModule = TestUtils.findModule(modules, "nodes");
+
         // get node containing uses
         ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
         ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
index 3eff948d8b65b81df3c776d2f2507d68eaa466bb..f2478e741dddeb3dd65db2740f334e599ffe0274 100644 (file)
@@ -34,7 +34,6 @@ import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
 import org.opendaylight.controller.yang.model.api.ExtensionDefinition;
 import org.opendaylight.controller.yang.model.api.FeatureDefinition;
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
-import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
 import org.opendaylight.controller.yang.model.api.Module;
@@ -52,42 +51,51 @@ import org.opendaylight.controller.yang.model.util.Decimal64;
 import org.opendaylight.controller.yang.model.util.ExtendedType;
 import org.opendaylight.controller.yang.model.util.Int16;
 import org.opendaylight.controller.yang.model.util.Int32;
-import org.opendaylight.controller.yang.model.util.Int8;
-import org.opendaylight.controller.yang.model.util.Leafref;
 import org.opendaylight.controller.yang.model.util.StringType;
 import org.opendaylight.controller.yang.model.util.Uint32;
 import org.opendaylight.controller.yang.model.util.UnionType;
 
 public class YangParserTest {
+
+    private final URI nodesNS = URI.create("urn:simple.nodes.test");
+    private final URI typesNS = URI.create("urn:simple.types.test");
+    private final URI customNS = URI.create("urn:custom.nodes.test");
+    private Date nodesRev;
+    private Date typesRev;
+    private Date customRev;
+
     private final DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
     private Set<Module> modules;
 
     @Before
-    public void init() throws FileNotFoundException {
+    public void init() throws FileNotFoundException, ParseException {
+        nodesRev = simpleDateFormat.parse("2013-02-27");
+        typesRev = simpleDateFormat.parse("2013-07-03");
+        customRev = simpleDateFormat.parse("2013-02-27");
+
         modules = TestUtils.loadModules(getClass().getResource("/model").getPath());
         assertEquals(3, modules.size());
     }
 
     @Test
-    public void testHeaders() {
-        Module test = TestUtils.findModule(modules, "types1");
+    public void testHeaders() throws ParseException {
+        Module test = TestUtils.findModule(modules, "nodes");
 
-        assertEquals("types1", test.getName());
+        assertEquals("nodes", test.getName());
         assertEquals("1", test.getYangVersion());
-        URI expectedNamespace = URI.create("urn:simple.container.demo");
-        assertEquals(expectedNamespace, test.getNamespace());
-        assertEquals("t1", test.getPrefix());
+        assertEquals(nodesNS, test.getNamespace());
+        assertEquals("n", test.getPrefix());
 
         Set<ModuleImport> imports = test.getImports();
         assertEquals(2, imports.size());
 
-        ModuleImport import2 = TestUtils.findImport(imports, "data");
-        assertEquals("types2", import2.getModuleName());
-        assertEquals(TestUtils.createDate("2013-02-27"), import2.getRevision());
+        ModuleImport import2 = TestUtils.findImport(imports, "t");
+        assertEquals("types", import2.getModuleName());
+        assertEquals(typesRev, import2.getRevision());
 
-        ModuleImport import3 = TestUtils.findImport(imports, "t3");
-        assertEquals("types3", import3.getModuleName());
-        assertEquals(TestUtils.createDate("2013-02-27"), import3.getRevision());
+        ModuleImport import3 = TestUtils.findImport(imports, "c");
+        assertEquals("custom", import3.getModuleName());
+        assertEquals(customRev, import3.getRevision());
 
         assertEquals("opendaylight", test.getOrganization());
         assertEquals("http://www.opendaylight.org/", test.getContact());
@@ -98,12 +106,10 @@ public class YangParserTest {
 
     @Test
     public void testOrderingTypedef() {
-        Module test = TestUtils.findModule(modules, "types2");
+        Module test = TestUtils.findModule(modules, "types");
         Set<TypeDefinition<?>> typedefs = test.getTypeDefinitions();
-        String[] expectedOrder = new String[] { "my-base-int32-type", "my-custom-string", "my-decimal-type",
-                "my-decimal-type-ext", "my-int-type", "my-int-type-ext", "my-int-type2", "my-string-type",
-                "my-string-type-ext", "my-string-type2", "my-type1", "my-union", "my-union-ext", "nested-union1",
-                "nested-union2" };
+        String[] expectedOrder = new String[] { "int32-ext1", "int32-ext2", "my-decimal-type", "my-union",
+                "my-union-ext", "nested-union2", "string-ext1", "string-ext2", "string-ext3", "string-ext4" };
         String[] actualOrder = new String[typedefs.size()];
 
         int i = 0;
@@ -116,23 +122,31 @@ public class YangParserTest {
 
     @Test
     public void testOrderingChildNodes() {
-        Module test = TestUtils.findModule(modules, "types2");
-        Set<DataSchemaNode> childNodes = test.getChildNodes();
-        String[] expectedOrder = new String[] { "count", "if-name", "interfaces", "name", "nested-type-leaf", "peer",
-                "system" };
-        String[] actualOrder = new String[childNodes.size()];
+        Module test = TestUtils.findModule(modules, "nodes");
+        AugmentationSchema augment1 = null;
+        for (AugmentationSchema as : test.getAugmentations()) {
+            if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
+                augment1 = as;
+                break;
+            }
+        }
+        assertNotNull(augment1);
+
+        String[] expectedOrder = new String[] { "ds0ChannelNumber", "interface-id", "my-type", "odl", "schemas" };
+        String[] actualOrder = new String[expectedOrder.length];
 
         int i = 0;
-        for (DataSchemaNode child : childNodes) {
-            actualOrder[i] = child.getQName().getLocalName();
+        for (DataSchemaNode augmentChild : augment1.getChildNodes()) {
+            actualOrder[i] = augmentChild.getQName().getLocalName();
             i++;
         }
+
         assertArrayEquals(expectedOrder, actualOrder);
     }
 
     @Test
     public void testOrderingNestedChildNodes() {
-        Module test = TestUtils.findModule(modules, "types2");
+        Module test = TestUtils.findModule(modules, "custom");
         Set<GroupingDefinition> groupings = test.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition target = groupings.iterator().next();
@@ -151,17 +165,15 @@ public class YangParserTest {
 
     @Test
     public void testParseContainer() {
-        Module test = TestUtils.findModule(modules, "types2");
-        URI expectedNamespace = URI.create("urn:simple.types.data.demo");
-        String expectedPrefix = "t2";
-        Date expectedRevision = TestUtils.createDate("2013-02-27");
+        Module test = TestUtils.findModule(modules, "types");
+        URI expectedNamespace = URI.create("urn:simple.types.test");
+        String expectedPrefix = "t";
 
         ContainerSchemaNode interfaces = (ContainerSchemaNode) test.getDataChildByName("interfaces");
         // test SchemaNode args
-        QName expectedQName = new QName(expectedNamespace, expectedRevision, expectedPrefix, "interfaces");
+        QName expectedQName = new QName(expectedNamespace, typesRev, expectedPrefix, "interfaces");
         assertEquals(expectedQName, interfaces.getQName());
-        SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, expectedRevision, expectedPrefix,
-                "interfaces");
+        SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, typesRev, expectedPrefix, "interfaces");
         assertEquals(expectedPath, interfaces.getPath());
         assertNull(interfaces.getDescription());
         assertNull(interfaces.getReference());
@@ -192,19 +204,18 @@ public class YangParserTest {
 
     @Test
     public void testParseList() {
-        Module test = TestUtils.findModule(modules, "types2");
-        URI expectedNamespace = URI.create("urn:simple.types.data.demo");
-        String expectedPrefix = "t2";
-        Date expectedRevision = TestUtils.createDate("2013-02-27");
+        Module test = TestUtils.findModule(modules, "types");
+        URI expectedNamespace = URI.create("urn:simple.types.test");
+        String expectedPrefix = "t";
 
         ContainerSchemaNode interfaces = (ContainerSchemaNode) test.getDataChildByName("interfaces");
 
         ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
         // test SchemaNode args
-        QName expectedQName = new QName(expectedNamespace, expectedRevision, expectedPrefix, "ifEntry");
+        QName expectedQName = new QName(expectedNamespace, typesRev, expectedPrefix, "ifEntry");
         assertEquals(expectedQName, ifEntry.getQName());
-        SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, expectedRevision, expectedPrefix,
-                "interfaces", "ifEntry");
+        SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, typesRev, expectedPrefix, "interfaces",
+                "ifEntry");
         assertEquals(expectedPath, ifEntry.getPath());
         assertNull(ifEntry.getDescription());
         assertNull(ifEntry.getReference());
@@ -224,7 +235,7 @@ public class YangParserTest {
         assertEquals(2, availableAugmentations.size());
         // test ListSchemaNode args
         List<QName> expectedKey = new ArrayList<QName>();
-        expectedKey.add(new QName(expectedNamespace, expectedRevision, expectedPrefix, "ifIndex"));
+        expectedKey.add(new QName(expectedNamespace, typesRev, expectedPrefix, "ifIndex"));
         assertEquals(expectedKey, ifEntry.getKeyDefinition());
         assertFalse(ifEntry.isUserOrdered());
         // test DataNodeContainer args
@@ -239,237 +250,228 @@ public class YangParserTest {
         assertTrue(ifMtu.getType() instanceof Int32);
     }
 
-    @Test
-    public void testParseLeaf() throws ParseException {
-        Module test = TestUtils.findModule(modules, "types2");
-
-        // leaf if-name
-        LeafSchemaNode ifName = (LeafSchemaNode) test.getDataChildByName("if-name");
-        Leafref ifNameType = (Leafref) ifName.getType();
-        QName qname = ifNameType.getQName();
-
-        URI baseYangTypeNS = URI.create("urn:ietf:params:xml:ns:yang:1");
-        assertEquals(baseYangTypeNS, qname.getNamespace());
-        assertNull(qname.getRevision());
-        assertEquals("", qname.getPrefix());
-        assertEquals("leafref", qname.getLocalName());
-
-        // leaf name
-        LeafSchemaNode name = (LeafSchemaNode) test.getDataChildByName("name");
-        StringType nameType = (StringType) name.getType();
-        QName nameQName = nameType.getQName();
-
-        assertEquals(baseYangTypeNS, nameQName.getNamespace());
-        assertNull(nameQName.getRevision());
-        assertEquals("", nameQName.getPrefix());
-        assertEquals("string", nameQName.getLocalName());
-
-        // leaf count
-        LeafSchemaNode count = (LeafSchemaNode) test.getDataChildByName("count");
-        ExtendedType countType = (ExtendedType) count.getType();
-        QName countTypeQName = countType.getQName();
-
-        URI expectedNS = URI.create("urn:simple.types.data.demo");
-        Date expectedDate = simpleDateFormat.parse("2013-02-27");
-        assertEquals(expectedNS, countTypeQName.getNamespace());
-        assertEquals(expectedDate, countTypeQName.getRevision());
-        assertEquals("t2", countTypeQName.getPrefix());
-        assertEquals("int8", countTypeQName.getLocalName());
-
-        Int8 countTypeBase = (Int8) countType.getBaseType();
-        QName countTypeBaseQName = countTypeBase.getQName();
-
-        assertEquals(baseYangTypeNS, countTypeBaseQName.getNamespace());
-        assertNull(countTypeBaseQName.getRevision());
-        assertEquals("", countTypeBaseQName.getPrefix());
-        assertEquals("int8", countTypeBaseQName.getLocalName());
-    }
-
-    @Test
-    public void testAugmentResolving() {
-        // testfile1
-        Module module1 = TestUtils.findModule(modules, "types1");
-
-        Set<AugmentationSchema> module1Augmentations = module1.getAugmentations();
-        AugmentationSchema augment1 = module1Augmentations.iterator().next();
-        LeafSchemaNode augmentedLeafDefinition = (LeafSchemaNode) augment1.getDataChildByName("ds0ChannelNumber");
-        assertTrue(augmentedLeafDefinition.isAugmenting());
-
-        // testfile2
-        Module module2 = TestUtils.findModule(modules, "types2");
-
-        ContainerSchemaNode interfaces = (ContainerSchemaNode) module2.getDataChildByName("interfaces");
-        ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
-        ContainerSchemaNode augmentedContainer = (ContainerSchemaNode) ifEntry.getDataChildByName("augment-holder");
-
-        ContainerSchemaNode schemas = (ContainerSchemaNode) augmentedContainer.getDataChildByName("schemas");
-        LeafSchemaNode linkleaf = (LeafSchemaNode) schemas.getDataChildByName("linkleaf");
-        assertNotNull(linkleaf);
-
-        // augmentation defined in testfile1 and augmentation returned from
-        // augmented container have to be same
-        Set<AugmentationSchema> augmentedContainerAugments = augmentedContainer.getAvailableAugmentations();
-        AugmentationSchema augmentDefinition = augmentedContainerAugments.iterator().next();
-        assertEquals(augment1, augmentDefinition);
-
-        LeafSchemaNode augmentedLeaf = (LeafSchemaNode) augmentedContainer.getDataChildByName("ds0ChannelNumber");
-        assertTrue(augmentedLeaf.isAugmenting());
-        assertEquals(augmentedLeafDefinition, augmentedLeaf);
-
-        Set<AugmentationSchema> ifEntryAugments = ifEntry.getAvailableAugmentations();
-        assertEquals(2, ifEntryAugments.size());
-
-        // testfile3
-        Module module3 = TestUtils.findModule(modules, "types3");
-
-        Set<AugmentationSchema> module3Augmentations = module3.getAugmentations();
-        assertEquals(3, module3Augmentations.size());
-        AugmentationSchema augment3 = null;
-        for (AugmentationSchema as : module3Augmentations) {
-            if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
-                augment3 = as;
-            }
-        }
-        ContainerSchemaNode augmentedContainerDefinition = (ContainerSchemaNode) augment3
-                .getDataChildByName("augment-holder");
-        assertTrue(augmentedContainerDefinition.isAugmenting());
-
-        // check
-        assertEquals(augmentedContainer, augmentedContainerDefinition);
-        assertEquals(augmentedLeaf, augmentedLeafDefinition);
-    }
-
-    @Test
-    public void testAugmentTarget() {
-        Module test = TestUtils.findModule(modules, "types2");
-
-        ContainerSchemaNode interfaces = (ContainerSchemaNode) test.getDataChildByName("interfaces");
-        ListSchemaNode ifEntry = (ListSchemaNode) interfaces.getDataChildByName("ifEntry");
-        Set<AugmentationSchema> augmentations = ifEntry.getAvailableAugmentations();
-        assertEquals(2, augmentations.size());
-
-        AugmentationSchema augment = null;
-        for (AugmentationSchema as : augmentations) {
-            if ("if:ifType='ds0'".equals(as.getWhenCondition().toString())) {
-                augment = as;
-            }
-        }
-        ContainerSchemaNode augmentHolder = (ContainerSchemaNode) augment.getDataChildByName("augment-holder");
-        assertNotNull(augmentHolder);
-        assertTrue(augmentHolder.isAugmenting());
-        QName augmentHolderQName = augmentHolder.getQName();
-        assertEquals("augment-holder", augmentHolderQName.getLocalName());
-        assertEquals("t3", augmentHolderQName.getPrefix());
-        assertEquals("Description for augment holder", augmentHolder.getDescription());
-    }
-
     @Test
     public void testTypedefRangesResolving() throws ParseException {
-        Module testModule = TestUtils.findModule(modules, "types1");
+        Module testModule = TestUtils.findModule(modules, "nodes");
+        LeafSchemaNode int32Leaf = (LeafSchemaNode) testModule.getDataChildByName("int32-leaf");
 
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("testleaf");
-        ExtendedType leafType = (ExtendedType) testleaf.getType();
+        ExtendedType leafType = (ExtendedType) int32Leaf.getType();
         QName leafTypeQName = leafType.getQName();
-        assertEquals("my-type1", leafTypeQName.getLocalName());
-        assertEquals("t1", leafTypeQName.getPrefix());
-        assertEquals(URI.create("urn:simple.container.demo"), leafTypeQName.getNamespace());
-        Date expectedDate = simpleDateFormat.parse("2013-02-27");
-        assertEquals(expectedDate, leafTypeQName.getRevision());
-        assertEquals(1, leafType.getRanges().size());
-
-        ExtendedType baseType = (ExtendedType) leafType.getBaseType();
-        QName baseTypeQName = baseType.getQName();
-        assertEquals("my-type1", baseTypeQName.getLocalName());
-        assertEquals("t2", baseTypeQName.getPrefix());
-        assertEquals(URI.create("urn:simple.types.data.demo"), baseTypeQName.getNamespace());
-        assertEquals(expectedDate, baseTypeQName.getRevision());
-        assertEquals(2, baseType.getRanges().size());
-
+        assertEquals("int32-ext2", leafTypeQName.getLocalName());
+        assertEquals("n", leafTypeQName.getPrefix());
+        assertEquals(nodesNS, leafTypeQName.getNamespace());
+        assertEquals(nodesRev, leafTypeQName.getRevision());
+        assertNull(leafType.getUnits());
+        assertNull(leafType.getDefaultValue());
+        assertTrue(leafType.getLengths().isEmpty());
+        assertTrue(leafType.getPatterns().isEmpty());
         List<RangeConstraint> ranges = leafType.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
         assertEquals(12L, range.getMin());
         assertEquals(20L, range.getMax());
+
+        ExtendedType baseType = (ExtendedType) leafType.getBaseType();
+        QName baseTypeQName = baseType.getQName();
+        assertEquals("int32-ext2", baseTypeQName.getLocalName());
+        assertEquals("t", baseTypeQName.getPrefix());
+        assertEquals(typesNS, baseTypeQName.getNamespace());
+        assertEquals(typesRev, baseTypeQName.getRevision());
+        assertEquals("mile", baseType.getUnits());
+        assertEquals("11", baseType.getDefaultValue());
+        assertTrue(leafType.getLengths().isEmpty());
+        assertTrue(leafType.getPatterns().isEmpty());
+        List<RangeConstraint> baseTypeRanges = baseType.getRanges();
+        assertEquals(2, baseTypeRanges.size());
+        RangeConstraint baseTypeRange1 = baseTypeRanges.get(0);
+        assertEquals(3L, baseTypeRange1.getMin());
+        assertEquals(9L, baseTypeRange1.getMax());
+        RangeConstraint baseTypeRange2 = baseTypeRanges.get(1);
+        assertEquals(11L, baseTypeRange2.getMin());
+        assertEquals(20L, baseTypeRange2.getMax());
+
+        ExtendedType base = (ExtendedType) baseType.getBaseType();
+        QName baseQName = base.getQName();
+        assertEquals("int32-ext1", baseQName.getLocalName());
+        assertEquals("t", baseQName.getPrefix());
+        assertEquals(typesNS, baseQName.getNamespace());
+        assertEquals(typesRev, baseQName.getRevision());
+        assertNull(base.getUnits());
+        assertNull(base.getDefaultValue());
+        assertTrue(leafType.getLengths().isEmpty());
+        assertTrue(leafType.getPatterns().isEmpty());
+        List<RangeConstraint> baseRanges = base.getRanges();
+        assertEquals(1, baseRanges.size());
+        RangeConstraint baseRange = baseRanges.get(0);
+        assertEquals(2L, baseRange.getMin());
+        assertEquals(20L, baseRange.getMax());
+
+        assertTrue(base.getBaseType() instanceof Int32);
     }
 
     @Test
     public void testTypedefPatternsResolving() {
-        Module testModule = TestUtils.findModule(modules, "types1");
-
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("test-string-leaf");
-        ExtendedType testleafType = (ExtendedType) testleaf.getType();
-        QName testleafTypeQName = testleafType.getQName();
-        assertEquals("my-string-type-ext", testleafTypeQName.getLocalName());
-        assertEquals("t2", testleafTypeQName.getPrefix());
-
-        List<PatternConstraint> patterns = testleafType.getPatterns();
+        Module testModule = TestUtils.findModule(modules, "nodes");
+        LeafSchemaNode stringleaf = (LeafSchemaNode) testModule.getDataChildByName("string-leaf");
+
+        ExtendedType type = (ExtendedType) stringleaf.getType();
+        QName typeQName = type.getQName();
+        assertEquals("string-ext4", typeQName.getLocalName());
+        assertEquals("t", typeQName.getPrefix());
+        assertEquals(typesNS, typeQName.getNamespace());
+        assertEquals(typesRev, typeQName.getRevision());
+        assertNull(type.getUnits());
+        assertNull(type.getDefaultValue());
+        List<PatternConstraint> patterns = type.getPatterns();
         assertEquals(1, patterns.size());
         PatternConstraint pattern = patterns.iterator().next();
         assertEquals("[e-z]*", pattern.getRegularExpression());
-
-        ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
-        assertEquals("my-string-type2", baseType.getQName().getLocalName());
-
-        patterns = baseType.getPatterns();
+        assertTrue(type.getLengths().isEmpty());
+        assertTrue(type.getRanges().isEmpty());
+
+        ExtendedType baseType1 = (ExtendedType) type.getBaseType();
+        QName baseType1QName = baseType1.getQName();
+        assertEquals("string-ext3", baseType1QName.getLocalName());
+        assertEquals("t", baseType1QName.getPrefix());
+        assertEquals(typesNS, baseType1QName.getNamespace());
+        assertEquals(typesRev, baseType1QName.getRevision());
+        assertNull(baseType1.getUnits());
+        assertNull(baseType1.getDefaultValue());
+        patterns = baseType1.getPatterns();
         assertEquals(1, patterns.size());
         pattern = patterns.iterator().next();
         assertEquals("[b-u]*", pattern.getRegularExpression());
-
-        List<LengthConstraint> lengths = testleafType.getLengths();
-        assertTrue(lengths.isEmpty());
+        assertTrue(baseType1.getLengths().isEmpty());
+        assertTrue(baseType1.getRanges().isEmpty());
+
+        ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType();
+        QName baseType2QName = baseType2.getQName();
+        assertEquals("string-ext2", baseType2QName.getLocalName());
+        assertEquals("t", baseType2QName.getPrefix());
+        assertEquals(typesNS, baseType2QName.getNamespace());
+        assertEquals(typesRev, baseType2QName.getRevision());
+        assertNull(baseType2.getUnits());
+        assertNull(baseType2.getDefaultValue());
+        assertTrue(baseType2.getPatterns().isEmpty());
+        List<LengthConstraint> baseType2Lengths = baseType2.getLengths();
+        assertEquals(1, baseType2Lengths.size());
+        LengthConstraint length = baseType2Lengths.get(0);
+        assertEquals(6L, length.getMin());
+        assertEquals(10L, length.getMax());
+        assertTrue(baseType2.getRanges().isEmpty());
+
+        ExtendedType baseType3 = (ExtendedType) baseType2.getBaseType();
+        QName baseType3QName = baseType3.getQName();
+        assertEquals("string-ext1", baseType3QName.getLocalName());
+        assertEquals("t", baseType3QName.getPrefix());
+        assertEquals(typesNS, baseType3QName.getNamespace());
+        assertEquals(typesRev, baseType3QName.getRevision());
+        assertNull(baseType3.getUnits());
+        assertNull(baseType3.getDefaultValue());
+        patterns = baseType3.getPatterns();
+        assertEquals(1, patterns.size());
+        pattern = patterns.iterator().next();
+        assertEquals("[a-k]*", pattern.getRegularExpression());
+        List<LengthConstraint> baseType3Lengths = baseType3.getLengths();
+        assertEquals(1, baseType3Lengths.size());
+        length = baseType3Lengths.get(0);
+        assertEquals(5L, length.getMin());
+        assertEquals(11L, length.getMax());
+        assertTrue(baseType3.getRanges().isEmpty());
+
+        assertTrue(baseType3.getBaseType() instanceof StringType);
     }
 
     @Test
     public void testTypedefLengthsResolving() {
-        Module testModule = TestUtils.findModule(modules, "types1");
-
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("leaf-with-length");
-        ExtendedType testleafType = (ExtendedType) testleaf.getType();
-        assertEquals("my-string-type", testleafType.getQName().getLocalName());
-
-        List<LengthConstraint> lengths = testleafType.getLengths();
-        assertEquals(1, lengths.size());
-
-        LengthConstraint length = lengths.get(0);
+        Module testModule = TestUtils.findModule(modules, "nodes");
+
+        LeafSchemaNode lengthLeaf = (LeafSchemaNode) testModule.getDataChildByName("length-leaf");
+        ExtendedType type = (ExtendedType) lengthLeaf.getType();
+
+        QName typeQName = type.getQName();
+        assertEquals("string-ext2", typeQName.getLocalName());
+        assertEquals("n", typeQName.getPrefix());
+        assertEquals(nodesNS, typeQName.getNamespace());
+        assertEquals(nodesRev, typeQName.getRevision());
+        assertNull(type.getUnits());
+        assertNull(type.getDefaultValue());
+        assertTrue(type.getPatterns().isEmpty());
+        List<LengthConstraint> typeLengths = type.getLengths();
+        assertEquals(1, typeLengths.size());
+        LengthConstraint length = typeLengths.get(0);
         assertEquals(7L, length.getMin());
         assertEquals(10L, length.getMax());
-    }
-
-    @Test
-    public void testTypeDef() {
-        Module testModule = TestUtils.findModule(modules, "types2");
-
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("nested-type-leaf");
-        ExtendedType testleafType = (ExtendedType) testleaf.getType();
-        assertEquals("my-type1", testleafType.getQName().getLocalName());
-
-        ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
-        assertEquals("my-base-int32-type", baseType.getQName().getLocalName());
-
-        Int32 int32Type = (Int32) baseType.getBaseType();
-        QName qname = int32Type.getQName();
-        assertEquals(URI.create("urn:ietf:params:xml:ns:yang:1"), qname.getNamespace());
-        assertNull(qname.getRevision());
-        assertEquals("", qname.getPrefix());
-        assertEquals("int32", qname.getLocalName());
-        List<RangeConstraint> ranges = baseType.getRanges();
-        assertEquals(1, ranges.size());
-        RangeConstraint range = ranges.get(0);
-        assertEquals(2L, range.getMin());
-        assertEquals(20L, range.getMax());
+        assertTrue(type.getRanges().isEmpty());
+
+        ExtendedType baseType1 = (ExtendedType) type.getBaseType();
+        QName baseType1QName = baseType1.getQName();
+        assertEquals("string-ext2", baseType1QName.getLocalName());
+        assertEquals("t", baseType1QName.getPrefix());
+        assertEquals(typesNS, baseType1QName.getNamespace());
+        assertEquals(typesRev, baseType1QName.getRevision());
+        assertNull(baseType1.getUnits());
+        assertNull(baseType1.getDefaultValue());
+        assertTrue(baseType1.getPatterns().isEmpty());
+        List<LengthConstraint> baseType2Lengths = baseType1.getLengths();
+        assertEquals(1, baseType2Lengths.size());
+        length = baseType2Lengths.get(0);
+        assertEquals(6L, length.getMin());
+        assertEquals(10L, length.getMax());
+        assertTrue(baseType1.getRanges().isEmpty());
+
+        ExtendedType baseType2 = (ExtendedType) baseType1.getBaseType();
+        QName baseType2QName = baseType2.getQName();
+        assertEquals("string-ext1", baseType2QName.getLocalName());
+        assertEquals("t", baseType2QName.getPrefix());
+        assertEquals(typesNS, baseType2QName.getNamespace());
+        assertEquals(typesRev, baseType2QName.getRevision());
+        assertNull(baseType2.getUnits());
+        assertNull(baseType2.getDefaultValue());
+        List<PatternConstraint> patterns = baseType2.getPatterns();
+        assertEquals(1, patterns.size());
+        PatternConstraint pattern = patterns.iterator().next();
+        assertEquals("[a-k]*", pattern.getRegularExpression());
+        List<LengthConstraint> baseType3Lengths = baseType2.getLengths();
+        assertEquals(1, baseType3Lengths.size());
+        length = baseType3Lengths.get(0);
+        assertEquals(5L, length.getMin());
+        assertEquals(11L, length.getMax());
+        assertTrue(baseType2.getRanges().isEmpty());
+
+        assertTrue(baseType2.getBaseType() instanceof StringType);
     }
 
     @Test
     public void testTypedefDecimal1() {
-        Module testModule = TestUtils.findModule(modules, "types1");
+        Module testModule = TestUtils.findModule(modules, "nodes");
+        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("decimal-leaf");
 
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("test-decimal-leaf");
         ExtendedType type = (ExtendedType) testleaf.getType();
+        QName typeQName = type.getQName();
+        assertEquals("my-decimal-type", typeQName.getLocalName());
+        assertEquals("n", typeQName.getPrefix());
+        assertEquals(nodesNS, typeQName.getNamespace());
+        assertEquals(nodesRev, typeQName.getRevision());
+        assertNull(type.getUnits());
+        assertNull(type.getDefaultValue());
         assertEquals(4, (int) type.getFractionDigits());
+        assertTrue(type.getLengths().isEmpty());
+        assertTrue(type.getPatterns().isEmpty());
+        assertTrue(type.getRanges().isEmpty());
 
         ExtendedType typeBase = (ExtendedType) type.getBaseType();
-        assertEquals("my-decimal-type", typeBase.getQName().getLocalName());
+        QName typeBaseQName = typeBase.getQName();
+        assertEquals("my-decimal-type", typeBaseQName.getLocalName());
+        assertEquals("t", typeBaseQName.getPrefix());
+        assertEquals(typesNS, typeBaseQName.getNamespace());
+        assertEquals(typesRev, typeBaseQName.getRevision());
+        assertNull(typeBase.getUnits());
+        assertNull(typeBase.getDefaultValue());
         assertNull(typeBase.getFractionDigits());
+        assertTrue(typeBase.getLengths().isEmpty());
+        assertTrue(typeBase.getPatterns().isEmpty());
+        assertTrue(typeBase.getRanges().isEmpty());
 
         Decimal64 decimal = (Decimal64) typeBase.getBaseType();
         assertEquals(6, (int) decimal.getFractionDigits());
@@ -477,147 +479,195 @@ public class YangParserTest {
 
     @Test
     public void testTypedefDecimal2() {
-        Module testModule = TestUtils.findModule(modules, "types1");
+        Module testModule = TestUtils.findModule(modules, "nodes");
+        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("decimal-leaf2");
 
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("test-decimal-leaf2");
-        TypeDefinition<?> baseType = testleaf.getType().getBaseType();
-        assertTrue(testleaf.getType().getBaseType() instanceof Decimal64);
-        Decimal64 baseTypeCast = (Decimal64) baseType;
-        assertEquals(5, (int) baseTypeCast.getFractionDigits());
+        ExtendedType type = (ExtendedType) testleaf.getType();
+        QName typeQName = type.getQName();
+        assertEquals("my-decimal-type", typeQName.getLocalName());
+        assertEquals("t", typeQName.getPrefix());
+        assertEquals(typesNS, typeQName.getNamespace());
+        assertEquals(typesRev, typeQName.getRevision());
+        assertNull(type.getUnits());
+        assertNull(type.getDefaultValue());
+        assertNull(type.getFractionDigits());
+        assertTrue(type.getLengths().isEmpty());
+        assertTrue(type.getPatterns().isEmpty());
+        assertTrue(type.getRanges().isEmpty());
+
+        Decimal64 baseTypeDecimal = (Decimal64) type.getBaseType();
+        assertEquals(6, (int) baseTypeDecimal.getFractionDigits());
     }
 
     @Test
     public void testTypedefUnion() {
-        Module testModule = TestUtils.findModule(modules, "types1");
-
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("union-leaf");
-        ExtendedType testleafType = (ExtendedType) testleaf.getType();
-        assertEquals("my-union-ext", testleafType.getQName().getLocalName());
-
-        ExtendedType baseType = (ExtendedType) testleafType.getBaseType();
-        assertEquals("my-union", baseType.getQName().getLocalName());
-
-        UnionType unionBase = (UnionType) baseType.getBaseType();
+        Module testModule = TestUtils.findModule(modules, "nodes");
+        LeafSchemaNode unionleaf = (LeafSchemaNode) testModule.getDataChildByName("union-leaf");
+
+        ExtendedType type = (ExtendedType) unionleaf.getType();
+        QName typeQName = type.getQName();
+        assertEquals("my-union-ext", typeQName.getLocalName());
+        assertEquals("t", typeQName.getPrefix());
+        assertEquals(typesNS, typeQName.getNamespace());
+        assertEquals(typesRev, typeQName.getRevision());
+        assertNull(type.getUnits());
+        assertNull(type.getDefaultValue());
+        assertNull(type.getFractionDigits());
+        assertTrue(type.getLengths().isEmpty());
+        assertTrue(type.getPatterns().isEmpty());
+        assertTrue(type.getRanges().isEmpty());
+
+        ExtendedType baseType = (ExtendedType) type.getBaseType();
+        QName baseTypeQName = baseType.getQName();
+        assertEquals("my-union", baseTypeQName.getLocalName());
+        assertEquals("t", baseTypeQName.getPrefix());
+        assertEquals(typesNS, baseTypeQName.getNamespace());
+        assertEquals(typesRev, baseTypeQName.getRevision());
+        assertNull(baseType.getUnits());
+        assertNull(baseType.getDefaultValue());
+        assertNull(baseType.getFractionDigits());
+        assertTrue(baseType.getLengths().isEmpty());
+        assertTrue(baseType.getPatterns().isEmpty());
+        assertTrue(baseType.getRanges().isEmpty());
+
+        UnionType unionType = (UnionType) baseType.getBaseType();
+        List<TypeDefinition<?>> unionTypes = unionType.getTypes();
+        assertEquals(2, unionTypes.size());
 
-        List<TypeDefinition<?>> unionTypes = unionBase.getTypes();
         ExtendedType unionType1 = (ExtendedType) unionTypes.get(0);
+        QName unionType1QName = baseType.getQName();
+        assertEquals("my-union", unionType1QName.getLocalName());
+        assertEquals("t", unionType1QName.getPrefix());
+        assertEquals(typesNS, unionType1QName.getNamespace());
+        assertEquals(typesRev, unionType1QName.getRevision());
+        assertNull(unionType1.getUnits());
+        assertNull(unionType1.getDefaultValue());
+        assertNull(unionType1.getFractionDigits());
+        assertTrue(unionType1.getLengths().isEmpty());
+        assertTrue(unionType1.getPatterns().isEmpty());
         List<RangeConstraint> ranges = unionType1.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
         assertEquals(1L, range.getMin());
         assertEquals(100L, range.getMax());
-
         assertTrue(unionType1.getBaseType() instanceof Int16);
-        assertTrue(unionTypes.get(1) instanceof Int32);
-    }
-
-    @Test
-    public void testNestedUnionResolving1() {
-        Module testModule = TestUtils.findModule(modules, "types1");
-
-        LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("nested-union-leaf");
-
-        ExtendedType nestedUnion1 = (ExtendedType) testleaf.getType();
-        assertEquals("nested-union1", nestedUnion1.getQName().getLocalName());
-
-        ExtendedType nestedUnion2 = (ExtendedType) nestedUnion1.getBaseType();
-        assertEquals("nested-union2", nestedUnion2.getQName().getLocalName());
-
-        UnionType unionType1 = (UnionType) nestedUnion2.getBaseType();
-        List<TypeDefinition<?>> unionTypes = unionType1.getTypes();
-        assertEquals(2, unionTypes.size());
-        assertTrue(unionTypes.get(0) instanceof StringType);
-        assertTrue(unionTypes.get(1) instanceof ExtendedType);
-
-        ExtendedType extendedUnion = (ExtendedType) unionTypes.get(1);
-        ExtendedType extendedUnionBase = (ExtendedType) extendedUnion.getBaseType();
-        assertEquals("my-union", extendedUnionBase.getQName().getLocalName());
 
-        UnionType extendedTargetUnion = (UnionType) extendedUnionBase.getBaseType();
-        List<TypeDefinition<?>> extendedTargetTypes = extendedTargetUnion.getTypes();
-        assertTrue(extendedTargetTypes.get(0).getBaseType() instanceof Int16);
-        assertTrue(extendedTargetTypes.get(1) instanceof Int32);
-
-        ExtendedType int16 = (ExtendedType) extendedTargetTypes.get(0);
-        assertTrue(int16.getBaseType() instanceof Int16);
-        List<RangeConstraint> ranges = int16.getRanges();
-        assertEquals(1, ranges.size());
-        RangeConstraint range = ranges.get(0);
-        assertEquals(1L, range.getMin());
-        assertEquals(100L, range.getMax());
+        assertTrue(unionTypes.get(1) instanceof Int32);
     }
 
     @Test
-    public void testNestedUnionResolving2() {
-        Module testModule = TestUtils.findModule(modules, "types1");
-
+    public void testNestedUnionResolving() {
+        Module testModule = TestUtils.findModule(modules, "nodes");
         LeafSchemaNode testleaf = (LeafSchemaNode) testModule.getDataChildByName("custom-union-leaf");
 
-        ExtendedType testleafType = (ExtendedType) testleaf.getType();
-        QName testleafTypeQName = testleafType.getQName();
-        assertEquals(URI.create("urn:simple.container.demo.test"), testleafTypeQName.getNamespace());
-        assertEquals(TestUtils.createDate("2013-02-27"), testleafTypeQName.getRevision());
-        assertEquals("t3", testleafTypeQName.getPrefix());
+        ExtendedType type = (ExtendedType) testleaf.getType();
+        QName testleafTypeQName = type.getQName();
+        assertEquals(customNS, testleafTypeQName.getNamespace());
+        assertEquals(customRev, testleafTypeQName.getRevision());
+        assertEquals("c", testleafTypeQName.getPrefix());
         assertEquals("union1", testleafTypeQName.getLocalName());
+        assertNull(type.getUnits());
+        assertNull(type.getDefaultValue());
+        assertNull(type.getFractionDigits());
+        assertTrue(type.getLengths().isEmpty());
+        assertTrue(type.getPatterns().isEmpty());
+        assertTrue(type.getRanges().isEmpty());
 
-        ExtendedType union2 = (ExtendedType) testleafType.getBaseType();
-        QName union2QName = union2.getQName();
-        assertEquals(URI.create("urn:simple.container.demo.test"), union2QName.getNamespace());
-        assertEquals(TestUtils.createDate("2013-02-27"), union2QName.getRevision());
-        assertEquals("t3", union2QName.getPrefix());
-        assertEquals("union2", union2QName.getLocalName());
+        ExtendedType typeBase = (ExtendedType) type.getBaseType();
+        QName typeBaseQName = typeBase.getQName();
+        assertEquals(customNS, typeBaseQName.getNamespace());
+        assertEquals(customRev, typeBaseQName.getRevision());
+        assertEquals("c", typeBaseQName.getPrefix());
+        assertEquals("union2", typeBaseQName.getLocalName());
+        assertNull(typeBase.getUnits());
+        assertNull(typeBase.getDefaultValue());
+        assertNull(typeBase.getFractionDigits());
+        assertTrue(typeBase.getLengths().isEmpty());
+        assertTrue(typeBase.getPatterns().isEmpty());
+        assertTrue(typeBase.getRanges().isEmpty());
 
-        UnionType union2Base = (UnionType) union2.getBaseType();
-        List<TypeDefinition<?>> unionTypes = union2Base.getTypes();
+        UnionType union = (UnionType) typeBase.getBaseType();
+        List<TypeDefinition<?>> unionTypes = union.getTypes();
         assertEquals(2, unionTypes.size());
         assertTrue(unionTypes.get(0) instanceof Int32);
         assertTrue(unionTypes.get(1) instanceof ExtendedType);
 
-        ExtendedType nestedUnion2 = (ExtendedType) unionTypes.get(1);
-        QName nestedUnion2QName = nestedUnion2.getQName();
-        assertEquals(URI.create("urn:simple.types.data.demo"), nestedUnion2QName.getNamespace());
-        assertEquals(TestUtils.createDate("2013-02-27"), nestedUnion2QName.getRevision());
-        assertEquals("t2", nestedUnion2QName.getPrefix());
-        assertEquals("nested-union2", nestedUnion2QName.getLocalName());
-
-        UnionType nestedUnion2Base = (UnionType) nestedUnion2.getBaseType();
-        List<TypeDefinition<?>> nestedUnion2Types = nestedUnion2Base.getTypes();
+        ExtendedType unionType1 = (ExtendedType) unionTypes.get(1);
+        QName uniontType1QName = unionType1.getQName();
+        assertEquals(typesNS, uniontType1QName.getNamespace());
+        assertEquals(typesRev, uniontType1QName.getRevision());
+        assertEquals("t", uniontType1QName.getPrefix());
+        assertEquals("nested-union2", uniontType1QName.getLocalName());
+        assertNull(unionType1.getUnits());
+        assertNull(unionType1.getDefaultValue());
+        assertNull(unionType1.getFractionDigits());
+        assertTrue(unionType1.getLengths().isEmpty());
+        assertTrue(unionType1.getPatterns().isEmpty());
+        assertTrue(unionType1.getRanges().isEmpty());
+
+        UnionType nestedUnion = (UnionType) unionType1.getBaseType();
+        List<TypeDefinition<?>> nestedUnion2Types = nestedUnion.getTypes();
         assertEquals(2, nestedUnion2Types.size());
         assertTrue(nestedUnion2Types.get(0) instanceof StringType);
         assertTrue(nestedUnion2Types.get(1) instanceof ExtendedType);
 
         ExtendedType myUnionExt = (ExtendedType) nestedUnion2Types.get(1);
         QName myUnionExtQName = myUnionExt.getQName();
-        assertEquals(URI.create("urn:simple.types.data.demo"), myUnionExtQName.getNamespace());
-        assertEquals(TestUtils.createDate("2013-02-27"), myUnionExtQName.getRevision());
-        assertEquals("t2", myUnionExtQName.getPrefix());
+        assertEquals(typesNS, myUnionExtQName.getNamespace());
+        assertEquals(typesRev, myUnionExtQName.getRevision());
+        assertEquals("t", myUnionExtQName.getPrefix());
         assertEquals("my-union-ext", myUnionExtQName.getLocalName());
+        assertNull(myUnionExt.getUnits());
+        assertNull(myUnionExt.getDefaultValue());
+        assertNull(myUnionExt.getFractionDigits());
+        assertTrue(myUnionExt.getLengths().isEmpty());
+        assertTrue(myUnionExt.getPatterns().isEmpty());
+        assertTrue(myUnionExt.getRanges().isEmpty());
 
         ExtendedType myUnion = (ExtendedType) myUnionExt.getBaseType();
         QName myUnionQName = myUnion.getQName();
-        assertEquals(URI.create("urn:simple.types.data.demo"), myUnionQName.getNamespace());
-        assertEquals(TestUtils.createDate("2013-02-27"), myUnionQName.getRevision());
-        assertEquals("t2", myUnionQName.getPrefix());
+        assertEquals(typesNS, myUnionQName.getNamespace());
+        assertEquals(typesRev, myUnionQName.getRevision());
+        assertEquals("t", myUnionQName.getPrefix());
         assertEquals("my-union", myUnionQName.getLocalName());
+        assertNull(myUnion.getUnits());
+        assertNull(myUnion.getDefaultValue());
+        assertNull(myUnion.getFractionDigits());
+        assertTrue(myUnion.getLengths().isEmpty());
+        assertTrue(myUnion.getPatterns().isEmpty());
+        assertTrue(myUnion.getRanges().isEmpty());
 
         UnionType myUnionBase = (UnionType) myUnion.getBaseType();
         List<TypeDefinition<?>> myUnionBaseTypes = myUnionBase.getTypes();
         assertEquals(2, myUnionBaseTypes.size());
-        assertTrue(myUnionBaseTypes.get(0).getBaseType() instanceof Int16);
+        assertTrue(myUnionBaseTypes.get(0) instanceof ExtendedType);
         assertTrue(myUnionBaseTypes.get(1) instanceof Int32);
-        ExtendedType int16 = (ExtendedType) myUnionBaseTypes.get(0);
-        List<RangeConstraint> ranges = int16.getRanges();
+
+        ExtendedType int16Ext = (ExtendedType) myUnionBaseTypes.get(0);
+        QName int16ExtQName = int16Ext.getQName();
+        assertEquals(typesNS, int16ExtQName.getNamespace());
+        assertEquals(typesRev, int16ExtQName.getRevision());
+        assertEquals("t", int16ExtQName.getPrefix());
+        assertEquals("int16", int16ExtQName.getLocalName());
+        assertNull(int16Ext.getUnits());
+        assertNull(int16Ext.getDefaultValue());
+        assertNull(int16Ext.getFractionDigits());
+        assertTrue(int16Ext.getLengths().isEmpty());
+        assertTrue(int16Ext.getPatterns().isEmpty());
+        List<RangeConstraint> ranges = int16Ext.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
         assertEquals(1L, range.getMin());
         assertEquals(100L, range.getMax());
+
+        assertTrue(int16Ext.getBaseType() instanceof Int16);
     }
 
     @Test
     public void testChoice() {
-        Module testModule = TestUtils.findModule(modules, "types1");
-        ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
-        ChoiceNode how = (ChoiceNode) peer.getDataChildByName("how");
+        Module testModule = TestUtils.findModule(modules, "nodes");
+        ContainerSchemaNode transfer = (ContainerSchemaNode) testModule.getDataChildByName("transfer");
+        ChoiceNode how = (ChoiceNode) transfer.getDataChildByName("how");
         Set<ChoiceCaseNode> cases = how.getCases();
         assertEquals(5, cases.size());
         ChoiceCaseNode input = null;
@@ -637,26 +687,52 @@ public class YangParserTest {
 
     @Test
     public void testAnyXml() {
-        Module testModule = TestUtils.findModule(modules, "types1");
+        Module testModule = TestUtils.findModule(modules, "nodes");
         AnyXmlSchemaNode data = (AnyXmlSchemaNode) testModule.getDataChildByName("data");
-        assertNotNull(data);
+        assertNotNull("anyxml data not found", data);
+
+        // test SchemaNode args
+        QName qname = data.getQName();
+        assertEquals("data", qname.getLocalName());
+        assertEquals("n", qname.getPrefix());
+        assertEquals(nodesNS, qname.getNamespace());
+        assertEquals(nodesRev, qname.getRevision());
+        assertTrue(data.getDescription().contains("Copy of the source typesstore subset that matched"));
+        assertNull(data.getReference());
+        assertEquals(Status.OBSOLETE, data.getStatus());
+        assertEquals(0, data.getUnknownSchemaNodes().size());
+        // test DataSchemaNode args
+        assertFalse(data.isAugmenting());
+        assertTrue(data.isConfiguration());
+        ConstraintDefinition constraints = data.getConstraints();
+        assertNull(constraints.getWhenCondition());
+        assertEquals(0, constraints.getMustConstraints().size());
+        assertFalse(constraints.isMandatory());
+        assertNull(constraints.getMinElements());
+        assertNull(constraints.getMaxElements());
     }
 
     @Test
     public void testDeviation() {
-        Module testModule = TestUtils.findModule(modules, "types1");
+        Module testModule = TestUtils.findModule(modules, "nodes");
         Set<Deviation> deviations = testModule.getDeviations();
         assertEquals(1, deviations.size());
-
         Deviation dev = deviations.iterator().next();
-        SchemaPath expectedPath = TestUtils.createPath(true, null, null, "data", "system", "user");
+
+        assertEquals("system/user ref", dev.getReference());
+
+        List<QName> path = new ArrayList<QName>();
+        path.add(new QName(typesNS, typesRev, "t", "interfaces"));
+        path.add(new QName(typesNS, typesRev, "t", "ifEntry"));
+        SchemaPath expectedPath = new SchemaPath(path, true);
+
         assertEquals(expectedPath, dev.getTargetPath());
         assertEquals(Deviate.ADD, dev.getDeviate());
     }
 
     @Test
     public void testUnknownNode() {
-        Module testModule = TestUtils.findModule(modules, "types3");
+        Module testModule = TestUtils.findModule(modules, "custom");
         ContainerSchemaNode network = (ContainerSchemaNode) testModule.getDataChildByName("network");
         List<UnknownSchemaNode> unknownNodes = network.getUnknownSchemaNodes();
         assertEquals(1, unknownNodes.size());
@@ -667,37 +743,34 @@ public class YangParserTest {
 
     @Test
     public void testFeature() {
-        Module testModule = TestUtils.findModule(modules, "types3");
+        Module testModule = TestUtils.findModule(modules, "custom");
         Set<FeatureDefinition> features = testModule.getFeatures();
         assertEquals(1, features.size());
     }
 
     @Test
     public void testExtension() {
-        Module testModule = TestUtils.findModule(modules, "types3");
+        Module testModule = TestUtils.findModule(modules, "custom");
         List<ExtensionDefinition> extensions = testModule.getExtensionSchemaNodes();
         assertEquals(1, extensions.size());
         ExtensionDefinition extension = extensions.get(0);
         assertEquals("name", extension.getArgument());
-        assertFalse(extension.isYinElement());
+        assertTrue(extension.isYinElement());
     }
 
     @Test
     public void testNotification() {
-        Module testModule = TestUtils.findModule(modules, "types3");
-        URI expectedNamespace = URI.create("urn:simple.container.demo.test");
-        String expectedPrefix = "t3";
-        Date expectedRevision = TestUtils.createDate("2013-02-27");
+        Module testModule = TestUtils.findModule(modules, "custom");
+        String expectedPrefix = "c";
 
         Set<NotificationDefinition> notifications = testModule.getNotifications();
         assertEquals(1, notifications.size());
 
         NotificationDefinition notification = notifications.iterator().next();
         // test SchemaNode args
-        QName expectedQName = new QName(expectedNamespace, expectedRevision, expectedPrefix, "event");
+        QName expectedQName = new QName(customNS, customRev, expectedPrefix, "event");
         assertEquals(expectedQName, notification.getQName());
-        SchemaPath expectedPath = TestUtils.createPath(true, expectedNamespace, expectedRevision, expectedPrefix,
-                "event");
+        SchemaPath expectedPath = TestUtils.createPath(true, customNS, customRev, expectedPrefix, "event");
         assertEquals(expectedPath, notification.getPath());
         assertNull(notification.getDescription());
         assertNull(notification.getReference());
@@ -719,7 +792,7 @@ public class YangParserTest {
 
     @Test
     public void testRpc() {
-        Module testModule = TestUtils.findModule(modules, "types3");
+        Module testModule = TestUtils.findModule(modules, "custom");
 
         Set<RpcDefinition> rpcs = testModule.getRpcs();
         assertEquals(1, rpcs.size());
@@ -735,66 +808,19 @@ public class YangParserTest {
         assertNotNull(output.getDataChildByName("data"));
     }
 
-    @Test
-    public void testAugmentNodesTypesSchemaPath() throws Exception {
-        Module testModule = TestUtils.findModule(modules, "types1");
-        Set<AugmentationSchema> augments = testModule.getAugmentations();
-        assertEquals(1, augments.size());
-        AugmentationSchema augment = augments.iterator().next();
-
-        LeafSchemaNode ifcId = (LeafSchemaNode) augment.getDataChildByName("interface-id");
-        Leafref ifcIdType = (Leafref) ifcId.getType();
-        SchemaPath ifcIdTypeSchemaPath = ifcIdType.getPath();
-        List<QName> ifcIdTypePath = ifcIdTypeSchemaPath.getPath();
-
-        URI types1URI = URI.create("urn:simple.container.demo");
-        URI types2URI = URI.create("urn:simple.types.data.demo");
-        URI types3URI = URI.create("urn:simple.container.demo.test");
-        Date expectedDate = simpleDateFormat.parse("2013-02-27");
-
-        QName q0 = new QName(types2URI, expectedDate, "data", "interfaces");
-        QName q1 = new QName(types2URI, expectedDate, "data", "ifEntry");
-        QName q2 = new QName(types3URI, expectedDate, "data", "augment-holder");
-        QName q3 = new QName(types1URI, expectedDate, "data", "interface-id");
-        assertEquals(q0, ifcIdTypePath.get(0));
-        assertEquals(q1, ifcIdTypePath.get(1));
-        assertEquals(q2, ifcIdTypePath.get(2));
-        assertEquals(q3, ifcIdTypePath.get(3));
-
-        LeafListSchemaNode higherLayer = (LeafListSchemaNode) augment.getDataChildByName("higher-layer-if");
-        Leafref higherLayerType = (Leafref) higherLayer.getType();
-        SchemaPath higherLayerTypeSchemaPath = higherLayerType.getPath();
-        List<QName> higherLayerTypePath = higherLayerTypeSchemaPath.getPath();
-        assertEquals(q0, higherLayerTypePath.get(0));
-        assertEquals(q1, higherLayerTypePath.get(1));
-        assertEquals(q2, higherLayerTypePath.get(2));
-        q3 = new QName(types1URI, expectedDate, "data", "higher-layer-if");
-        assertEquals(q3, higherLayerTypePath.get(3));
-
-        LeafSchemaNode myType = (LeafSchemaNode) augment.getDataChildByName("my-type");
-        ExtendedType leafType = (ExtendedType) myType.getType();
-
-        testModule = TestUtils.findModule(modules, "types2");
-        TypeDefinition<?> typedef = TestUtils.findTypedef(testModule.getTypeDefinitions(), "my-type1");
-
-        assertEquals(typedef, leafType);
-    }
-
     @Test
     public void testTypePath() throws ParseException {
-        Module test = TestUtils.findModule(modules, "types2");
+        Module test = TestUtils.findModule(modules, "types");
         Set<TypeDefinition<?>> types = test.getTypeDefinitions();
 
         // my-base-int32-type
-        ExtendedType int32Typedef = (ExtendedType) TestUtils.findTypedef(types, "my-base-int32-type");
+        ExtendedType int32Typedef = (ExtendedType) TestUtils.findTypedef(types, "int32-ext1");
         QName int32TypedefQName = int32Typedef.getQName();
 
-        URI expectedNS = URI.create("urn:simple.types.data.demo");
-        Date expectedDate = simpleDateFormat.parse("2013-02-27");
-        assertEquals(expectedNS, int32TypedefQName.getNamespace());
-        assertEquals(expectedDate, int32TypedefQName.getRevision());
-        assertEquals("t2", int32TypedefQName.getPrefix());
-        assertEquals("my-base-int32-type", int32TypedefQName.getLocalName());
+        assertEquals(typesNS, int32TypedefQName.getNamespace());
+        assertEquals(typesRev, int32TypedefQName.getRevision());
+        assertEquals("t", int32TypedefQName.getPrefix());
+        assertEquals("int32-ext1", int32TypedefQName.getLocalName());
 
         SchemaPath typeSchemaPath = int32Typedef.getPath();
         List<QName> typePath = typeSchemaPath.getPath();
@@ -818,18 +844,16 @@ public class YangParserTest {
 
     @Test
     public void testTypePath2() throws ParseException {
-        Module test = TestUtils.findModule(modules, "types2");
+        Module test = TestUtils.findModule(modules, "types");
         Set<TypeDefinition<?>> types = test.getTypeDefinitions();
 
         // my-base-int32-type
         ExtendedType myDecType = (ExtendedType) TestUtils.findTypedef(types, "my-decimal-type");
         QName myDecTypeQName = myDecType.getQName();
 
-        URI expectedNS = URI.create("urn:simple.types.data.demo");
-        Date expectedDate = simpleDateFormat.parse("2013-02-27");
-        assertEquals(expectedNS, myDecTypeQName.getNamespace());
-        assertEquals(expectedDate, myDecTypeQName.getRevision());
-        assertEquals("t2", myDecTypeQName.getPrefix());
+        assertEquals(typesNS, myDecTypeQName.getNamespace());
+        assertEquals(typesRev, myDecTypeQName.getRevision());
+        assertEquals("t", myDecTypeQName.getPrefix());
         assertEquals("my-decimal-type", myDecTypeQName.getLocalName());
 
         SchemaPath typeSchemaPath = myDecType.getPath();
index be7b7ef7aa6974864cbad524fd97760ed36c55ec..f029a33f024e8a8a63890f3a91f8c514f2b4235d 100644 (file)
@@ -15,6 +15,7 @@ import java.net.URI;
 import java.text.DateFormat;
 import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -25,6 +26,8 @@ import org.opendaylight.controller.yang.model.api.AnyXmlSchemaNode;
 import org.opendaylight.controller.yang.model.api.ChoiceNode;
 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
+import org.opendaylight.controller.yang.model.api.Deviation;
+import org.opendaylight.controller.yang.model.api.Deviation.Deviate;
 import org.opendaylight.controller.yang.model.api.GroupingDefinition;
 import org.opendaylight.controller.yang.model.api.IdentitySchemaNode;
 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
@@ -77,7 +80,7 @@ public class YangParserWithContextTest {
         assertEquals("inet", qname.getPrefix());
         assertEquals("port-number", qname.getLocalName());
 
-        ExtendedType dscpExt = (ExtendedType)TestUtils.findTypedef(module.getTypeDefinitions(), "dscp-ext");
+        ExtendedType dscpExt = (ExtendedType) TestUtils.findTypedef(module.getTypeDefinitions(), "dscp-ext");
         List<RangeConstraint> ranges = dscpExt.getRanges();
         assertEquals(1, ranges.size());
         RangeConstraint range = ranges.get(0);
@@ -88,8 +91,10 @@ public class YangParserWithContextTest {
     @Test
     public void testUsesFromContext() throws Exception {
         SchemaContext context = null;
-        try (InputStream stream = new FileInputStream(getClass().getResource("/model/testfile2.yang").getPath())) {
-            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+        try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/custom.yang").getPath());
+                InputStream stream2 = new FileInputStream(getClass().getResource("/model/types.yang").getPath());
+                InputStream stream3 = new FileInputStream(getClass().getResource("/model/nodes.yang").getPath())) {
+            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3)));
         }
         Module testModule = null;
         try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) {
@@ -101,62 +106,62 @@ public class YangParserWithContextTest {
         // suffix _g = defined in grouping from context
 
         // get grouping
-        Module contextModule = context.findModuleByNamespace(URI.create("urn:simple.types.data.demo"));
+        Module contextModule = context.findModuleByNamespace(URI.create("urn:custom.nodes.test"));
         assertNotNull(contextModule);
         Set<GroupingDefinition> groupings = contextModule.getGroupings();
         assertEquals(1, groupings.size());
         GroupingDefinition grouping = groupings.iterator().next();
 
         // get node containing uses
-        ContainerSchemaNode peer = (ContainerSchemaNode)testModule.getDataChildByName("peer");
-        ContainerSchemaNode destination = (ContainerSchemaNode)peer.getDataChildByName("destination");
+        ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName("peer");
+        ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName("destination");
 
         // check uses
         Set<UsesNode> uses = destination.getUses();
         assertEquals(1, uses.size());
 
         // check uses process
-        AnyXmlSchemaNode data_u = (AnyXmlSchemaNode)destination.getDataChildByName("data");
+        AnyXmlSchemaNode data_u = (AnyXmlSchemaNode) destination.getDataChildByName("data");
         assertNotNull(data_u);
         assertTrue(data_u.isAddedByUses());
 
-        AnyXmlSchemaNode data_g = (AnyXmlSchemaNode)grouping.getDataChildByName("data");
+        AnyXmlSchemaNode data_g = (AnyXmlSchemaNode) grouping.getDataChildByName("data");
         assertNotNull(data_g);
         assertFalse(data_g.isAddedByUses());
         assertFalse(data_u.equals(data_g));
 
-        ChoiceNode how_u = (ChoiceNode)destination.getDataChildByName("how");
+        ChoiceNode how_u = (ChoiceNode) destination.getDataChildByName("how");
         assertNotNull(how_u);
         assertTrue(how_u.isAddedByUses());
 
-        ChoiceNode how_g = (ChoiceNode)grouping.getDataChildByName("how");
+        ChoiceNode how_g = (ChoiceNode) grouping.getDataChildByName("how");
         assertNotNull(how_g);
         assertFalse(how_g.isAddedByUses());
         assertFalse(how_u.equals(how_g));
 
-        LeafSchemaNode address_u = (LeafSchemaNode)destination.getDataChildByName("address");
+        LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName("address");
         assertNotNull(address_u);
         assertTrue(address_u.isAddedByUses());
 
-        LeafSchemaNode address_g = (LeafSchemaNode)grouping.getDataChildByName("address");
+        LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName("address");
         assertNotNull(address_g);
         assertFalse(address_g.isAddedByUses());
         assertFalse(address_u.equals(address_g));
 
-        ContainerSchemaNode port_u = (ContainerSchemaNode)destination.getDataChildByName("port");
+        ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName("port");
         assertNotNull(port_u);
         assertTrue(port_u.isAddedByUses());
 
-        ContainerSchemaNode port_g = (ContainerSchemaNode)grouping.getDataChildByName("port");
+        ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName("port");
         assertNotNull(port_g);
         assertFalse(port_g.isAddedByUses());
         assertFalse(port_u.equals(port_g));
 
-        ListSchemaNode addresses_u = (ListSchemaNode)destination.getDataChildByName("addresses");
+        ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName("addresses");
         assertNotNull(addresses_u);
         assertTrue(addresses_u.isAddedByUses());
 
-        ListSchemaNode addresses_g = (ListSchemaNode)grouping.getDataChildByName("addresses");
+        ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName("addresses");
         assertNotNull(addresses_g);
         assertFalse(addresses_g.isAddedByUses());
         assertFalse(addresses_u.equals(addresses_g));
@@ -189,8 +194,10 @@ public class YangParserWithContextTest {
     @Test
     public void testUsesRefineFromContext() throws Exception {
         SchemaContext context = null;
-        try (InputStream stream = new FileInputStream(getClass().getResource("/model/testfile2.yang").getPath())) {
-            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+        try (InputStream stream1 = new FileInputStream(getClass().getResource("/model/custom.yang").getPath());
+                InputStream stream2 = new FileInputStream(getClass().getResource("/model/types.yang").getPath());
+                InputStream stream3 = new FileInputStream(getClass().getResource("/model/nodes.yang").getPath())) {
+            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream1, stream2, stream3)));
         }
         Module module = null;
         try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/test2.yang").getPath())) {
@@ -206,7 +213,7 @@ public class YangParserWithContextTest {
 
         // test grouping path
         List<QName> path = new ArrayList<QName>();
-        QName qname = new QName(URI.create("urn:simple.types.data.demo"), simpleDateFormat.parse("2013-02-27"), "t2",
+        QName qname = new QName(URI.create("urn:custom.nodes.test"), simpleDateFormat.parse("2013-02-27"), "c",
                 "target");
         path.add(qname);
         SchemaPath expectedPath = new SchemaPath(path, true);
@@ -314,7 +321,8 @@ public class YangParserWithContextTest {
     @Test
     public void testUnknownNodes() throws Exception {
         SchemaContext context = null;
-        try (InputStream stream = new FileInputStream(getClass().getResource("/types/custom-types-test@2012-4-4.yang").getPath())) {
+        try (InputStream stream = new FileInputStream(getClass().getResource("/types/custom-types-test@2012-4-4.yang")
+                .getPath())) {
             context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
         }
 
@@ -382,4 +390,43 @@ public class YangParserWithContextTest {
         assertTrue(ifEntry == ifEntryAfterAugment);
     }
 
+    @Test
+    public void testDeviation() throws Exception {
+        // load first module
+        SchemaContext context = null;
+        String resource = "/model/types.yang";
+
+        try (InputStream stream = new FileInputStream(getClass().getResource(resource).getPath())) {
+            context = parser.resolveSchemaContext(TestUtils.loadModules(Lists.newArrayList(stream)));
+        }
+
+        // load another modules and parse them against already existing context
+        Set<Module> modules = null;
+        try (InputStream stream = new FileInputStream(getClass().getResource("/context-test/deviation-test.yang")
+                .getPath())) {
+            List<InputStream> input = Lists.newArrayList(stream);
+            modules = TestUtils.loadModulesWithContext(input, context);
+        }
+        assertNotNull(modules);
+
+        // test deviation
+        Module testModule = TestUtils.findModule(modules, "deviation-test");
+        Set<Deviation> deviations = testModule.getDeviations();
+        assertEquals(1, deviations.size());
+        Deviation dev = deviations.iterator().next();
+
+        assertEquals("system/user ref", dev.getReference());
+
+        URI expectedNS = URI.create("urn:simple.types.test");
+        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+        Date expectedRev = simpleDateFormat.parse("2013-07-03");
+        List<QName> path = new ArrayList<QName>();
+        path.add(new QName(expectedNS, expectedRev, "t", "interfaces"));
+        path.add(new QName(expectedNS, expectedRev, "t", "ifEntry"));
+        SchemaPath expectedPath = new SchemaPath(path, true);
+
+        assertEquals(expectedPath, dev.getTargetPath());
+        assertEquals(Deviate.ADD, dev.getDeviate());
+    }
+
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/context-test/deviation-test.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/context-test/deviation-test.yang
new file mode 100644 (file)
index 0000000..eafcb56
--- /dev/null
@@ -0,0 +1,27 @@
+module deviation-test {
+    yang-version 1;
+    namespace "urn:simple.deviation.test";
+    prefix "dev";
+
+    import types {
+        prefix "t";
+        revision-date 2013-07-03;
+    }
+
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+
+    revision "2013-02-27" {
+        reference " WILL BE DEFINED LATER";
+    }
+
+
+    deviation /t:interfaces/t:ifEntry {
+        deviate add {
+            default "admin"; // new users are 'admin' by default
+            config "true";
+        }
+        reference "system/user ref";
+    }
+
+}
index 74704d5c22ae0afbdc8377f2448c72776939002a..4cff19259e4de0767545f66f13facbee592b6c14 100644 (file)
@@ -4,7 +4,7 @@ module test2 {
     namespace "urn:simple.demo.test2";
     prefix "t2";
 
-    import types2 {
+    import custom {
         prefix "data";
     }
 
similarity index 63%
rename from opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile3.yang
rename to opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/custom.yang
index c507da55e521612178a2bde2aa9f01fbb5b21b4c..d8d6054b597b6e7a43d7cb34e194d0f479fa6880 100644 (file)
@@ -1,11 +1,11 @@
-module types3 {
+module custom {
     yang-version 1;
-    namespace "urn:simple.container.demo.test";
-    prefix "t3";
+    namespace "urn:custom.nodes.test";
+    prefix "c";
 
-    import types2 {
-        prefix "data";
-        revision-date 2013-02-27;
+    import types {
+        prefix "types";
+        revision-date 2013-07-03;
     }
 
     organization "opendaylight";
@@ -22,25 +22,25 @@ module types3 {
     typedef union2 {
         type union {
             type int32;
-            type data:nested-union2;
+            type types:nested-union2;
         }
     }
 
-    augment "/data:interfaces/data:ifEntry" {
+    augment "/types:interfaces/types:ifEntry" {
         when "if:ifType='ds0'";
         container augment-holder {
             description "Description for augment holder";
         }
     }
 
-    augment "/data:interfaces/data:ifEntry" {
+    augment "/types:interfaces/types:ifEntry" {
         when "if:ifType='ds2'";
         container augment-holder2 {
             description "Description for augment holder";
         }
     }
 
-    augment "/data:interfaces/data:ifEntry/t3:augment-holder/t1:schemas" {
+    augment "/types:interfaces/types:ifEntry/t3:augment-holder/t1:schemas" {
         when "if:leafType='ds1'";
         leaf linkleaf {
             type binary;
@@ -68,10 +68,10 @@ module types3 {
 
     extension c-define {
         description
-            "Takes as argument a name string.
-             Makes the code generator use the given name in the
-             #define.";
-        argument "name";
+        "Takes as argument a name string. Makes the code generator use the given name in the #define.";
+        argument "name" {
+            yin-element "true";
+        }
     }
 
     notification event {
@@ -145,4 +145,61 @@ module types3 {
         }
     }
 
+    grouping target {
+        anyxml data {
+            config true;
+            description "Copy of the source datastore subset.";
+            mandatory false;
+            must "test-condition-text";
+            reference "test-no-reference";
+            status "obsolete";
+            when "test-when-text";
+        }
+        choice how {
+            description "test choice description";
+            default interval;
+            case interval {
+                leaf interval {
+                    type uint16;
+                    default 30;
+                    units minutes;
+                }
+            }
+            case daily {
+                leaf daily {
+                    type empty;
+                }
+                leaf time-of-day {
+                    type string;
+                    units 24-hour-clock;
+                    default 1am;
+                }
+            }
+        }
+        leaf address {
+            type string;
+            description "Target IP address";
+        }
+        container port {
+            description "Target port container";
+        }
+        list addresses {
+            key "id";
+            leaf id {
+                type int8;
+            }
+        }
+        grouping target-inner {
+            description "target-inner default description";
+            leaf inner-grouping-id {
+                type int8;
+            }
+        }
+        typedef group-type {
+            type types:my-decimal-type;
+        }
+
+        opendaylight;
+    }
+
 }
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/nodes.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/nodes.yang
new file mode 100644 (file)
index 0000000..e27dd0b
--- /dev/null
@@ -0,0 +1,192 @@
+module nodes {
+    yang-version 1;
+    namespace "urn:simple.nodes.test";
+    prefix "n";
+
+    import types {
+        prefix "t";
+        revision-date 2013-07-03;
+    }
+
+   import custom {
+        prefix "c";
+        revision-date 2013-02-27;
+    }
+
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+
+    revision "2013-02-27" {
+        reference " WILL BE DEFINED LATER";
+    }
+
+    leaf int32-leaf {
+        type t:int32-ext2 {
+            range "12..max";
+        }
+    }
+
+    leaf string-leaf {
+        type t:string-ext4;
+    }
+
+    leaf length-leaf {
+        type t:string-ext2 {
+            length "7..max";
+        }
+    }
+
+    leaf decimal-leaf {
+        type t:my-decimal-type {
+            fraction-digits 4;
+        }
+    }
+
+    leaf decimal-leaf2 {
+        type t:my-decimal-type;
+    }
+
+    container ext {
+        types:c-define "MY_INTERFACES";
+    }
+
+    leaf union-leaf {
+        type t:my-union-ext;
+    }
+
+    deviation /t:interfaces/t:ifEntry {
+        deviate add {
+            default "admin"; // new users are 'admin' by default
+            config "true";
+        }
+        reference "system/user ref";
+    }
+
+    leaf custom-union-leaf {
+        type c:union1;
+    }
+
+    container transfer {
+        choice how {
+            default interval;
+            container input {
+            }
+            list output {
+                leaf id {
+                    type string;
+                }
+            }
+            case interval {
+                leaf interval {
+                    type uint16;
+                    default 30;
+                    units minutes;
+                }
+            }
+            case daily {
+                leaf daily {
+                    type empty;
+                }
+                leaf time-of-day {
+                    type string;
+                    units 24-hour-clock;
+                    default 1am;
+                }
+            }
+            case manual {
+                leaf manual {
+                    type empty;
+                }
+            }
+        }
+    }
+
+    anyxml data {
+        description
+          "Copy of the source typesstore subset that matched
+           the filter criteria (if any).  An empty types container
+           indicates that the request did not produce any results.";
+        status obsolete;
+    }
+
+    augment "/t:interfaces/t:ifEntry/c:augment-holder" {
+        when "if:ifType='ds0'";
+        leaf ds0ChannelNumber {
+            type string;
+        }
+        leaf interface-id {
+            type leafref {
+                path "/if:interfaces/if:interface/if:name";
+            }
+        }
+        leaf my-type {
+            type t:int32-ext2;
+        }
+        container schemas {
+        }
+        choice odl {
+            leaf id {
+                type int8;
+            }
+            case node1 {
+                description "node1";
+            }
+            case node2 {
+                description "node2";
+            }
+            container node3 {
+                description "node3";
+            }
+        }
+    }
+
+    container mycont {
+        container innercont {
+            typedef mytype {
+                type string;
+            }
+            leaf myleaf {
+                type mytype;
+            }
+        }
+    }
+
+    container peer {
+        container destination {
+            uses c:target {
+                refine address {
+                    default "1.2.3.4";
+                    description "IP address of target node";
+                    reference "address reference added by refine";
+                    config false;
+                    mandatory true;
+                    must "ifType != 'ethernet' or " +
+                            "(ifType = 'ethernet' and ifMTU = 1500)" {
+                        error-message "An ethernet MTU must be 1500";
+                    }
+                }
+                refine port {
+                    description "description of port defined by refine";
+                    reference "port reference added by refine";
+                    config false;
+                    presence "presence is required";
+                }
+                refine addresses {
+                    description "description of addresses defined by refine";
+                    reference "addresses reference added by refine";
+                    config false;
+                    min-elements 2;
+                    max-elements 12;
+                }
+                refine target-inner {
+                    description "new target-inner grouping description";
+                }
+                refine group-type {
+                    description "new group-type description";
+                    reference "new group-type reference";
+                }
+            }
+        }
+    }
+
+}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile1.yang
deleted file mode 100644 (file)
index 47e6491..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-module types1 {
-    yang-version 1;
-    namespace "urn:simple.container.demo";
-    prefix "t1";
-
-    import types2 {
-        prefix "data";
-        revision-date 2013-02-27;
-    }
-
-   import types3 {
-        prefix "t3";
-        revision-date 2013-02-27;
-    }
-
-    organization "opendaylight";
-    contact "http://www.opendaylight.org/";
-
-    revision "2013-02-27" {
-        reference " WILL BE DEFINED LATER";
-    }
-
-    leaf testleaf {
-        type data:my-type1 {
-            range "12..max";
-        }
-    }
-
-    leaf test-string-leaf {
-        type data:my-string-type-ext;
-    }
-
-    leaf leaf-with-length {
-        type data:my-string-type {
-            length "7..max";
-        }
-    }
-
-    leaf test-int-leaf {
-        type data:my-int-type-ext;
-    }
-
-    leaf test-decimal-leaf {
-        type data:my-decimal-type {
-            fraction-digits 4;
-        }
-    }
-
-    leaf test-decimal-leaf2 {
-        type data:my-decimal-type-ext;
-    }
-
-    container ext {
-        data:c-define "MY_INTERFACES";
-    }
-
-    leaf union-leaf {
-        type data:my-union-ext;
-    }
-
-    deviation /data:system/data:user {
-        deviate add {
-            default "admin"; // new users are 'admin' by default
-            config "true";
-        }
-    }
-
-    leaf nested-union-leaf {
-        type data:nested-union1;
-    }
-
-    leaf custom-union-leaf {
-        type t3:union1;
-    }
-
-    container transfer {
-        choice how {
-            default interval;
-            container input {
-            }
-            list output {
-                leaf id {
-                    type string;
-                }
-            }
-            case interval {
-                leaf interval {
-                    type uint16;
-                    default 30;
-                    units minutes;
-                }
-            }
-            case daily {
-                leaf daily {
-                    type empty;
-                }
-                leaf time-of-day {
-                    type string;
-                    units 24-hour-clock;
-                    default 1am;
-                }
-            }
-            case manual {
-                leaf manual {
-                    type empty;
-                }
-            }
-        }
-    }
-
-    anyxml data {
-        description
-          "Copy of the source datastore subset that matched
-           the filter criteria (if any).  An empty data container
-           indicates that the request did not produce any results.";
-    }
-
-    augment "/data:interfaces/data:ifEntry/t3:augment-holder" {
-        when "if:ifType='ds0'";
-        leaf ds0ChannelNumber {
-            type string;
-        }
-        leaf interface-id {
-            type leafref {
-                path "/if:interfaces/if:interface/if:name";
-            }
-        }
-        leaf-list higher-layer-if {
-            type leafref {
-                path "/if:interfaces/if:interface/if:higher-layer-if";
-            }
-        }
-        leaf my-type {
-            type data:my-type1;
-        }
-        container schemas {
-        }
-        choice odl {
-            leaf id {
-                type int8;
-            }
-        }
-    }
-    
-    container mycont {
-        container innercont {
-            typedef mytype {
-                type string;
-            }
-        
-            leaf myleaf {
-                type mytype;
-            }
-        }
-    }
-    
-}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/testfile2.yang
deleted file mode 100644 (file)
index b25f65e..0000000
+++ /dev/null
@@ -1,257 +0,0 @@
-module types2 {
-    yang-version 1;
-    namespace "urn:simple.types.data.demo";
-    prefix "t2";
-    
-    organization "opendaylight";
-    contact "http://www.opendaylight.org/";
-    
-    description "This is types-data test description";
-
-    revision "2013-02-27" {
-        reference " WILL BE DEFINED LATER";
-    }
-
-    typedef my-base-int32-type {
-        type int32 {
-            range "2..20";
-        }
-    }
-
-    typedef my-type1 {
-        type my-base-int32-type {
-            range "3..9|11..max";
-        }
-        units "mile";
-        default "11";
-    }
-
-    typedef my-custom-string {
-        type string {
-            pattern "[a-k]*";
-            length "5..11";
-        }
-    }
-
-    typedef my-string-type {
-        type my-custom-string {
-            length "6..10";
-        }
-    }
-    
-    typedef my-string-type2 {
-        type my-string-type {
-            pattern "[b-u]*";
-        }
-    }
-
-    typedef my-string-type-ext {
-        type my-string-type2 {
-            pattern "[e-z]*";
-        }
-    }
-
-    typedef my-int-type {
-        type int32 {
-            range "10..20";
-        }
-    }
-
-    typedef my-int-type2 {
-        type my-int-type {
-            range "12..18";
-        }
-    }
-
-    typedef my-int-type-ext {
-        type my-int-type2 {
-            range "14..16";
-        }
-    }
-
-    typedef my-decimal-type {
-        type decimal64 {
-            fraction-digits 6;
-        }
-    }
-
-    typedef my-decimal-type-ext {
-        type decimal64 {
-            fraction-digits 5;
-        }
-    }
-
-    typedef my-union {
-        type union {
-            type int16 {
-                range "1..100";
-            }
-            type int32;
-        }
-    }
-
-    typedef my-union-ext {
-        type my-union;
-    }
-
-    typedef nested-union1 {
-        type nested-union2;
-    }
-
-    typedef nested-union2 {
-        type union {
-            type my-union-ext;
-            type string;
-        }
-    }
-
-    leaf if-name {
-        type leafref {
-            path "/interface/name";
-        }
-    }
-
-    leaf name {
-        type string;
-    }
-
-    leaf count {
-        type int8 {
-            range "1..10";
-        }
-    }
-
-    leaf nested-type-leaf {
-        type my-type1;
-    }
-
-    extension c-define {
-        description
-        "Takes as argument a name string.
-        Makes the code generator use the given name in the
-        #define.";
-        argument "name" {
-            yin-element "true";
-        }
-    }
-
-    container system {
-        leaf user {
-            type string;
-        }
-    }
-
-    grouping target {
-        anyxml data {
-            config true;
-            description "Copy of the source datastore subset.";
-            mandatory false;
-            must "test-condition-text";
-            reference "test-no-reference";
-            status "obsolete";
-            when "test-when-text";
-        }
-        choice how {
-            description "test choice description";
-            default interval;
-            case interval {
-                leaf interval {
-                    type uint16;
-                    default 30;
-                    units minutes;
-                }
-            }
-            case daily {
-                leaf daily {
-                    type empty;
-                }
-                leaf time-of-day {
-                    type string;
-                    units 24-hour-clock;
-                    default 1am;
-                }
-            }
-        }
-        leaf address {
-            type string;
-            description "Target IP address";
-        }
-        container port {
-            description "Target port container";
-        }
-        list addresses {
-            key "id";
-            leaf id {
-                type int8;
-            }
-        }
-        grouping target-inner {
-            description "target-inner default description";
-            leaf inner-grouping-id {
-                type int8;
-            }
-        }
-        typedef group-type {
-            type my-decimal-type;
-        }
-
-        opendaylight;
-    }
-
-    container peer {
-        container destination {
-            uses target {
-                refine address {
-                    default "1.2.3.4";
-                    description "IP address of target node";
-                    reference "address reference added by refine";
-                    config false;
-                    mandatory true;
-                    must "ifType != 'ethernet' or " +
-                            "(ifType = 'ethernet' and ifMTU = 1500)" {
-                        error-message "An ethernet MTU must be 1500";
-                    }
-                }
-                refine port {
-                    description "description of port defined by refine";
-                    reference "port reference added by refine";
-                    config false;
-                    presence "presence is required";
-                }
-                refine addresses {
-                    description "description of addresses defined by refine";
-                    reference "addresses reference added by refine";
-                    config false;
-                    min-elements 2;
-                    max-elements 12;
-                }
-                refine target-inner {
-                    description "new target-inner grouping description";
-                }
-                refine group-type {
-                    description "new group-type description";
-                    reference "new group-type reference";
-                }
-            }
-        }
-    }
-
-    container interfaces {
-         list ifEntry {
-             key "ifIndex";
-
-             leaf ifIndex {
-                 type uint32;
-                 units minutes;
-             }
-
-             leaf ifMtu {
-                 type int32;
-             }
-
-             min-elements 1;
-             max-elements 11;
-         }
-    }
-
-}
diff --git a/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/types.yang b/opendaylight/sal/yang-prototype/code-generator/yang-model-parser-impl/src/test/resources/model/types.yang
new file mode 100644 (file)
index 0000000..d9d5064
--- /dev/null
@@ -0,0 +1,97 @@
+module types {
+    yang-version 1;
+    namespace "urn:simple.types.test";
+    prefix "t";
+    
+    organization "opendaylight";
+    contact "http://www.opendaylight.org/";
+    description "This is types-data test description";
+
+    revision "2013-07-03" {
+        reference " WILL BE DEFINED LATER";
+    }
+
+    typedef int32-ext1 {
+        type int32 {
+            range "2..20";
+        }
+    }
+
+    typedef int32-ext2 {
+        type int32-ext1 {
+            range "3..9|11..max";
+        }
+        units "mile";
+        default "11";
+    }
+
+    typedef string-ext1 {
+        type string {
+            pattern "[a-k]*";
+            length "5..11";
+        }
+    }
+
+    typedef string-ext2 {
+        type string-ext1 {
+            length "6..10";
+        }
+    }
+    
+    typedef string-ext3 {
+        type string-ext2 {
+            pattern "[b-u]*";
+        }
+    }
+
+    typedef string-ext4 {
+        type string-ext3 {
+            pattern "[e-z]*";
+        }
+    }
+
+    typedef my-decimal-type {
+        type decimal64 {
+            fraction-digits 6;
+        }
+    }
+
+    typedef my-union {
+        type union {
+            type int16 {
+                range "1..100";
+            }
+            type int32;
+        }
+    }
+
+    typedef my-union-ext {
+        type my-union;
+    }
+
+    typedef nested-union2 {
+        type union {
+            type my-union-ext;
+            type string;
+        }
+    }
+
+    container interfaces {
+         list ifEntry {
+             key "ifIndex";
+
+             leaf ifIndex {
+                 type uint32;
+                 units minutes;
+             }
+
+             leaf ifMtu {
+                 type int32;
+             }
+
+             min-elements 1;
+             max-elements 11;
+         }
+    }
+
+}
index b9729102c90b3b8d05a15f1380e5567d6663d802..6070c1c6ac563cc230dd7c9ddac921cfb9344911 100644 (file)
@@ -51,7 +51,7 @@ public class ExtendedType implements TypeDefinition<TypeDefinition<?>> {
         private List<UnknownSchemaNode> unknownSchemaNodes = Collections
                 .emptyList();
         private Status status = Status.CURRENT;
-        private String units = "";
+        private String units = null;
         private Object defaultValue = null;
         private boolean addedByUses;