Merge "Bug 584: Increase test coverage"
authorLukas Sedlak <lsedlak@cisco.com>
Wed, 22 Oct 2014 13:18:01 +0000 (13:18 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 22 Oct 2014 13:18:01 +0000 (13:18 +0000)
30 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/AbstractBaseType.java
common/features-test/src/main/java/org/opendaylight/yangtools/featuretest/SingleFeatureTest.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableAugmentationNodeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/ImmutableMapEntryNodeBuilder.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/builder/impl/valid/DataNodeContainerValidator.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueAttrNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/nodes/AbstractImmutableNormalizedValueNode.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/parser/BaseDispatcherParser.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/transform/base/parser/NodeParserDispatcher.java
yang/yang-data-operations/src/main/java/org/opendaylight/yangtools/yang/data/operations/AbstractContainerNodeModification.java
yang/yang-data-operations/src/main/java/org/opendaylight/yangtools/yang/data/operations/ChoiceNodeModification.java
yang/yang-data-operations/src/main/java/org/opendaylight/yangtools/yang/data/operations/LeafSetNodeModification.java
yang/yang-data-operations/src/main/java/org/opendaylight/yangtools/yang/data/operations/MapNodeModification.java
yang/yang-data-operations/src/main/java/org/opendaylight/yangtools/yang/data/operations/OperationStack.java
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/repo/util/FilesystemSchemaSourceCache.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleIdentifierImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/SharedSchemaContextFactory.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/AbstractBuilderTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtilsTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/LeafListSchemaNodeBuilderTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilderTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtilsTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilderTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2219Test.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/schema-context-util-test/imported-module.yang [new file with mode: 0644]
yang/yang-parser-impl/src/test/resources/schema-context-util-test/my-module.yang [new file with mode: 0644]

index 00abec0db68d4006ec7561bf4b9174ddd66ee7ab..f8abb348e60e6310a398a71eb706da4c434f4103 100644 (file)
@@ -1209,9 +1209,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
                 final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
                 if (caseChildNodes != null) {
-                    Object parentNode = null;
                     final SchemaPath nodeSp = choiceNode.getPath();
-                    parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
+                    final Object parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
 
                     SchemaNode parent;
                     if (parentNode instanceof AugmentationSchema) {
@@ -1234,14 +1233,15 @@ public class BindingGeneratorImpl implements BindingGenerator {
                         final SchemaPath sp = choiceNode.getPath();
                         parent = findDataSchemaNode(schemaContext, sp.getParent());
                     }
-                    GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
-                    if (childOfType == null) {
-                        childOfType = findGroupingByPath(parent.getPath());
+                    if (parent != null) {
+                        GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
+                        if (childOfType == null) {
+                            childOfType = findGroupingByPath(parent.getPath());
+                        }
+                        resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
                     }
-                    resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
                 }
             }
-
             processUsesAugments(caseNode, module);
         }
     }
index 735c888a0eb172f314f841ddaa93d4a42859b192..2c15ad8a36fc57737a761bc84580a9d0923da38d 100644 (file)
@@ -11,7 +11,7 @@ import org.opendaylight.yangtools.sal.binding.model.api.Type;
 
 /**
  * It is used only as ancestor for other <code>Type</code>s
- * 
+ *
  */
 public class AbstractBaseType implements Type {
 
@@ -47,7 +47,7 @@ public class AbstractBaseType implements Type {
     /**
      * Constructs the instance of this class with the concrete package name type
      * name.
-     * 
+     *
      * @param pkName
      *            string with the package name to which this <code>Type</code>
      *            belongs
@@ -82,7 +82,7 @@ public class AbstractBaseType implements Type {
         if (obj == null) {
             return false;
         }
-        if (false ==(obj instanceof Type)) {
+        if (!(obj instanceof Type)) {
             return false;
         }
         Type other = (Type) obj;
index 5f46d040c8d76703ed8fe24869982cfcc1a970d9..cdcff63960e8d08d41cfaf452c38e36cd71e5aa7 100644 (file)
@@ -11,6 +11,7 @@ import static org.opendaylight.yangtools.featuretest.Constants.ORG_OPENDAYLIGHT_
 import static org.opendaylight.yangtools.featuretest.Constants.ORG_OPENDAYLIGHT_FEATURETEST_FEATUREVERSION_PROP;
 import static org.opendaylight.yangtools.featuretest.Constants.ORG_OPENDAYLIGHT_FEATURETEST_URI_PROP;
 import static org.ops4j.pax.exam.CoreOptions.maven;
+import static org.ops4j.pax.exam.CoreOptions.vmOptions;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.configureConsole;
 import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.editConfigurationFilePut;
 //import static org.ops4j.pax.exam.karaf.options.KarafDistributionOption.debugConfiguration;
@@ -77,6 +78,7 @@ public class SingleFeatureTest {
     public Option[] config() throws IOException {
        return new Option[] {
              getKarafDistroOption(),
+             vmOptions("-Xmx2048m","-XX:MaxPermSize=512m"),
              keepRuntimeFolder(),
              configureConsole().ignoreLocalConsole(),
              logLevel(LogLevel.WARN),
index ecc0d6534fde16dfd04c8cb0d26726d84fbbf914..965528471275f934e0909f64420241d5d3910697 100644 (file)
@@ -8,7 +8,6 @@
 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
 
 import java.util.Map;
-
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -52,7 +51,7 @@ public class ImmutableAugmentationNodeBuilder extends AbstractImmutableDataConta
     public DataContainerNodeBuilder<YangInstanceIdentifier.AugmentationIdentifier, AugmentationNode> withChild(
             final DataContainerChild<?, ?> child) {
         // Check nested augments
-        DataValidationException.checkLegalData(child instanceof AugmentationNode == false,
+        DataValidationException.checkLegalData(!(child instanceof AugmentationNode),
                 "Unable to add: %s, as a child for: %s, Nested augmentations are not permitted", child.getNodeType(),
                 getNodeIdentifier() == null ? this : getNodeIdentifier());
 
index a23b070140f1cbc48c85bd50f16dacae51942178..0b1f58cd028d30d3128bfe71cc427c4adb5e5537 100644 (file)
@@ -10,7 +10,6 @@ package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@@ -83,7 +82,7 @@ public class ImmutableMapEntryNodeBuilder extends AbstractImmutableDataContainer
     @Override
     public DataContainerNodeAttrBuilder<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> withChild(final DataContainerChild<?, ?> child) {
         // Augmentation nodes cannot be keys, and do not have to be present in childrenQNamesToPaths map
-        if(isAugment(child.getIdentifier()) == false) {
+        if(!isAugment(child.getIdentifier())) {
             childrenQNamesToPaths.put(child.getNodeType(), child.getIdentifier());
         }
 
index e48f5c2592945231e6ffe0ba830ecbac53a4eb41..d2739d657f4f3644a2f24e7092849f7f72532e89 100644 (file)
@@ -7,9 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.valid;
 
-import java.util.Set;
-
+import com.google.common.base.Preconditions;
 import com.google.common.collect.Sets;
+import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -20,8 +20,6 @@ import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
-import com.google.common.base.Preconditions;
-
 /**
  * General validator for container like statements, e.g. container, list-entry, choice, augment
  */
@@ -69,7 +67,7 @@ public class DataNodeContainerValidator {
         for (DataSchemaNode childSchema : nodeContainer.getChildNodes()) {
             if(childSchema instanceof ChoiceCaseNode) {
                 allChildNodes.addAll(getChildNodes((DataNodeContainer) childSchema));
-            } else if (childSchema instanceof AugmentationSchema == false) {
+            } else if (!(childSchema instanceof AugmentationSchema)) {
                 allChildNodes.add(childSchema.getQName());
             }
         }
index acfb07c49f169d4fc268fe32d10e24ada4ed22ca..e90db03c6440ae77cee001360d6586335f0c2a2a 100644 (file)
@@ -7,15 +7,14 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
 
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.collect.ImmutableMap;
 import java.util.Map;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 
-import com.google.common.base.Objects.ToStringHelper;
-import com.google.common.collect.ImmutableMap;
-
 public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangInstanceIdentifier.PathArgument,V>
         extends AbstractImmutableNormalizedValueNode<K, V>
         implements AttributesContainer {
@@ -44,7 +43,7 @@ public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangIns
 
     @Override
     protected int valueHashCode() {
-        final int result = getValue().hashCode();
+        final int result = getValue() != null ? getValue().hashCode() : 1;
 // FIXME: are attributes part of hashCode/equals?
 //        for (final Entry<?, ?> a : attributes.entrySet()) {
 //            result = 31 * result + a.hashCode();
@@ -54,7 +53,9 @@ public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangIns
 
     @Override
     protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
-        if (!getValue().equals(other.getValue())) {
+        // We can not call directly getValue.equals because of Empty Type Definition leaves
+        // which allways have NULL value
+        if (!Objects.equal(getValue(), other.getValue())) {
             return false;
         }
 
index bd8252159ae58b9c2e898f6d0de573d34fbd40e6..ba49348df5a1092717cd1b4aa5b3941438ce7570 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
 
+import javax.annotation.Nullable;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -15,6 +16,7 @@ public abstract class AbstractImmutableNormalizedValueNode<K extends YangInstanc
         AbstractImmutableNormalizedNode<K, V> {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(AbstractImmutableNormalizedValueNode.class);
+    @Nullable
     private final V value;
 
     protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, final V value) {
index 9de1b823acaa4399266e393832c45d6a511453d7..ed458c6c65c07ab4281098b6ecbde32a50e01f9c 100644 (file)
@@ -7,11 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.data.impl.schema.transform.base.parser;
 
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.LinkedListMultimap;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -24,10 +26,6 @@ import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
 
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.LinkedListMultimap;
-
 /**
  * Abstract(base) Parser for DataContainerNodes e.g. ContainerNode, AugmentationNode.
  */
@@ -166,7 +164,7 @@ public abstract class BaseDispatcherParser<E, N extends DataContainerNode<?>, S>
     }
 
     private void checkAtLeastOneNode(S schema, Iterable<E> childNodes) {
-        Preconditions.checkArgument(Iterables.isEmpty(childNodes) == false,
+        Preconditions.checkArgument(!Iterables.isEmpty(childNodes),
                 "Node detected 0 times, should be at least 1, identified by: %s, found: %s", schema, childNodes);
     }
 }
index c316e72b02a59e3fe2a1aaf4441efca4c43cf80a..220b2cb04d4058e081bee585bc516bc0e9608319 100644 (file)
@@ -42,7 +42,7 @@ public interface NodeParserDispatcher<E> {
 
         @Override
         public final DataContainerChild<?, ?> dispatchChildElement(Object schema, List<E> childNodes) {
-            Preconditions.checkArgument(childNodes.isEmpty() == false);
+            Preconditions.checkArgument(!childNodes.isEmpty());
 
             if (schema instanceof ContainerSchemaNode) {
                 return factory.getContainerNodeParser().parse(childNodes, (ContainerSchemaNode) schema);
index ddfc69e6e7c45c945028d8b2404e71879ffca0dd..fd6b9c6ab183bc1f13ddc5f5715b331fdde67c1f 100644 (file)
@@ -7,9 +7,12 @@
  */
 package org.opendaylight.yangtools.yang.data.operations;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
 import java.util.List;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
@@ -27,11 +30,6 @@ import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
-
 abstract class AbstractContainerNodeModification<S, N extends DataContainerNode<?>> implements Modification<S, N> {
 
     @Override
@@ -80,11 +78,11 @@ abstract class AbstractContainerNodeModification<S, N extends DataContainerNode<
     private Optional<N> modifyContainer(S schema, Optional<N> actual, Optional<N> modification,
             OperationStack operationStack) throws DataModificationException {
 
-        if (actual.isPresent() == false) {
+        if (!actual.isPresent()) {
             return modification;
         }
 
-        if (modification.isPresent() == false) {
+        if (!modification.isPresent()) {
             return actual;
         }
 
index fdaf0c8f702513899a84586cac99bf2a0a25aabf..bd518fd00e35c14fa17175daf7eda2a39f4527ad 100644 (file)
@@ -7,20 +7,18 @@
  */
 package org.opendaylight.yangtools.yang.data.operations;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.Sets;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
-import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.data.impl.schema.SchemaUtils;
+import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
 import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Sets;
-
 final class ChoiceNodeModification extends
         AbstractContainerNodeModification<ChoiceNode, org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode> {
 
@@ -42,7 +40,7 @@ final class ChoiceNodeModification extends
         Set<YangInstanceIdentifier.PathArgument> childrenToProcess = super.getChildrenToProcess(schema, actual,
                 modification);
 
-        if (modification.isPresent() == false) {
+        if (!modification.isPresent()) {
             return childrenToProcess;
         }
 
@@ -51,12 +49,12 @@ final class ChoiceNodeModification extends
         for (DataContainerChild<? extends YangInstanceIdentifier.PathArgument, ?> child : modification.get().getValue()) {
             Optional<ChoiceCaseNode> detectedCaseForChild = SchemaUtils.detectCase(schema, child);
 
-            if(detectedCaseForChild.isPresent() == false) {
+            if(!detectedCaseForChild.isPresent()) {
                 DataModificationException.IllegalChoiceValuesException.throwUnknownChild(schema.getQName(),
                         child.getNodeType());
             }
 
-            if (detectedCase != null && detectedCase.equals(detectedCaseForChild.get()) == false) {
+            if (detectedCase != null && (!detectedCase.equals(detectedCaseForChild.get()))) {
                 DataModificationException.IllegalChoiceValuesException.throwMultipleCasesReferenced(schema.getQName(),
                         modification.get(), detectedCase.getQName(), detectedCaseForChild.get().getQName());
             }
@@ -72,10 +70,10 @@ final class ChoiceNodeModification extends
         for (YangInstanceIdentifier.PathArgument childToProcess : childrenToProcess) {
             // child from other cases, skip
             if (childToProcess instanceof YangInstanceIdentifier.AugmentationIdentifier
-                    && SchemaUtils.belongsToCaseAugment(detectedCase,
-                            (YangInstanceIdentifier.AugmentationIdentifier) childToProcess) == false) {
+                    && (!SchemaUtils.belongsToCaseAugment(detectedCase,
+                            (YangInstanceIdentifier.AugmentationIdentifier) childToProcess))) {
                 continue;
-            } else if (belongsToCase(detectedCase, childToProcess) == false) {
+            } else if (!belongsToCase(detectedCase, childToProcess)) {
                 continue;
             }
 
index de5a5b0e24847430574a1f664dad791db1932ac4..55327ea2a80811cbad6d8f4834fdb0a9e95168c5 100644 (file)
@@ -7,18 +7,16 @@
  */
 package org.opendaylight.yangtools.yang.data.operations;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 import java.util.List;
-
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Lists;
-
 final class LeafSetNodeModification implements Modification<LeafListSchemaNode, LeafSetNode<?>> {
 
     @Override
@@ -41,7 +39,7 @@ final class LeafSetNodeModification implements Modification<LeafListSchemaNode,
                     DataModificationException.DataExistsException.check(schema.getQName(), actual, leafListModification);
                 }
                 case REPLACE: {
-                    if (contains(actual, leafListModification) == false) {
+                    if (!contains(actual, leafListModification)) {
                         resultNodes.add(leafListModification);
                     }
                     break;
index 5a4d724ace244c4e35c53be095a4db154f269eb3..51996a8449e5c0f7a173820ed355992bb07a636e 100644 (file)
@@ -7,8 +7,9 @@
 */
 package org.opendaylight.yangtools.yang.data.operations;
 
+import com.google.common.base.Optional;
+import com.google.common.collect.Maps;
 import java.util.Map;
-
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
@@ -16,9 +17,6 @@ import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
 import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.CollectionNodeBuilder;
 import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 
-import com.google.common.base.Optional;
-import com.google.common.collect.Maps;
-
 public class MapNodeModification implements Modification<ListSchemaNode, MapNode> {
 
     public static final MapEntryNodeModification MAP_ENTRY_NODE_MODIFICATION = new MapEntryNodeModification();
@@ -28,7 +26,7 @@ public class MapNodeModification implements Modification<ListSchemaNode, MapNode
                                     Optional<MapNode> modification, OperationStack operationStack) throws DataModificationException {
 
         // Merge or None operation on parent, leaving actual if modification not present
-        if (modification.isPresent() == false)
+        if (!modification.isPresent())
             return actual;
 
         Map<YangInstanceIdentifier.NodeIdentifierWithPredicates, MapEntryNode> resultNodes = Maps.newLinkedHashMap();
index c4f890dc801bc272772b8115adb9538153547ce2..33681c08d721ec165f664848fab69f41b9564a26 100644 (file)
@@ -7,10 +7,11 @@
  */
 package org.opendaylight.yangtools.yang.data.operations;
 
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
 import java.net.URI;
 import java.util.Deque;
 import java.util.LinkedList;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
@@ -18,9 +19,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-
 /**
  * Tracks netconf operations on nested nodes.
  */
@@ -36,7 +34,7 @@ final class OperationStack {
     }
 
     public void enteringNode(Optional<? extends NormalizedNode<?, ?>> modificationNode) {
-        if (modificationNode.isPresent() == false) {
+        if (!modificationNode.isPresent()) {
             return;
         }
 
@@ -55,7 +53,7 @@ final class OperationStack {
     }
 
     private ModifyAction getOperation(NormalizedNode<?, ?> modificationNode) {
-        if (modificationNode instanceof AttributesContainer == false)
+        if (!(modificationNode instanceof AttributesContainer))
             return null;
 
         String operationString = ((AttributesContainer) modificationNode).getAttributes().get(OPERATION_NAME);
@@ -74,7 +72,7 @@ final class OperationStack {
     }
 
     public void exitingNode(Optional<? extends NormalizedNode<?, ?>> modificationNode) {
-        if (modificationNode.isPresent() == false) {
+        if (!modificationNode.isPresent()) {
             return;
         }
 
index 675a6953418fbbd8a6e969bde48c35bd7d41f03a..3478953a0607b7e02e2eb6b4646fbda0557ee1e9 100644 (file)
@@ -62,7 +62,7 @@ public final class FilesystemSchemaSourceCache<T extends SchemaSourceRepresentat
 
         checkSupportedRepresentation(representation);
 
-        if(storageDirectory.exists() == false) {
+        if(!storageDirectory.exists()) {
             Preconditions.checkArgument(storageDirectory.mkdirs(), "Unable to create cache directory at %s", storageDirectory);
         }
         Preconditions.checkArgument(storageDirectory.exists());
index 7f2c6895874690f098d5976eb1033d2db2daf0ef..6c20697ad5ae3aacad1f61e3cdc5802b388d4eb8 100644 (file)
@@ -443,10 +443,13 @@ public final class CopyUtils {
 
     private static DataBean getdata(final SchemaNodeBuilder old, final Builder newParent, final boolean updateQName) {
         final SchemaPath newSchemaPath;
+        // this check avoid NPE because if old is IdentityrefTypeBuilder, old.getQNname() return null
+        final boolean identityrefTypeCheck = old instanceof IdentityrefTypeBuilder ? false : updateQName;
+
         QName newQName = null;
         if (newParent instanceof ModuleBuilder) {
             ModuleBuilder parent = (ModuleBuilder) newParent;
-            if (updateQName) {
+            if (identityrefTypeCheck) {
                 newQName = QName.create(parent.getQNameModule(), parent.getPrefix(), old.getQName()
                         .getLocalName());
             } else {
@@ -456,7 +459,7 @@ public final class CopyUtils {
         } else if (newParent instanceof AugmentationSchemaBuilder) {
             AugmentationSchemaBuilder augment = (AugmentationSchemaBuilder) newParent;
             ModuleBuilder parent = BuilderUtils.getParentModule(newParent);
-            if (updateQName) {
+            if (identityrefTypeCheck) {
                 newQName = QName.create(parent.getQNameModule(), parent.getPrefix(), old.getQName()
                         .getLocalName());
             } else {
@@ -466,7 +469,7 @@ public final class CopyUtils {
         } else if (newParent instanceof SchemaNodeBuilder) {
             SchemaNodeBuilder parent = (SchemaNodeBuilder) newParent;
             QName parentQName = parent.getQName();
-            if (updateQName) {
+            if (identityrefTypeCheck) {
                 newQName = QName.create(parentQName, old.getQName().getLocalName());
             } else {
                 newQName = old.getQName();
index 7a2c8f1c1d203e198a9df02079ae81aa03b1f10c..5a32774036a56b0809a68863a893c9e5a8f43020 100644 (file)
@@ -10,10 +10,8 @@ package org.opendaylight.yangtools.yang.parser.builder.impl;
 import static com.google.common.base.Preconditions.checkNotNull;
 
 import com.google.common.base.Optional;
-
 import java.net.URI;
 import java.util.Date;
-
 import org.opendaylight.yangtools.yang.common.QNameModule;
 import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
 
@@ -65,7 +63,7 @@ public class ModuleIdentifierImpl implements ModuleIdentifier {
         if (this == o) {
             return true;
         }
-        if (o == null || (o instanceof ModuleIdentifier == false)) {
+        if (o == null || (!(o instanceof ModuleIdentifier))) {
             return false;
         }
 
index ebb97ee8bbf632c5601f8b69ebdbe41bc0da9047..e6e357dc0e9664f21595bf54066caea591071500 100644 (file)
@@ -190,7 +190,7 @@ final class SharedSchemaContextFactory implements SchemaContextFactory {
                 final ASTSchemaSource astSchemaSource = input.get(i);
                 final SourceIdentifier realSId = astSchemaSource.getIdentifier();
 
-                if (expectedSId.equals(realSId) == false) {
+                if (!expectedSId.equals(realSId)) {
                     LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. Using actual id", expectedSId.getName(), expectedSId, realSId);
                 }
 
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/AbstractBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/AbstractBuilderTest.java
new file mode 100644 (file)
index 0000000..9e6dca2
--- /dev/null
@@ -0,0 +1,84 @@
+package org.opendaylight.yangtools.yang.parser.builder.impl;
+
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.junit.Before;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.MustDefinitionImpl;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UsesNodeBuilder;
+
+/**
+ * Created by lukas on 10/14/14.
+ */
+public abstract class AbstractBuilderTest {
+
+    protected final static String MODULE_NAMESPACE = "urn:opendaylight.rpc:def:test-model";
+    protected final static String REVISION = "2014-10-06";
+    protected final static String MODULE_NAME = "test-module";
+    protected final static DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-mm-dd");
+    protected final static String MODULE_PATH = "test/module/path/test-module@" + REVISION + ".yang";
+
+    protected ModuleBuilder module;
+
+    @Before
+    public void setUp() throws Exception {
+        module = new ModuleBuilder(MODULE_NAME, MODULE_PATH);
+        final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(REVISION);
+        module.setRevision(moduleRevision);
+        module.setNamespace(URI.create(MODULE_NAMESPACE));
+        module.setPrefix("mod");
+    }
+
+    protected MustDefinition provideMustDefinition() {
+        return MustDefinitionImpl.create("must-condition == value",
+            Optional.fromNullable("desc"), Optional.fromNullable("reference"), Optional.fromNullable("error-apptag"),
+            Optional.fromNullable("error-message"));
+    }
+
+    protected UnknownSchemaNodeBuilder provideUnknownNodeBuilder() {
+        final QName unknownType = QName.create(module.getNamespace(), module.getRevision(), "unknown-type");
+        final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use");
+        final SchemaPath unknownNodePath = SchemaPath.create(true, unknownNode);
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(),
+            25, unknownNode, unknownNodePath);
+        unknownNodeBuilder.setNodeType(unknownType);
+        return unknownNodeBuilder;
+    }
+
+    protected UnknownSchemaNodeBuilder provideUnknownNodeBuilder(final QName innerPathSegment) {
+        final QName unknownType = QName.create(module.getNamespace(), module.getRevision(), "unknown-type");
+        final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use");
+        final SchemaPath unknownNodePath = SchemaPath.create(true, innerPathSegment, unknownNode);
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(module.getModuleName(),
+            25, unknownNode, unknownNodePath);
+        unknownNodeBuilder.setNodeType(unknownType);
+        return unknownNodeBuilder;
+    }
+
+    protected ChoiceBuilder provideChoiceBuilder(String choiceLocalName) {
+        final QName choiceName = QName.create(module.getNamespace(), module.getRevision(), choiceLocalName);
+        final SchemaPath choicePath = SchemaPath.create(true, choiceName);
+        final ChoiceBuilder choiceBuilder = new ChoiceBuilder(module.getModuleName(), 22, choiceName, choicePath);
+
+        return choiceBuilder;
+    }
+
+    protected UsesNodeBuilder provideUsesNodeBuilder(final String usesGroupingName) {
+        final QName targetQName = QName.create(module.getNamespace(), module.getRevision(), usesGroupingName);
+        return new UsesNodeBuilderImpl(module.getModuleName(), 10, SchemaPath.create(true, targetQName));
+    }
+
+    protected ContainerSchemaNodeBuilder provideContainerBuilder(final String containerLocalName) {
+        final QName containerQName = QName.create(module.getNamespace(), module.getRevision(), containerLocalName);
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+        return new ContainerSchemaNodeBuilder(module.getModuleName(), 10,
+            containerQName, containerPath);
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/BuilderUtilsTest.java
new file mode 100644 (file)
index 0000000..2ea1099
--- /dev/null
@@ -0,0 +1,474 @@
+/*
+ * 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.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.mockito.Mockito.mock;
+
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.*;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of BuilderUtils implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.BuilderUtils
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class BuilderUtilsTest {
+
+    private final static String MASTER_MODULE_NAMESPACE = "urn:opendaylight.master-model";
+    private final static String MODULES_REVISION = "2014-10-06";
+    private final static String MASTER_MODULE = "master-module";
+    private final static String DEPENDENT_MODULE_NAMESPACE = "urn:opendaylight.secondary-model";
+    private final static String DEPENDENT_MODULE = "depend-module";
+    private final static String MASTER_MODULE_PATH = "test/module/path/master-module@" + MODULES_REVISION + ".yang";
+    private final static String DEPENDENT_MODULE_PATH = "test/module/path/depend-module@" + MODULES_REVISION + ".yang";
+    private final static String DEPENDENT_MODULE_PREFIX = "dep";
+
+    private final static DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-mm-dd");
+
+    private ModuleBuilder masterModule;
+    private ModuleBuilder dependentModule;
+
+    @Before
+    public void setUp() throws Exception {
+        masterModule = new ModuleBuilder(MASTER_MODULE, MASTER_MODULE_PATH);
+        dependentModule = new ModuleBuilder(DEPENDENT_MODULE, DEPENDENT_MODULE_PATH);
+
+        final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(MODULES_REVISION);
+        masterModule.setRevision(moduleRevision);
+        dependentModule.setRevision(moduleRevision);
+
+        masterModule.setNamespace(URI.create(MASTER_MODULE_NAMESPACE));
+        dependentModule.setNamespace(URI.create(DEPENDENT_MODULE_NAMESPACE));
+
+        masterModule.setNamespace(URI.create(MASTER_MODULE_NAMESPACE));
+        dependentModule.setNamespace(URI.create(DEPENDENT_MODULE_NAMESPACE));
+
+        masterModule.setPrefix("mod");
+        dependentModule.setPrefix("mod");
+        masterModule.addModuleImport(dependentModule.getModuleName(), dependentModule.getRevision(), DEPENDENT_MODULE_PREFIX);
+    }
+
+    @Test
+    public void testFindModuleFromBuildersWithNullPrefix() throws Exception {
+        final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+
+        ModuleBuilder result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, null, 12);
+        assertEquals(masterModule, result);
+
+        result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, masterModule.getPrefix(), 12);
+        assertEquals(masterModule, result);
+
+        result = BuilderUtils.findModuleFromBuilders(testModules, masterModule, DEPENDENT_MODULE_PREFIX, 12);
+        assertEquals(dependentModule, result);
+    }
+
+    private Map<String, TreeMap<Date, ModuleBuilder>> initModuleBuildersForTest() throws Exception {
+        final Map<String, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>();
+        final String module3Name = "Module3";
+
+        ModuleBuilder module3 = new ModuleBuilder(module3Name, "test/module/path/module3.yang");
+        final Date moduleRevision = SIMPLE_DATE_FORMAT.parse(MODULES_REVISION);
+
+        module3.setRevision(moduleRevision);
+        module3.setNamespace(URI.create("urn:opendaylight.ternary-model"));
+        module3.setPrefix("mod");
+
+        dependentModule.addModuleImport(module3.getModuleName(), module3.getRevision(), "ter");
+
+        final TreeMap<Date, ModuleBuilder> module1Map = new TreeMap<>();
+        module1Map.put(masterModule.getRevision(), masterModule);
+
+        final TreeMap<Date, ModuleBuilder> module2Map = new TreeMap<>();
+        module2Map.put(dependentModule.getRevision(), dependentModule);
+
+        final TreeMap<Date, ModuleBuilder> module3Map = new TreeMap<>();
+        module3Map.put(module3.getRevision(), module3);
+
+        modules.put(masterModule.getName(), module1Map);
+        modules.put(dependentModule.getName(), module2Map);
+        modules.put(module3Name, module3Map);
+
+        return modules;
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testFindModuleFromBuildersWithNoImportedModule() throws Exception {
+        final Map<String, TreeMap<Date, ModuleBuilder>> testModules = initModuleBuildersForTest();
+
+        BuilderUtils.findModuleFromBuilders(testModules, masterModule, "eth", 12);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testFindModuleFromContextWithDependentModuleImportEqualsToNull() {
+        final SchemaContext mockContext = mock(SchemaContext.class);
+
+        BuilderUtils.findModuleFromContext(mockContext, masterModule, "inalid-prefix", 14);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testFindModuleFromContextWhereModuleIsNotPresent() {
+        final SchemaContext mockContext = mock(SchemaContext.class);
+
+        BuilderUtils.findModuleFromContext(mockContext, masterModule, DEPENDENT_MODULE_PREFIX, 14);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testFillAugmentTargetForInvalidTarget() {
+        AugmentationSchemaBuilder augBuilder = mock(AugmentationSchemaBuilder.class);
+        Builder invalidTarget = mock(Builder.class);
+        BuilderUtils.fillAugmentTarget(augBuilder, invalidTarget);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testFillAugmentTargetWithChoiceBuilderContainingInvalidUsesNodeBuilder() {
+        final QName usesQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-grouping");
+        final UsesNodeBuilder usesNodeBuilder = new UsesNodeBuilderImpl(masterModule.getModuleName(), 10, SchemaPath.create(true, usesQName));
+
+        final QName augTargetQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "target");
+        final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(masterModule.getModuleName(), 12,
+            "/target", SchemaPath.create(true, augTargetQName), 1);
+
+        augBuilder.setParent(usesNodeBuilder);
+
+        final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-choice");
+        final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 14, choiceQName,
+            SchemaPath.create(true, choiceQName));
+
+        augBuilder.addUsesNode(usesNodeBuilder);
+        BuilderUtils.fillAugmentTarget(augBuilder, choiceBuilder);
+    }
+
+    @Test
+    public void testFillAugmentTargetSetNodeAddedByUses() {
+        final QName augTargetQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "target");
+        final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(masterModule.getModuleName(), 12,
+            "/target", SchemaPath.create(true, augTargetQName), 1);
+
+        final String containerLocalName = "top-level-container";
+        final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), containerLocalName);
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        augBuilder.addChildNode(
+            new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10, containerQName, containerPath));
+
+        final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "test-choice");
+        final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 14, choiceQName,
+            SchemaPath.create(true, choiceQName));
+
+        BuilderUtils.fillAugmentTarget(augBuilder, choiceBuilder);
+
+        ChoiceCaseBuilder result = choiceBuilder.getCaseNodeByName(containerLocalName);
+        assertNotNull(result);
+    }
+
+    @Test
+    public void testFindUnknownNodeInDataNodeContainer() {
+        final String parentLocalName = "parent";
+        final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName);
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+        final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10,
+            containerQName, containerPath);
+
+        final String unknownLocalName = "unknown-ext-use";
+        final QName unknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), unknownLocalName);
+        SchemaPath unknownNodePath = SchemaPath.create(true, containerQName, unknownNode);
+        UnknownSchemaNodeBuilderImpl unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(masterModule.getModuleName(),
+            22, unknownNode, unknownNodePath);
+        containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        List<QName> path = new ArrayList<>(2);
+        path.add(unknownNode);
+
+        SchemaNodeBuilder result = BuilderUtils.findSchemaNode(path, containerBuilder);
+        assertNotNull(result);
+        assertEquals(unknownNodeBuilder, result);
+
+        path.add(QName.create(masterModule.getNamespace(), masterModule.getRevision(), "foo"));
+        assertNull(BuilderUtils.findSchemaNode(path, containerBuilder));
+
+        final QName choiceQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "select");
+        SchemaPath choicePath = SchemaPath.create(true, choiceQName);
+
+        final ChoiceBuilder choiceBuilder = new ChoiceBuilder(masterModule.getModuleName(), 33, choiceQName, choicePath);
+
+        final QName caseQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "simple-case");
+        SchemaPath casePath = SchemaPath.create(true, choiceQName, caseQName);
+
+        ChoiceCaseBuilder caseBuilder = new ChoiceCaseBuilder(masterModule.getModuleName(), 35, caseQName, casePath);
+        choiceBuilder.addCase(caseBuilder);
+
+        choiceBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        path.clear();
+        path.add(caseQName);
+        result = BuilderUtils.findSchemaNode(path, choiceBuilder);
+        assertNotNull(result);
+        assertTrue(result instanceof ChoiceCaseBuilder);
+        assertEquals(caseBuilder, result);
+
+        path.clear();
+        path.add(unknownNode);
+        result = BuilderUtils.findSchemaNode(path, choiceBuilder);
+        assertNotNull(result);
+        assertEquals(unknownNodeBuilder, result);
+
+        path.add(QName.create(masterModule.getNamespace(), masterModule.getRevision(), "foo"));
+        result = BuilderUtils.findSchemaNode(path, choiceBuilder);
+        assertNull(result);
+
+        final QName rpcQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName);
+        SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+        final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(masterModule.getModuleName(), 45, rpcQName, rpcPath);
+
+        final QName inputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "input");
+        final SchemaPath inputPath = SchemaPath.create(true, rpcQName, inputQName);
+
+        final QName outputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "output");
+        final SchemaPath outputPath = SchemaPath.create(true, rpcQName, outputQName);
+
+        final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 46,
+            inputQName, inputPath);
+        final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 76,
+            outputQName, outputPath);
+
+        rpcBuilder.setInput(inputBuilder);
+        rpcBuilder.setOutput(outputBuilder);
+        rpcBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        path.clear();
+        path.add(inputQName);
+        result = BuilderUtils.findSchemaNode(path, rpcBuilder);
+        assertNotNull(result);
+        assertEquals(inputBuilder, result);
+
+        path.clear();
+        path.add(outputQName);
+        result = BuilderUtils.findSchemaNode(path, rpcBuilder);
+        assertNotNull(result);
+        assertEquals(outputBuilder, result);
+
+        path.clear();
+        path.add(unknownNode);
+        result = BuilderUtils.findSchemaNode(path, rpcBuilder);
+        assertNotNull(result);
+        assertEquals(unknownNodeBuilder, result);
+
+        final QName leafQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "simple-leaf");
+        SchemaPath leafPath = SchemaPath.create(true, leafQName);
+
+        final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(masterModule.getModuleName(), 10, leafQName, leafPath);
+        leafBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        path.clear();
+        path.add(unknownNode);
+        result = BuilderUtils.findSchemaNode(path, leafBuilder);
+        assertNotNull(result);
+        assertEquals(unknownNodeBuilder, result);
+    }
+
+    @Test
+    public void testFindUnknownSchemaNodeInModule() {
+        final String parentLocalName = "parent";
+        final QName containerQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), parentLocalName);
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+        final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 10,
+            containerQName, containerPath);
+
+        final String unknownLocalName = "unknown-ext-use";
+        final QName unknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), unknownLocalName);
+        final SchemaPath unknownNodePath = SchemaPath.create(true, containerQName, unknownNode);
+        UnknownSchemaNodeBuilderImpl unknownNodeBuilder = new UnknownSchemaNodeBuilderImpl(masterModule.getModuleName(),
+            22, unknownNode, unknownNodePath);
+        containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        masterModule.addChildNode(containerBuilder);
+
+        Optional<SchemaNodeBuilder> result = BuilderUtils.findSchemaNodeInModule(unknownNodePath, masterModule);
+
+        assertTrue(result.isPresent());
+        assertEquals(result.get(), unknownNodeBuilder);
+
+        final QName invalidUnknownNode = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "invalid-ext-use");
+        final SchemaPath invalidPath = SchemaPath.create(true, containerQName, invalidUnknownNode);
+
+        result = BuilderUtils.findSchemaNodeInModule(invalidPath, masterModule);
+        assertFalse(result.isPresent());
+    }
+
+    @Test
+    public void testFindContainerInRPC() {
+
+        final QName rpcQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "send-message");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+        final RpcDefinitionBuilder rpcBuilder = masterModule.addRpc(45, rpcQName, rpcPath);
+
+        final QName inputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "input");
+        final SchemaPath inputPath = SchemaPath.create(true, rpcQName, inputQName);
+
+        final QName outputQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "output");
+        final SchemaPath outputPath = SchemaPath.create(true, rpcQName, outputQName);
+
+        Optional<SchemaNodeBuilder> requestResult = BuilderUtils.findSchemaNodeInModule(inputPath, masterModule);
+        assertTrue(requestResult.isPresent());
+
+        Optional<SchemaNodeBuilder> responseResult = BuilderUtils.findSchemaNodeInModule(outputPath, masterModule);
+        assertTrue(responseResult.isPresent());
+
+        final ContainerSchemaNodeBuilder inputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 46,
+            inputQName, inputPath);
+        final ContainerSchemaNodeBuilder outputBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 76,
+            outputQName, outputPath);
+
+        final QName request = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "request");
+        final SchemaPath requestPath = SchemaPath.create(true, rpcQName, inputQName, request);
+
+        final QName response = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "response");
+        final SchemaPath responsePath = SchemaPath.create(true, rpcQName, outputQName, response);
+
+        final ContainerSchemaNodeBuilder requestBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 50,
+            request, requestPath);
+        final ContainerSchemaNodeBuilder responseBuilder = new ContainerSchemaNodeBuilder(masterModule.getModuleName(), 80,
+            response, responsePath);
+
+        inputBuilder.addChildNode(requestBuilder);
+        outputBuilder.addChildNode(responseBuilder);
+
+        rpcBuilder.setInput(inputBuilder);
+        rpcBuilder.setOutput(outputBuilder);
+
+        requestResult = BuilderUtils.findSchemaNodeInModule(requestPath, masterModule);
+        assertTrue(requestResult.isPresent());
+
+        responseResult = BuilderUtils.findSchemaNodeInModule(responsePath, masterModule);
+        assertTrue(responseResult.isPresent());
+
+        final SchemaPath invalidPath = SchemaPath.create(true, rpcQName, response);
+        Optional<SchemaNodeBuilder> invalidResult = BuilderUtils.findSchemaNodeInModule(invalidPath, masterModule);
+        assertFalse(invalidResult.isPresent());
+    }
+
+    @Test
+    public void testFindIdentity() {
+        assertNull(BuilderUtils.findIdentity(Collections.<IdentitySchemaNodeBuilder>emptySet(), "test-identity"));
+    }
+
+    @Test
+    public void testGetModuleByPrefix() {
+        assertEquals(BuilderUtils.getModuleByPrefix(masterModule, null), masterModule);
+        assertEquals(BuilderUtils.getModuleByPrefix(masterModule, ""), masterModule);
+        assertEquals(BuilderUtils.getModuleByPrefix(masterModule, masterModule.getPrefix()), masterModule);
+    }
+
+    @Test
+    public void testFindModule() {
+        final Map<URI, TreeMap<Date, ModuleBuilder>> modules = new HashMap<>(1);
+        final TreeMap<Date, ModuleBuilder> masterModuleMap = new TreeMap<>();
+        masterModuleMap.put(masterModule.getRevision(), masterModule);
+        modules.put(masterModule.getNamespace(), masterModuleMap);
+
+        assertNull(BuilderUtils.findModule(QName.create("test-urn:namespace", "2014-10-08", "impossible-module"), modules));
+
+        assertEquals(BuilderUtils.findModule(QName.create(masterModule.getNamespace(), null, masterModule.getName()), modules),
+            masterModule);
+    }
+
+    @Test
+    public void testFindBaseIdentity() {
+        assertNull(BuilderUtils.findBaseIdentity(masterModule, "prefix:ident", 27));
+
+        final QName identity = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "ident");
+        masterModule.addIdentity(identity, 22, SchemaPath.create(true, identity));
+
+        final IdentitySchemaNodeBuilder result = BuilderUtils
+            .findBaseIdentity(masterModule, masterModule.getPrefix() + ":ident", 22);
+        assertNotNull(result);
+        assertEquals(result.getQName(), identity);
+    }
+
+    @Test
+    public void testWrapChildNode() {
+        final QName leafQName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "parent-leaf");
+        final SchemaPath leafPath = SchemaPath.create(true, leafQName);
+        final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(masterModule.getModuleName(),
+            27, leafQName, leafPath);
+        leafListBuilder.setType(Uint16.getInstance());
+
+        final LeafListSchemaNode leafList = leafListBuilder.build();
+
+        DataSchemaNodeBuilder wrapedLeafList = BuilderUtils
+            .wrapChildNode(masterModule.getModuleName(), 72, leafList, leafPath, leafQName);
+
+        assertNotNull(wrapedLeafList);
+        assertEquals(wrapedLeafList.getQName(), leafList.getQName());
+    }
+
+    @Test(expected = YangParseException.class)
+    public void wrapChildNodeForUnknownNode() {
+        final QName qName = QName.create(masterModule.getNamespace(), masterModule.getRevision(), "name");
+        final SchemaPath path = SchemaPath.create(true, qName);
+
+        BuilderUtils
+            .wrapChildNode(masterModule.getModuleName(), 72, new NotExistingDataSchemaNodeImpl(), path, qName);
+    }
+
+    private static class NotExistingDataSchemaNodeImpl implements DataSchemaNode {
+
+        @Override public boolean isAugmenting() {
+            return false;
+        }
+
+        @Override public boolean isAddedByUses() {
+            return false;
+        }
+
+        @Override public boolean isConfiguration() {
+            return false;
+        }
+
+        @Override public ConstraintDefinition getConstraints() {
+            return null;
+        }
+
+        @Override public QName getQName() {
+            return null;
+        }
+
+        @Override public SchemaPath getPath() {
+            return null;
+        }
+
+        @Override public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+            return null;
+        }
+
+        @Override public String getDescription() {
+            return null;
+        }
+
+        @Override public String getReference() {
+            return null;
+        }
+
+        @Override public Status getStatus() {
+            return null;
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtilsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/CopyUtilsTest.java
new file mode 100644 (file)
index 0000000..ace25d4
--- /dev/null
@@ -0,0 +1,455 @@
+/*
+ * 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.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.ExtendedType;
+import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.*;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of CopyUtils implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class CopyUtilsTest extends AbstractBuilderTest {
+
+    @Test(expected = YangParseException.class)
+    public void testCopyOfUnknownTypeOfDataSchemaNode() {
+        final String leafLocalName = "leaf-to-refine";
+        final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName);
+        final SchemaPath leafPath = SchemaPath.create(true, leafName);
+        final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath);
+
+        CopyUtils.copy(new InvalidDataSchemaNodeBuilder(), leafBuilder, false);
+    }
+
+    @Test
+    public void testCopyAnyxmlWithAnyxmlOriginalNodeAndUnknownNodes() {
+        final String parentAnyxmlLocalName = "original-anyxml";
+        final QName parentAnyxmlName = QName.create(module.getNamespace(), module.getRevision(), parentAnyxmlLocalName);
+        final SchemaPath parentAnyxmlPath = SchemaPath.create(true, parentAnyxmlName);
+        final AnyXmlBuilder parentAnyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, parentAnyxmlName, parentAnyxmlPath);
+
+        final String anyxmlLocalName = "anyxml";
+        final QName anyxmlName = QName.create(module.getNamespace(), module.getRevision(), anyxmlLocalName);
+        final SchemaPath anyxmlPath = SchemaPath.create(true, anyxmlName);
+        final AnyXmlBuilder anyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, anyxmlName, anyxmlPath);
+
+        anyXmlBuilder.setOriginal(parentAnyXmlBuilder);
+
+        final UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(anyxmlName);
+        anyXmlBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+
+        final AnyXmlBuilder copy = (AnyXmlBuilder) CopyUtils.copy(anyXmlBuilder, anyXmlBuilder, false);
+        assertFalse(copy.getUnknownNodes().isEmpty());
+        assertNotNull(copy.getOriginal());
+        assertEquals(copy.getOriginal(), parentAnyXmlBuilder);
+    }
+
+    @Test
+    public void testCopyChoiceBuilderWithUnknownNodesAndAugmentation() {
+        final String originalChoiceLocalName = "original-choice-to-copy";
+        final ChoiceBuilder originalChoiceBuilder = provideChoiceBuilder(originalChoiceLocalName);
+
+        final String choiceLocalName = "choice-to-copy";
+        final ChoiceBuilder choiceBuilder = provideChoiceBuilder(choiceLocalName);
+        choiceBuilder.setOriginal(originalChoiceBuilder);
+
+        final UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(choiceBuilder.getQName());
+        final SchemaPath augPath = SchemaPath.create(true, choiceBuilder.getQName());
+
+        final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(module.getModuleName(), 22,
+            "/imaginary/path", augPath, 0);
+
+        final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use");
+            augBuilder.addUsesNode(usesNodeBuilder);
+        augBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+
+        choiceBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+        choiceBuilder.addAugmentation(augBuilder);
+
+        final ChoiceBuilder copy = (ChoiceBuilder)CopyUtils.copy(choiceBuilder, module, false);
+        List<AugmentationSchemaBuilder> augmentations = copy.getAugmentationBuilders();
+
+        assertFalse(copy.getUnknownNodes().isEmpty());
+
+        final UnknownSchemaNodeBuilder copyUnknownNode = copy.getUnknownNodes().get(0);
+        assertEquals(copyUnknownNode, unknownSchemaNodeBuilder);
+
+        assertFalse(augmentations.isEmpty());
+        final AugmentationSchemaBuilder copyAugBuilder = augmentations.get(0);
+
+        assertEquals(copyAugBuilder, augBuilder);
+        assertEquals(copyAugBuilder.getUnknownNodes().get(0), augBuilder.getUnknownNodes().get(0));
+        assertNotEquals(copyAugBuilder.getUsesNodeBuilders().get(0), augBuilder.getUsesNodeBuilders().get(0));
+    }
+
+    @Test
+    public void testCopyChoiceCaseBuilder() {
+        final String originalChoiceCaseLocalName = "original-choice-case";
+        final QName originalChoiceCaseQName = QName.create(module.getNamespace(), module.getRevision(),
+            originalChoiceCaseLocalName);
+        final SchemaPath originalChoiceCasePath = SchemaPath.create(true, originalChoiceCaseQName);
+        final ChoiceCaseBuilder originalChoiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10,
+            originalChoiceCaseQName, originalChoiceCasePath);
+
+        final String choiceCaseLocalName = "test-choice-case";
+        final QName choiceCaseQName = QName.create(module.getNamespace(), module.getRevision(), choiceCaseLocalName);
+        final SchemaPath choiceCasePath = SchemaPath.create(true, choiceCaseQName);
+        final ChoiceCaseBuilder choiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10, choiceCaseQName,
+            choiceCasePath);
+
+        choiceCaseBuilder.setOriginal(originalChoiceCaseBuilder);
+
+        final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use");
+
+        UnknownSchemaNodeBuilder unknownSchemaNodeBuilder = provideUnknownNodeBuilder(choiceCaseQName);
+
+        choiceCaseBuilder.addUsesNode(usesNodeBuilder);
+        choiceCaseBuilder.addUnknownNodeBuilder(unknownSchemaNodeBuilder);
+
+        ChoiceCaseBuilder copy = (ChoiceCaseBuilder) CopyUtils.copy(choiceCaseBuilder, module, true);
+
+        assertNotNull(copy);
+        assertEquals(copy.getUnknownNodes().get(0), choiceCaseBuilder.getUnknownNodes().get(0));
+        assertFalse(copy.getUsesNodeBuilders().isEmpty());
+        assertNotEquals(copy.getUsesNodeBuilders().get(0), choiceCaseBuilder.getUsesNodeBuilders().get(0));
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddGroupingIntoChoiceCaseBuilder() {
+        final String choiceCaseLocalName = "test-choice-case";
+        final QName choiceCaseQName = QName.create(module.getNamespace(), module.getRevision(), choiceCaseLocalName);
+        final SchemaPath choiceCasePath = SchemaPath.create(true, choiceCaseQName);
+        final ChoiceCaseBuilder choiceCaseBuilder = new ChoiceCaseBuilder(module.getModuleName(), 10, choiceCaseQName,
+            choiceCasePath);
+
+        final String groupLocalName = "test-group";
+        final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+        final SchemaPath groupPath = SchemaPath.create(true, choiceCaseQName, testGroup);
+        final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+        choiceCaseBuilder.addGrouping(grouping);
+    }
+
+    @Test
+    public void testCopyContainerSchemaNodeBuilder() {
+        final ContainerSchemaNodeBuilder containerBuilder = provideContainerBuilder("parent-container");
+
+        final String groupLocalName = "test-group";
+        final GroupingBuilder grouping = provideNestedGroupingDefinition(containerBuilder.getQName(), groupLocalName);
+
+        final String typedefLocalName = "test-type-definition";
+        final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(containerBuilder.getQName(), typedefLocalName);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(containerBuilder.getQName());
+
+        containerBuilder.addGrouping(grouping);
+        containerBuilder.addTypedef(typedefBuilder);
+        containerBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        final ContainerSchemaNodeBuilder copy = (ContainerSchemaNodeBuilder) CopyUtils.copy(containerBuilder, module, true);
+
+        assertNotNull(copy);
+
+        assertFalse(copy.getGroupingBuilders().isEmpty());
+        assertFalse(copy.getTypeDefinitionBuilders().isEmpty());
+        assertFalse(copy.getUnknownNodes().isEmpty());
+    }
+
+    private GroupingBuilder provideNestedGroupingDefinition(final QName parentName, final String groupLocalName) {
+        final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+        final SchemaPath groupPath = SchemaPath.create(true, parentName, testGroup);
+        final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+
+        return grouping;
+    }
+
+    private TypeDefinitionBuilder provideNestedTypedef(final QName parentName, final String typedefLocalName) {
+        final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+        final SchemaPath typedefPath = SchemaPath.create(true, parentName, typedefQname);
+        final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(), 12,
+            typedefQname, typedefPath);
+        typedefBuilder.setType(Uint16.getInstance());
+
+        return typedefBuilder;
+    }
+
+    @Test
+    public void testCopyLeafSchemaNodeBuilder() {
+        final String leafLocalName = "original-leaf";
+        final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName);
+        final SchemaPath leafPath = SchemaPath.create(true, leafName);
+        final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath);
+        leafBuilder.setType(Uint16.getInstance());
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(leafName);
+        leafBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        final LeafSchemaNodeBuilder copy = (LeafSchemaNodeBuilder)CopyUtils.copy(leafBuilder, module, true);
+
+        assertNotNull(copy);
+        assertFalse(leafBuilder.getUnknownNodes().isEmpty());
+    }
+
+    @Test
+    public void testCopyLeafListSchemaNodeBuilder() {
+        final String origLeafListLocalName = "original-list-to";
+        final QName origLeafListQName = QName.create(module.getNamespace(), module.getRevision(), origLeafListLocalName );
+        final SchemaPath origLeafListPath = SchemaPath.create(true, origLeafListQName);
+        final LeafListSchemaNodeBuilder origLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            10, origLeafListQName, origLeafListPath);
+        origLeafListBuilder.setType(Uint16.getInstance());
+
+        final String leafListLocalName = "leaflist-copy";
+        final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+        final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+        final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            20, leafListQName, leafListPath);
+        leafListBuilder.setType(Uint16.getInstance());
+
+        leafListBuilder.setOriginal(origLeafListBuilder);
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(leafListQName);
+        leafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        final LeafListSchemaNodeBuilder copy = (LeafListSchemaNodeBuilder)CopyUtils.copy(leafListBuilder, module, true);
+
+        assertNotNull(copy);
+        assertFalse(copy.getUnknownNodes().isEmpty());
+        assertNotNull(copy.getUnknownNodes().get(0));
+    }
+
+    @Test
+    public void testCopyListSchemaNodeBuilder() {
+        final String origListLocalName = "original-list";
+        final QName origListQName = QName.create(module.getNamespace(), module.getRevision(), origListLocalName);
+        final SchemaPath origListPath = SchemaPath.create(true, origListQName);
+        final ListSchemaNodeBuilder origListBuilder = new ListSchemaNodeBuilder(module.getModuleName(),
+            10, origListQName, origListPath);
+
+        final String listLocalName = "copy-of-list";
+        final QName listQName = QName.create(module.getNamespace(), module.getRevision(), listLocalName);
+        final SchemaPath listPath = SchemaPath.create(true, listQName);
+        final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(module.getModuleName(),
+            20, listQName, listPath);
+
+        listBuilder.setOriginal(origListBuilder);
+
+        final String groupLocalName = "test-group";
+        final GroupingBuilder grouping = provideNestedGroupingDefinition(listBuilder.getQName(), groupLocalName);
+        listBuilder.addGrouping(grouping);
+
+        final String typedefLocalName = "test-type-definition";
+        final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(listBuilder.getQName(), typedefLocalName);
+        listBuilder.addTypedef(typedefBuilder);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(listBuilder.getQName());
+        listBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder("test-grouping-use");
+        listBuilder.addUsesNode(usesNodeBuilder);
+
+        final SchemaPath augPath = SchemaPath.create(true, listBuilder.getQName());
+        final AugmentationSchemaBuilder augBuilder = new AugmentationSchemaBuilderImpl(module.getModuleName(), 22,
+            "/imaginary/path", augPath, 0);
+        listBuilder.addAugmentation(augBuilder);
+
+        ListSchemaNodeBuilder copy = (ListSchemaNodeBuilder) CopyUtils.copy(listBuilder, module, true);
+        assertNotNull(copy);
+        assertFalse(copy.getGroupingBuilders().isEmpty());
+        assertFalse(copy.getTypeDefinitionBuilders().isEmpty());
+        assertFalse(copy.getUnknownNodes().isEmpty());
+        assertFalse(copy.getUsesNodeBuilders().isEmpty());
+        assertFalse(copy.getAugmentationBuilders().isEmpty());
+    }
+
+    @Test
+    public void testCopyGroupingBuilder() {
+        final String groupLocalName = "test-group";
+        final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+        final SchemaPath groupPath = SchemaPath.create(true, testGroup);
+        final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+
+        final String innerGroupLocalName = "inner-group";
+        final QName innerGroup = QName.create(module.getNamespace(), module.getRevision(), innerGroupLocalName);
+        final SchemaPath innerGroupPath = SchemaPath.create(true, testGroup, innerGroup);
+        final GroupingBuilder innerGrouping = module.addGrouping(12, innerGroup, innerGroupPath);
+
+        grouping.addGrouping(innerGrouping);
+
+        final String typedefLocalName = "test-type-definition";
+        final TypeDefinitionBuilder typedefBuilder = provideNestedTypedef(grouping.getQName(), typedefLocalName);
+        grouping.addTypedef(typedefBuilder);
+
+        final UsesNodeBuilder usesNodeBuilder = provideUsesNodeBuilder(innerGroupLocalName);
+        grouping.addUsesNode(usesNodeBuilder);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder(grouping.getQName());
+        grouping.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        final GroupingBuilder copy = CopyUtils.copy(grouping, module, true);
+        assertNotNull(copy);
+        assertFalse(copy.getGroupingBuilders().isEmpty());
+        assertFalse(copy.getTypeDefinitionBuilders().isEmpty());
+        assertFalse(copy.getUsesNodeBuilders().isEmpty());
+        assertFalse(copy.getUnknownNodes().isEmpty());
+    }
+
+    @Ignore
+    @Test
+    public void testCopyIdentityrefTypeBuilder() {
+        final String typedefLocalName = "identity-ref-test-type";
+        final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+        final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
+        final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(module.getModuleName(), 12,
+            "base:parent-identity", typedefPath);
+
+        //FIXME remove Ignore annotation once fix for bug 2219 will be resolved and merged
+        final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, module, true);
+        assertNotNull(copy);
+
+        //TODO: add additional asserts
+    }
+
+    @Ignore
+    @Test
+    public void testCopyTypeDefinitionBuilderWithUnknownNodes() {
+        final String typedefLocalName = "test-typedef-with-ext";
+        final QName typedefQname = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+        final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
+        final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(), 12,
+            typedefQname, typedefPath);
+        typedefBuilder.setType(Uint16.getInstance());
+
+        typedefBuilder.addUnknownNodeBuilder(provideUnknownNodeBuilder());
+
+        TypeDefinitionBuilder copy = CopyUtils.copy(typedefBuilder, module, true);
+        //FIXME: remove @Ignore annotation once bug 2220 will be resolved and merged
+        assertNotNull(copy);
+        assertFalse(copy.getUnknownNodes().isEmpty());
+    }
+
+    private static final class InvalidDataSchemaNodeBuilder implements DataSchemaNodeBuilder {
+
+        @Override public SchemaNodeBuilder getOriginal() {
+            return null;
+        }
+
+        @Override public void setOriginal(SchemaNodeBuilder original) {
+
+        }
+
+        @Override public boolean isAugmenting() {
+            return false;
+        }
+
+        @Override public void setAugmenting(boolean augmenting) {
+
+        }
+
+        @Override public boolean isConfiguration() {
+            return false;
+        }
+
+        @Override public void setConfiguration(boolean config) {
+
+        }
+
+        @Override public ConstraintsBuilder getConstraints() {
+            return null;
+        }
+
+        @Override public QName getQName() {
+            return null;
+        }
+
+        @Override public SchemaPath getPath() {
+            return null;
+        }
+
+        @Override public void setPath(SchemaPath path) {
+
+        }
+
+        @Override public String getModuleName() {
+            return null;
+        }
+
+        @Override public void setModuleName(String moduleName) {
+
+        }
+
+        @Override public int getLine() {
+            return 0;
+        }
+
+        @Override public Builder getParent() {
+            return null;
+        }
+
+        @Override public void setParent(Builder parent) {
+
+        }
+
+        @Override public void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode) {
+
+        }
+
+        @Override public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+            return null;
+        }
+
+        @Override public DataSchemaNode build() {
+            return null;
+        }
+
+        @Override public String getDescription() {
+            return null;
+        }
+
+        @Override public void setDescription(String description) {
+
+        }
+
+        @Override public String getReference() {
+            return null;
+        }
+
+        @Override public void setReference(String reference) {
+
+        }
+
+        @Override public Status getStatus() {
+            return null;
+        }
+
+        @Override public void setStatus(Status status) {
+
+        }
+
+        @Override public boolean isAddedByUses() {
+            return false;
+        }
+
+        @Override public void setAddedByUses(boolean addedByUses) {
+
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/LeafListSchemaNodeBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/LeafListSchemaNodeBuilderTest.java
new file mode 100644 (file)
index 0000000..5518804
--- /dev/null
@@ -0,0 +1,129 @@
+/*
+ * 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.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+
+/**
+ * Test suite for increasing of test coverage of LeafListSchemaNodeBuilder implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.LeafListSchemaNodeBuilder
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class LeafListSchemaNodeBuilderTest extends AbstractBuilderTest {
+
+    @Test
+    public void testLeafListSchemaNodeBuilderWithBaseLeafListSchemaNode() {
+        final String baseLeafListLocalName = "base-leaf-list";
+        final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName);
+        final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName);
+        final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            10, baseLeafListQName, baseLeafListPath);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+
+        baseLeafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+        baseLeafListBuilder.setType(Uint16.getInstance());
+        final LeafListSchemaNode leafList = baseLeafListBuilder.build();
+
+        assertNotNull(leafList);
+        assertFalse(leafList.getUnknownSchemaNodes().isEmpty());
+        assertEquals(leafList.getUnknownSchemaNodes().size(), 1);
+
+        final String leafListLocalName = "extended-leaf-list";
+        final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+        final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+        final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            15, leafListQName, leafListPath, leafList);
+
+        final LeafListSchemaNode extendedLeafList = leafListBuilder.build();
+
+        assertNotNull(extendedLeafList);
+        assertFalse(extendedLeafList.getUnknownSchemaNodes().isEmpty());
+        assertEquals(extendedLeafList.getUnknownSchemaNodes().size(), 1);
+
+        assertNotEquals(leafList, extendedLeafList);
+
+        assertTrue(extendedLeafList instanceof DerivableSchemaNode);
+        assertTrue(((DerivableSchemaNode) extendedLeafList).getOriginal().isPresent());
+        assertEquals(leafList, ((DerivableSchemaNode) extendedLeafList).getOriginal().get());
+    }
+
+    @Test
+    public void testEquals() {
+        final String baseLeafListLocalName = "leaf-list1";
+        final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName);
+        final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName);
+        final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            10, baseLeafListQName, baseLeafListPath);
+
+        baseLeafListBuilder.setType(Uint16.getInstance());
+        final LeafListSchemaNode leafList = baseLeafListBuilder.build();
+
+        final String leafListLocalName = "leaf-list2";
+        final QName leafListQName2 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+        final SchemaPath leafListPath2 = SchemaPath.create(true, leafListQName2);
+        final LeafListSchemaNodeBuilder leafListBuilder2 = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            10, leafListQName2, leafListPath2);
+
+        leafListBuilder2.setType(Uint16.getInstance());
+        final LeafListSchemaNode leafList2 = leafListBuilder2.build();
+
+        assertNotEquals(baseLeafListBuilder, null);
+        assertNotEquals(baseLeafListBuilder, leafListBuilder2);
+
+        assertNotEquals(leafList, null);
+        assertNotEquals(leafList, leafList2);
+
+        final QName containerQName = QName.create(module.getNamespace(), module.getRevision(), "parent-container");
+        final String leafListLocalName3 = "leaf-list2";
+        final QName leafListQName3 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName3);
+        final SchemaPath leafListPath3 = SchemaPath.create(true, containerQName, leafListQName3);
+        final LeafListSchemaNodeBuilder leafListBuilder3 = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            10, leafListQName3, leafListPath3);
+
+        baseLeafListBuilder.setType(Uint16.getInstance());
+        final LeafListSchemaNode leafList3 = baseLeafListBuilder.build();
+
+        assertNotEquals(leafListBuilder2, leafListBuilder3);
+        assertNotEquals(leafList3, leafList2);
+    }
+
+    @Test
+    public void testLeafListSchemaNodeImplProperties() {
+        final String descString = "my leaf list description";
+        final String leafListLocalName = "base-leaf-list";
+        final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+        final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+        final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            10, leafListQName, leafListPath);
+
+        leafListBuilder.setType(Uint16.getInstance());
+        leafListBuilder.setDescription(descString);
+        final LeafListSchemaNode leafList = leafListBuilder.build();
+
+        assertEquals(leafList.getQName(), leafListQName);
+        assertEquals(leafList.getDescription(), descString);
+        assertEquals(leafList.getStatus(), Status.CURRENT);
+        assertEquals(leafList.getPath(), leafListPath);
+        assertEquals(leafList.getType(), Uint16.getInstance());
+        assertNull(leafList.getReference());
+
+        assertEquals("LeafListSchemaNodeImpl[(urn:opendaylight.rpc:def:test-model?revision=2014-01-06)base-leaf-list]",
+            leafList.toString());
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilderTest.java
new file mode 100644 (file)
index 0000000..3930109
--- /dev/null
@@ -0,0 +1,802 @@
+/*
+ * 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.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+
+import java.net.URI;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.Builder;
+import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of ModuleBuilder implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class ModuleBuilderTest {
+
+    private final static String TEST_MODULE_NAMESPACE = "urn:opendaylight.foo";
+    private final static String TEST_MODULE_REVISION = "2014-09-22";
+    private final static String MODULE_NAME = "TestModule";
+    private static final String TEST_MODULE_PATH = "/test/module/path";
+
+    private ModuleBuilder moduleBuilder;
+
+    @Before
+    public void setUp() throws Exception {
+        moduleBuilder = new ModuleBuilder(MODULE_NAME , TEST_MODULE_PATH);
+    }
+
+    @Test
+    public void testGetSetModuleBuilderMethods() throws Exception {
+        assertEquals("module", moduleBuilder.getStatementName());
+        assertEquals(TEST_MODULE_PATH, moduleBuilder.getModuleSourcePath());
+        assertNotNull(moduleBuilder.getAllLists());
+        final URI namespace = URI.create(TEST_MODULE_NAMESPACE + "?" + TEST_MODULE_REVISION);
+        moduleBuilder.setNamespace(namespace);
+        assertEquals(namespace, moduleBuilder.getNamespace());
+        moduleBuilder.setBelongsTo("TEST_SUBMODULE");
+        assertEquals("TEST_SUBMODULE", moduleBuilder.getBelongsTo());
+        final Date revision = new SimpleDateFormat("yyyy-dd-mm").parse(TEST_MODULE_REVISION);
+        moduleBuilder.setRevision(revision);
+        assertEquals(revision, moduleBuilder.getRevision());
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckPrefixFailOnPrefixNull() {
+        moduleBuilder.addModuleImport("TEST_MODULE", null, null);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckPrefixFailOnPrefixStringIsEmpty() {
+        moduleBuilder.addModuleImport("TEST_MODULE", null, "");
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testCheckPrefixFailOnPrefixEqualsModuleBuilderPrefix() {
+        moduleBuilder.setPrefix("prefix");
+        moduleBuilder.addModuleImport("TEST_MODULE", null, "prefix");
+    }
+
+    @Test
+    public void testGetActualNodeNullResult() {
+        moduleBuilder.exitNode();
+        assertNull(moduleBuilder.getActualNode());
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testSetParent() throws Exception {
+        moduleBuilder.setParent(new Builder() {
+            @Override public String getModuleName() {
+                return null;
+            }
+
+            @Override public void setModuleName(String moduleName) {
+
+            }
+
+            @Override public int getLine() {
+                return 0;
+            }
+
+            @Override public Builder getParent() {
+                return null;
+            }
+
+            @Override public void setParent(Builder parent) {
+
+            }
+
+            @Override public void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode) {
+
+            }
+
+            @Override public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+                return null;
+            }
+
+            @Override public Object build() {
+                return null;
+            }
+        });
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddExtensionWhereParentNodeIsNotModuleBuilder() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+        final QName extQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext");
+        SchemaPath extPath = SchemaPath.create(true, containerQName, extQName);
+        moduleBuilder.addExtension(extQName, 12, extPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddExtensionWhereNameOfExtensionCollides() throws Exception {
+        final QName extQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext");
+        SchemaPath extPath = SchemaPath.create(true, extQName);
+        moduleBuilder.addExtension(extQName, 12, extPath);
+
+        final QName extQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-ext");
+        moduleBuilder.addExtension(extQName2, 22, extPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateGroupingIntoModule() {
+        final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath1 = SchemaPath.create(true, testGroup1);
+
+        final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath2 = SchemaPath.create(true, testGroup2);
+
+        moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+        moduleBuilder.addGrouping(12, testGroup2, groupPath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateGroupingIntoDataNodeContainer() {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+        final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath1 = SchemaPath.create(true, containerQName, testGroup1);
+
+        final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath2 = SchemaPath.create(true, containerQName, testGroup2);
+
+        moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+        moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+    }
+
+    @Test
+    public void testAddTwoGroupingIntoDataNodeContainer() {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+        final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath1 = SchemaPath.create(true, containerQName, testGroup1);
+
+        final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group2");
+        final SchemaPath groupPath2 = SchemaPath.create(true, containerQName, testGroup2);
+
+        GroupingBuilder grouping1 = moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+        GroupingBuilder grouping2 = moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+
+        assertNotNull(grouping1);
+        assertNotNull(grouping2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateGroupingIntoRpcDefinition() {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcDefName, rpcPath));
+        final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath1 = SchemaPath.create(true, rpcDefName, testGroup1);
+
+        final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath2 = SchemaPath.create(true, rpcDefName, testGroup2);
+
+        moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+        moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+    }
+
+    @Test
+    public void testAddTwoGroupingsIntoRpcDefinition() {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcDefName, rpcPath));
+        final QName testGroup1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath1 = SchemaPath.create(true, rpcDefName, testGroup1);
+
+        final QName testGroup2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group2");
+        final SchemaPath groupPath2 = SchemaPath.create(true, rpcDefName, testGroup2);
+
+        GroupingBuilder grouping1 = moduleBuilder.addGrouping(12, testGroup1, groupPath1);
+        GroupingBuilder grouping2 = moduleBuilder.addGrouping(22, testGroup2, groupPath2);
+
+        assertNotNull(grouping1);
+        assertNotNull(grouping2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddGroupingIntoNonValidStatementDefinition() {
+        final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist");
+        SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName);
+        moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath));
+        final QName testGroup = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath = SchemaPath.create(true, leafListDefName, testGroup);
+
+        moduleBuilder.addGrouping(12, testGroup, groupPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testInvalidAugmentPathTargetString() {
+        final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container");
+        moduleBuilder.addAugment(12, "something/something", SchemaPath.create(true, targetSchemaName), 0);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testInvalidAugmentPathTargetStringInUsesNode() {
+        final QName usesNode = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-uses-node");
+        SchemaPath targetPath = SchemaPath.create(true, usesNode);
+        moduleBuilder.enterNode(new UsesNodeBuilderImpl(MODULE_NAME, 10, targetPath));
+        final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container");
+        moduleBuilder.addAugment(12, "/something/something", SchemaPath.create(true, targetSchemaName), 0);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testInvalidAugmentDefinition() {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName targetSchemaName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "fictive-target-container");
+        moduleBuilder.addAugment(12, "/something/something", SchemaPath.create(true, targetSchemaName), 0);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testInvalidUsesNodeUse() {
+        final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist");
+        SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName);
+        moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath));
+
+        final QName testGroup = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-group");
+        final SchemaPath groupPath = SchemaPath.create(true, testGroup);
+
+        moduleBuilder.addUsesNode(17, groupPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddRefineToNonUsesNodeBuilder() throws Exception {
+        final QName leafListDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaflist");
+        SchemaPath leaflistPath = SchemaPath.create(true, leafListDefName);
+        moduleBuilder.enterNode(new LeafListSchemaNodeBuilder(MODULE_NAME, 10, leafListDefName, leaflistPath));
+
+        moduleBuilder.addRefine(new RefineHolderImpl(MODULE_NAME, 12, "testRefineName"));
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddRpcToNonModuleBuilder() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+
+        moduleBuilder.addRpc(17, rpcDefName, rpcPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddRpcWithSameNameAsAlreadyExistingDataNodeContainer() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "element-foo");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.addContainerNode(10, containerQName, containerPath);
+
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "element-foo");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.addRpc(17, rpcDefName, rpcPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateRpc() throws Exception {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.addRpc(17, rpcDefName, rpcPath);
+
+        final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2);
+        moduleBuilder.addRpc(23, rpcDefName2, rpcPath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddRpcWithSameNameAsAlreadyDefinedNotification() throws Exception {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.addNotification(17, rpcDefName, rpcPath);
+
+        final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2);
+        moduleBuilder.addRpc(23, rpcDefName2, rpcPath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddRpcInputForInvalidParent() throws Exception {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        final QName rpcInput = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "input");
+        SchemaPath rpcInputPath = SchemaPath.create(true, rpcDefName, rpcInput);
+
+        moduleBuilder.addRpcInput(23, rpcInput, rpcInputPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddRpcOutputForInvalidParent() throws Exception {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "rpc-definition");
+        final QName rpcOutput = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "output");
+        SchemaPath rpcOutputPath = SchemaPath.create(true, rpcDefName, rpcOutput);
+
+        moduleBuilder.addRpcOutput(rpcOutputPath, rpcOutput, 23);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddNotificationForInvalidParent() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+        SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+
+        moduleBuilder.addNotification(12, notificationName, notificationPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddNotificationWithSameNameAsAlreadyExistingDataNodeContainer() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.addContainerNode(10, containerQName, containerPath);
+
+        final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify");
+        SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+
+        moduleBuilder.addNotification(12, notificationName, notificationPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateNotification() throws Exception {
+        final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+        SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+
+        moduleBuilder.addNotification(12, notificationName, notificationPath);
+
+        final QName notificationName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+        SchemaPath notificationPath2 = SchemaPath.create(true, notificationName2);
+
+        moduleBuilder.addNotification(17, notificationName2, notificationPath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddNotificationWithSameNameAsAlreadyDefinedRpc() throws Exception {
+        final QName rpcDefName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+        SchemaPath rpcPath2 = SchemaPath.create(true, rpcDefName2);
+        moduleBuilder.addRpc(17, rpcDefName2, rpcPath2);
+
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-this");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.addNotification(23, rpcDefName, rpcPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddFeatureIntoNonModuleBuilder() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+        SchemaPath featurePath = SchemaPath.create(true, testFeature);
+
+        moduleBuilder.addFeature(23, testFeature, featurePath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateFeature() throws Exception {
+        final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+        SchemaPath featurePath = SchemaPath.create(true, testFeature);
+
+        moduleBuilder.addFeature(23, testFeature, featurePath);
+
+        final QName testFeature2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+        SchemaPath featurePath2 = SchemaPath.create(true, testFeature2);
+
+        moduleBuilder.addFeature(23, testFeature2, featurePath2);
+    }
+
+    @Test
+    public void testAddTwoFeatures() throws Exception {
+        final QName testFeature = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature");
+        SchemaPath featurePath = SchemaPath.create(true, testFeature);
+
+        final FeatureBuilder feature1 = moduleBuilder.addFeature(23, testFeature, featurePath);
+
+        final QName testFeature2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-feature2");
+        SchemaPath featurePath2 = SchemaPath.create(true, testFeature2);
+
+        final FeatureBuilder feature2 = moduleBuilder.addFeature(23, testFeature2, featurePath2);
+
+        assertNotNull(feature1);
+        assertNotNull(feature2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddCaseWhenParentIsNull() throws Exception {
+        moduleBuilder.exitNode();
+        addTestCase();
+    }
+
+    private void addTestCase() {
+        final QName testCase = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-case");
+        SchemaPath testCasePath = SchemaPath.create(true, testCase);
+
+        moduleBuilder.addCase(72, testCase, testCasePath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddCaseWhenParentIsModule() throws Exception {
+        addTestCase();
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddCaseWhenParentIsNotChoiceNorAugmentation() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+        addTestCase();
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateTypedefIntoContainer() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        tryToAddDuplicateTypedef();
+    }
+
+    private void tryToAddDuplicateTypedef() {
+        final QName testTypedef1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+        SchemaPath testTypedefPath1 = SchemaPath.create(true, testTypedef1);
+
+        final QName testTypedef2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+        SchemaPath testTypedefPath2 = SchemaPath.create(true, testTypedef2);
+
+        moduleBuilder.addTypedef(23, testTypedef1, testTypedefPath1);
+        moduleBuilder.addTypedef(44, testTypedef2, testTypedefPath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateTypedefIntoRpcDefinition() throws Exception {
+        final QName rpcQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-rpc");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+        moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcQName, rpcPath));
+
+        tryToAddDuplicateTypedef();
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddTypedefIntoNonValidStatement() throws Exception {
+        final QName leafName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-leaf");
+        SchemaPath leafPath = SchemaPath.create(true, leafName);
+        moduleBuilder.enterNode(new LeafSchemaNodeBuilder(MODULE_NAME, 10, leafName, leafPath));
+
+        final QName testRpc = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+        SchemaPath testRpcPath = SchemaPath.create(true, testRpc);
+
+        moduleBuilder.addTypedef(23, testRpc, testRpcPath);
+    }
+
+    @Test
+    public void testAddTwoTypedefsIntoContainer() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        tryToAddTwoTypedefs();
+    }
+
+    private void tryToAddTwoTypedefs() {
+        final QName testTypedef1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition");
+        SchemaPath testTypedefPath1 = SchemaPath.create(true, testTypedef1);
+
+        final QName testTypedef2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-type-definition2");
+        SchemaPath testTypedefPath2 = SchemaPath.create(true, testTypedef2);
+
+        final TypeDefinitionBuilderImpl typedef1 = moduleBuilder.addTypedef(23, testTypedef1, testTypedefPath1);
+        final TypeDefinitionBuilderImpl typedef2 = moduleBuilder.addTypedef(44, testTypedef2, testTypedefPath2);
+
+        assertNotNull(typedef1);
+        assertNotNull(typedef2);
+    }
+
+    @Test
+    public void testAddTwoTypedefsIntoRpcDefinition() throws Exception {
+        final QName rpcQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-rpc");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+        moduleBuilder.enterNode(new RpcDefinitionBuilder(MODULE_NAME, 10, rpcQName, rpcPath));
+
+        tryToAddTwoTypedefs();
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testSetType() throws Exception {
+        final Uint16 uint = Uint16.getInstance();
+        moduleBuilder.setType(uint);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddUnionTypeWhenParentIsNull() throws Exception {
+        moduleBuilder.exitNode();
+
+        tryToAddUnionType();
+    }
+
+    private void tryToAddUnionType() {
+        final QName unionQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "union-type-def");
+        moduleBuilder.addUnionType(25, QNameModule.create(unionQName.getNamespace(), unionQName.getRevision()));
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddUnionTypeWhenParentIsNotTypeAwareBuilder() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        tryToAddUnionType();
+    }
+
+    @Test(expected = YangParseException.class)
+    public void addIdentityrefTypeWhenParentIsNull() throws Exception {
+        moduleBuilder.exitNode();
+        tryToAddIdentityrefType();
+    }
+
+    private void tryToAddIdentityrefType() {
+        final QName identityrefQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "identityref-type-def");
+        SchemaPath identityrefPath = SchemaPath.create(true, identityrefQName);
+        moduleBuilder.addIdentityrefType(25, identityrefPath, "simplebase");
+    }
+
+    @Test(expected = YangParseException.class)
+    public void addIdentityrefTypeWhenParentIsNotTypeAwareBuilder() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        tryToAddIdentityrefType();
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDeviationWhereParentIsNotModule() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName deviationQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-deviation-name");
+        SchemaPath deviationPath = SchemaPath.create(true, deviationQName);
+
+        moduleBuilder.addDeviation(78, deviationPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddIdentityWhereParentIsNotModule() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        tryToAddIdentity();
+    }
+
+    private void tryToAddIdentity() {
+        final QName identityQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "test-identity-name");
+        SchemaPath identityPath = SchemaPath.create(true, identityQName);
+
+        moduleBuilder.addIdentity(identityQName, 78, identityPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateIdentity() throws Exception {
+        tryToAddIdentity();
+        tryToAddIdentity();
+    }
+
+    @Test
+    public void testAddUnknownSchemaNodeDirectlyToParent() throws Exception {
+        final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use");
+        SchemaPath unknownPath = SchemaPath.create(true, unknownQName);
+        assertTrue(moduleBuilder.getUnknownNodes().isEmpty());
+        moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath);
+        assertFalse(moduleBuilder.getUnknownNodes().isEmpty());
+    }
+
+    @Test
+    public void testAddUnknownSchemaNodeIntoDataNodeContainer() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use");
+        SchemaPath unknownPath = SchemaPath.create(true, unknownQName);
+        assertTrue(moduleBuilder.getAllUnknownNodes().isEmpty());
+        moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath);
+        assertFalse(moduleBuilder.getAllUnknownNodes().isEmpty());
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddUnknownSchemaNodeIntoNonSchemaNode() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-non-schema-node");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new NonSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName unknownQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-extension-use");
+        SchemaPath unknownPath = SchemaPath.create(true, unknownQName);
+        assertTrue(moduleBuilder.getUnknownNodes().isEmpty());
+        moduleBuilder.addUnknownSchemaNode(72, unknownQName, unknownPath);
+        assertFalse(moduleBuilder.getUnknownNodes().isEmpty());
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddContainerWithSameNameAsRpcDefintion() throws Exception {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.addRpc(70, rpcDefName, rpcPath);
+        tryToAddContainer();
+    }
+
+    private void tryToAddContainer() {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message");
+        final SchemaPath containerPath = SchemaPath.create(true, containerQName);
+
+        moduleBuilder.addContainerNode(22, containerQName, containerPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddContainerWithSameNameAsNotificationDefintion() throws Exception {
+        final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "message");
+        SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+        moduleBuilder.addNotification(70, notificationName, notificationPath);
+        tryToAddContainer();
+    }
+
+    @Test
+    public void testAddContainerWithAlreadyAddedRpcDefintion() throws Exception {
+        final QName rpcDefName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "send-message");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcDefName);
+        moduleBuilder.addRpc(70, rpcDefName, rpcPath);
+        tryToAddContainer();
+
+        DataSchemaNodeBuilder addedContainer = moduleBuilder.getDataChildByName("message");
+        assertNotNull(addedContainer);
+    }
+
+    @Test
+    public void testAddContainerWithAlreadyAddedNotificationDefintion() throws Exception {
+        final QName notificationName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "notify-me");
+        SchemaPath notificationPath = SchemaPath.create(true, notificationName);
+        moduleBuilder.addNotification(70, notificationName, notificationPath);
+        tryToAddContainer();
+
+        DataSchemaNodeBuilder addedContainer = moduleBuilder.getDataChildByName("message");
+        assertNotNull(addedContainer);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateSchemaNodeIntoSubnodeOfModule() throws Exception {
+        final QName containerQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath containerPath = SchemaPath.create(true, containerQName);
+        moduleBuilder.enterNode(new ContainerSchemaNodeBuilder(MODULE_NAME, 10, containerQName, containerPath));
+
+        final QName leafQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+        SchemaPath leafPath1 = SchemaPath.create(true, containerQName, leafQName1);
+
+        final QName leafQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+        SchemaPath leafPath2 = SchemaPath.create(true, containerQName, leafQName2);
+
+        moduleBuilder.addLeafNode(12, leafQName1, leafPath1);
+        moduleBuilder.addLeafNode(20, leafQName2, leafPath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddDuplicateCaseIntoChoiceCaseNode() throws Exception {
+        //FIXME: move this into ChoiceBuilderTest !!!
+        final QName choiceQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "top-level-container");
+        SchemaPath choicePath = SchemaPath.create(true, choiceQName);
+
+        moduleBuilder.enterNode(new ChoiceBuilder(MODULE_NAME, 10, choiceQName, choicePath));
+
+        final QName caseQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+        SchemaPath casePath1 = SchemaPath.create(true, choiceQName, caseQName1);
+
+        final QName caseQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+        SchemaPath casePath2 = SchemaPath.create(true, choiceQName, caseQName2);
+
+        moduleBuilder.addCase(12, caseQName1, casePath1);
+        moduleBuilder.addCase(20, caseQName2, casePath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddChoiceWithSameNameAsCase() throws Exception {
+        final QName choiceQName = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "my-choice");
+        SchemaPath choicePath = SchemaPath.create(true, choiceQName);
+
+        final ChoiceBuilder choiceBuilder = moduleBuilder.addChoice(8, choiceQName, choicePath);
+        moduleBuilder.enterNode(choiceBuilder);
+
+        final QName caseQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+        SchemaPath casePath1 = SchemaPath.create(true, choiceQName, caseQName1);
+
+        final QName caseQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-case");
+        SchemaPath casePath2 = SchemaPath.create(true, choiceQName, caseQName2);
+
+        moduleBuilder.addCase(12, caseQName1, casePath1);
+        moduleBuilder.addChoice(20, caseQName2, casePath2);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testAddChildToSubnodeForNonDataNodeContainerAndNonChoiceNode() {
+        final QName leafQName1 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+        SchemaPath leafPath1 = SchemaPath.create(true, leafQName1);
+
+        final LeafSchemaNodeBuilder leafBuilder = moduleBuilder.addLeafNode(10, leafQName1, leafPath1);
+        moduleBuilder.enterNode(leafBuilder);
+
+        final QName leafQName2 = QName.create(TEST_MODULE_NAMESPACE, TEST_MODULE_REVISION, "simple-leaf");
+        SchemaPath leafPath2 = SchemaPath.create(true, leafQName1, leafQName2);
+
+        moduleBuilder.addLeafNode(12, leafQName2, leafPath2);
+    }
+
+    private static class NonSchemaNodeBuilder implements Builder {
+
+        String moduleName;
+        final int line;
+        final QName name;
+        final SchemaPath path;
+
+        public NonSchemaNodeBuilder(final String moduleName, final int line, final QName name, final SchemaPath path) {
+            this.moduleName = moduleName;
+            this.line = line;
+            this.name = name;
+            this.path = path;
+        }
+
+        @Override public String getModuleName() {
+            return moduleName;
+        }
+
+        @Override public void setModuleName(String moduleName) {
+            this.moduleName = moduleName;
+        }
+
+        @Override public int getLine() {
+            return line;
+        }
+
+        @Override public Builder getParent() {
+            return null;
+        }
+
+        @Override public void setParent(Builder parent) {
+
+        }
+
+        @Override public void addUnknownNodeBuilder(UnknownSchemaNodeBuilder unknownNode) {
+
+        }
+
+        @Override public List<UnknownSchemaNodeBuilder> getUnknownNodes() {
+            return null;
+        }
+
+        @Override public Object build() {
+            return null;
+        }
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtilsTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RefineUtilsTest.java
new file mode 100644 (file)
index 0000000..c9b3711
--- /dev/null
@@ -0,0 +1,256 @@
+/*
+ * 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.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.MustDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.util.MustDefinitionImpl;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+/**
+ * Test suite for increasing of test coverage of RefineUtils implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.RefineUtils
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class RefineUtilsTest extends AbstractBuilderTest {
+
+    @Test
+    public void testRefineLeafWithEmptyDefaultString() {
+        final String leafLocalName = "leaf-to-refine";
+        final QName leafName = QName.create(module.getNamespace(), module.getRevision(), leafLocalName);
+        final SchemaPath leafPath = SchemaPath.create(true, leafName);
+        final LeafSchemaNodeBuilder leafBuilder = new LeafSchemaNodeBuilder(module.getModuleName(), 22, leafName, leafPath);
+
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+leafLocalName);
+        refineBuilder.setDefaultStr("");
+
+        RefineUtils.performRefine(leafBuilder, refineBuilder);
+        assertNull(leafBuilder.getDefaultStr());
+    }
+
+    @Test
+    public void testRefineContainer() {
+        final String containerLocalName = "container-to-refine";
+        final QName containerName = QName.create(module.getNamespace(), module.getRevision(), containerLocalName);
+        final SchemaPath containerPath = SchemaPath.create(true, containerName);
+        final ContainerSchemaNodeBuilder containerBuilder = new ContainerSchemaNodeBuilder(module.getModuleName(),
+            10, containerName, containerPath);
+
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+containerLocalName);
+        refineBuilder.setPresence(null);
+
+        final MustDefinition must = provideMustDefinition();
+        refineBuilder.setMust(must);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+        refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        RefineUtils.performRefine(containerBuilder, refineBuilder);
+
+        assertFalse(containerBuilder.getConstraints().getMustDefinitions().isEmpty());
+        assertEquals(containerBuilder.getConstraints().getMustDefinitions().size(), 1);
+        assertFalse(containerBuilder.getUnknownNodes().isEmpty());
+        assertEquals(containerBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+    }
+
+
+
+    @Test
+    public void testRefineList() {
+        final String listLocalName = "list-to-refine";
+        final QName listQName = QName.create(module.getNamespace(), module.getRevision(), listLocalName);
+        final SchemaPath listPath = SchemaPath.create(true, listQName);
+        final ListSchemaNodeBuilder listBuilder = new ListSchemaNodeBuilder(module.getModuleName(),
+            10, listQName, listPath);
+
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+listLocalName);
+
+        final MustDefinition must = provideMustDefinition();
+        refineBuilder.setMust(must);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+        refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        refineBuilder.setMinElements(null);
+        refineBuilder.setMaxElements(null);
+
+        RefineUtils.performRefine(listBuilder, refineBuilder);
+        assertFalse(listBuilder.getConstraints().getMustDefinitions().isEmpty());
+        assertEquals(listBuilder.getConstraints().getMustDefinitions().size(), 1);
+        assertNull(listBuilder.getConstraints().getMinElements());
+        assertNull(listBuilder.getConstraints().getMaxElements());
+        assertFalse(listBuilder.getUnknownNodes().isEmpty());
+        assertEquals(listBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+    }
+
+    @Test
+    public void testRefineLeafList() {
+        final String leafListLocalName = "list-to-refine";
+        final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
+        final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
+        final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
+            10, leafListQName, leafListPath);
+
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+leafListLocalName);
+
+        final MustDefinition must = provideMustDefinition();
+        refineBuilder.setMust(null);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+        refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        refineBuilder.setMinElements(null);
+        refineBuilder.setMaxElements(null);
+
+        RefineUtils.performRefine(leafListBuilder, refineBuilder);
+        assertTrue(leafListBuilder.getConstraints().getMustDefinitions().isEmpty());
+        assertNull(leafListBuilder.getConstraints().getMinElements());
+        assertNull(leafListBuilder.getConstraints().getMaxElements());
+        assertFalse(leafListBuilder.getUnknownNodes().isEmpty());
+        assertEquals(leafListBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+
+        refineBuilder.setMinElements(Integer.MIN_VALUE);
+        refineBuilder.setMaxElements(Integer.MAX_VALUE);
+        refineBuilder.setMust(must);
+
+        RefineUtils.performRefine(leafListBuilder, refineBuilder);
+        assertFalse(leafListBuilder.getConstraints().getMustDefinitions().isEmpty());
+        assertEquals(leafListBuilder.getConstraints().getMustDefinitions().size(), 1);
+
+        assertNotNull(leafListBuilder.getConstraints().getMinElements());
+        assertNotNull(leafListBuilder.getConstraints().getMaxElements());
+    }
+
+    @Test
+    public void testRefineChoice() {
+        final String choiceLocalName = "choice-to-refine";
+        final ChoiceBuilder choiceBuilder = provideChoiceBuilder(choiceLocalName);
+
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+choiceLocalName);
+        refineBuilder.setDefaultStr(null);
+        refineBuilder.setMandatory(null);
+
+        RefineUtils.performRefine(choiceBuilder, refineBuilder);
+        assertNull(choiceBuilder.getDefaultCase());
+        assertFalse(choiceBuilder.getConstraints().isMandatory());
+
+        final String defaultValue = "choice-default-case";
+        refineBuilder.setDefaultStr(defaultValue);
+        refineBuilder.setMandatory(true);
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+        refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        RefineUtils.performRefine(choiceBuilder, refineBuilder);
+        assertNotNull(choiceBuilder.getDefaultCase());
+        assertNotNull(choiceBuilder.getConstraints().isMandatory());
+        assertFalse(choiceBuilder.getUnknownNodes().isEmpty());
+        assertEquals(choiceBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+    }
+
+    @Test
+    public void testRefineAnyxml() {
+        final String anyxmlLocalName = "anyxml-to-refine";
+        final QName anyxmlName = QName.create(module.getNamespace(), module.getRevision(), anyxmlLocalName);
+        final SchemaPath anyxmlPath = SchemaPath.create(true, anyxmlName);
+        final AnyXmlBuilder anyXmlBuilder = new AnyXmlBuilder(module.getModuleName(), 22, anyxmlName, anyxmlPath);
+
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+anyxmlLocalName);
+        refineBuilder.setMandatory(null);
+        refineBuilder.setMust(null);
+
+        RefineUtils.performRefine(anyXmlBuilder, refineBuilder);
+        assertNull(refineBuilder.isMandatory());
+        assertNull(refineBuilder.getMust());
+
+        final MustDefinition must = provideMustDefinition();
+
+        refineBuilder.setMandatory(true);
+        refineBuilder.setMust(must);
+
+        final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
+        refineBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        RefineUtils.performRefine(anyXmlBuilder, refineBuilder);
+        assertFalse(anyXmlBuilder.getConstraints().getMustDefinitions().isEmpty());
+        assertEquals(anyXmlBuilder.getConstraints().getMustDefinitions().size(), 1);
+        assertFalse(anyXmlBuilder.getUnknownNodes().isEmpty());
+        assertEquals(anyXmlBuilder.getUnknownNodes().get(0), unknownNodeBuilder);
+        assertTrue(anyXmlBuilder.getConstraints().isMandatory());
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testCheckRefineDefault() {
+        final String groupLocalName = "test-group";
+        final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), groupLocalName);
+        final SchemaPath groupPath = SchemaPath.create(true, testGroup);
+        final GroupingBuilder grouping = module.addGrouping(12, testGroup, groupPath);
+
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+groupLocalName);
+        refineBuilder.setDefaultStr("invalid-default-value");
+
+        RefineUtils.performRefine(grouping, refineBuilder);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testCheckRefineMandatory() {
+        final TypeDefinitionBuilderImpl typedef = initTypedef();
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+        refineBuilder.setMandatory(true);
+        RefineUtils.performRefine(typedef, refineBuilder);
+    }
+
+    private TypeDefinitionBuilderImpl initTypedef() {
+        final String typedefLocalName = "test-type-definition";
+        final QName testTypedef = QName.create(module.getNamespace(), module.getRevision(), typedefLocalName);
+        SchemaPath testTypedefPath = SchemaPath.create(true, testTypedef);
+
+        return module.addTypedef(23, testTypedef, testTypedefPath);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testCheckRefineMust() {
+        final TypeDefinitionBuilderImpl typedef = initTypedef();
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+
+        final MustDefinition must = provideMustDefinition();
+        refineBuilder.setMust(must);
+        RefineUtils.performRefine(typedef, refineBuilder);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testCheckRefineMin() {
+        final TypeDefinitionBuilderImpl typedef = initTypedef();
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+
+        refineBuilder.setMinElements(Integer.MIN_VALUE);
+        RefineUtils.performRefine(typedef, refineBuilder);
+    }
+
+    @Test(expected = YangParseException.class)
+    public void testCheckRefineMax() {
+        final TypeDefinitionBuilderImpl typedef = initTypedef();
+        final RefineHolderImpl refineBuilder = new RefineHolderImpl(module.getModuleName(), 23, "/"+typedef.getQName().getLocalName());
+
+        refineBuilder.setMaxElements(Integer.MAX_VALUE);
+        RefineUtils.performRefine(typedef, refineBuilder);
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/builder/impl/RpcDefinitionBuilderTest.java
new file mode 100644 (file)
index 0000000..e923c93
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * 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.yangtools.yang.parser.builder.impl;
+
+import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
+
+/**
+ * Test suite for increasing of test coverage of RpcDefinitionBuilder implementation.
+ *
+ * @see org.opendaylight.yangtools.yang.parser.builder.impl.RpcDefinitionBuilder
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class RpcDefinitionBuilderTest extends AbstractBuilderTest {
+
+    @Test
+    public void testBuild() {
+        final QName rpcQName = QName.create(module.getNamespace(), module.getRevision(), "send-message");
+        SchemaPath rpcPath = SchemaPath.create(true, rpcQName);
+        final RpcDefinitionBuilder rpcBuilder = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, rpcPath);
+
+        final QName testTypedef = QName.create(module.getNamespace(), module.getRevision(), "test-typedef");
+        final SchemaPath testTypedefPath = SchemaPath.create(true, rpcQName, testTypedef);
+        final TypeDefinitionBuilder typedefBuilder = new TypeDefinitionBuilderImpl(module.getModuleName(),
+            12, testTypedef, testTypedefPath);
+        typedefBuilder.setType(Uint16.getInstance());
+
+        rpcBuilder.addTypedef(typedefBuilder);
+
+        final QName testGroup = QName.create(module.getNamespace(), module.getRevision(), "test-group");
+        final SchemaPath groupPath = SchemaPath.create(true, rpcQName, testGroup);
+        final GroupingBuilder groupBuilder = new GroupingBuilderImpl(module.getModuleName(), 15, testGroup, groupPath);
+
+        rpcBuilder.addGrouping(groupBuilder);
+
+        final QName unknownNode = QName.create(module.getNamespace(), module.getRevision(), "unknown-ext-use");
+        final SchemaPath unknownNodePath = SchemaPath.create(true, rpcQName, unknownNode);
+        final UnknownSchemaNodeBuilder unknownNodeBuilder =  new UnknownSchemaNodeBuilderImpl(module.getModuleName(),
+            25, unknownNode, unknownNodePath);
+
+        rpcBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
+
+        final RpcDefinitionBuilder rpcBuilder2 = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, rpcPath);
+        final RpcDefinitionBuilder rpcBuilder3 = new RpcDefinitionBuilder(module.getModuleName(), 10, unknownNode, rpcPath);
+        final RpcDefinitionBuilder rpcBuilder4 = new RpcDefinitionBuilder(module.getModuleName(), 10, rpcQName, unknownNodePath);
+
+        assertEquals(rpcBuilder, rpcBuilder2);
+        assertNotEquals(rpcBuilder, null);
+        assertNotEquals(rpcBuilder, rpcBuilder3);
+        assertNotEquals(rpcBuilder, rpcBuilder4);
+
+        assertEquals(rpcBuilder.toString(), "rpc send-message");
+
+        final RpcDefinition instance = rpcBuilder.build();
+
+        assertNotNull(instance);
+
+        final RpcDefinition sameInstance = rpcBuilder.build();
+        assertTrue(sameInstance == instance);
+        assertEquals(sameInstance, instance);
+
+        assertEquals(instance.getPath(), rpcPath);
+        assertEquals(instance.getStatus(), Status.CURRENT);
+        assertNull(instance.getOutput());
+        assertFalse(instance.getTypeDefinitions().isEmpty());
+        assertFalse(instance.getGroupings().isEmpty());
+        assertFalse(instance.getUnknownSchemaNodes().isEmpty());
+
+        assertEquals(instance.getTypeDefinitions().size(), 1);
+        assertEquals(instance.getGroupings().size(), 1);
+        assertEquals(instance.getUnknownSchemaNodes().size(), 1);
+
+        RpcDefinition instance2 = rpcBuilder2.build();
+        RpcDefinition instance3 = rpcBuilder3.build();
+        RpcDefinition instance4 = rpcBuilder4.build();
+
+        assertEquals(instance, instance2);
+        assertNotEquals(instance, null);
+        assertNotEquals(instance, instance3);
+        assertNotEquals(instance, instance4);
+
+        assertEquals(instance.toString(), "RpcDefinitionImpl[qname=(urn:opendaylight.rpc:def:test-model?" +
+            "revision=2014-01-06)send-message, path=AbsoluteSchemaPath{path=[(urn:opendaylight.rpc:def:test-model?" +
+            "revision=2014-01-06)send-message]}, input=null, output=null]");
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2219Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/impl/Bug2219Test.java
new file mode 100644 (file)
index 0000000..5834e14
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2014 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.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils;
+import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
+
+/**
+ * NPE is rised during use of CopyUtils.copy operation for IdentityrefTypeBuilder.
+ * NPE occours in private getData method in CopyUtils.java during QName.create.
+ *
+ * The reason for exception is the old.getQName returns null since IdentityrefTypeBuilder.getQName()
+ * by implementation returns always null.
+ *
+ */
+public class Bug2219Test {
+
+    private ModuleBuilder moduleBuilder;
+
+    @Before
+    public void init() {
+        moduleBuilder = new ModuleBuilder("test-module", "somePath");
+    }
+
+    @Test
+    public void testCopyIdentityrefTypeBuilder() {
+        final String typedefLocalName = "identity-ref-test-type";
+        final QName typedefQname = QName.create(moduleBuilder.getNamespace(), moduleBuilder.getRevision(), typedefLocalName);
+        final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
+        final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(moduleBuilder.getModuleName(), 12,
+            "base:parent-identity", typedefPath);
+
+        final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, moduleBuilder, true);
+        assertNotNull(copy);
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/SchemaContextUtilTest.java
new file mode 100644 (file)
index 0000000..db9942f
--- /dev/null
@@ -0,0 +1,542 @@
+/*
+ * Copyright (c) 2014 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.yangtools.yang.parser.util;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
+import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.model.util.Int32;
+import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
+import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.text.ParseException;
+import java.util.Collections;
+import java.util.Set;
+
+import static org.junit.Assert.*;
+
+public class SchemaContextUtilTest {
+    @Mock
+    private SchemaContext mockSchemaContext;
+    @Mock
+    private Module mockModule;
+
+    @Test
+    public void testFindDummyData() {
+        MockitoAnnotations.initMocks(this);
+
+        QName qName = QName.create("TestQName");
+        SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+        assertEquals("Should be null. Module TestQName not found", null,
+                SchemaContextUtil.findDataSchemaNode(mockSchemaContext, schemaPath));
+
+        RevisionAwareXPath xPath = new RevisionAwareXPathImpl("/bookstore/book/title", true);
+        assertEquals("Should be null. Module bookstore not found", null,
+                SchemaContextUtil.findDataSchemaNode(mockSchemaContext, mockModule, xPath));
+
+        SchemaNode schemaNode = Int32.getInstance();
+        RevisionAwareXPath xPathRelative = new RevisionAwareXPathImpl("../prefix", false);
+        assertEquals("Should be null, Module prefix not found", null,
+                SchemaContextUtil.findDataSchemaNodeForRelativeXPath(mockSchemaContext, mockModule, schemaNode,
+                        xPathRelative));
+
+        assertEquals("Should be null. Module TestQName not found", null,
+                SchemaContextUtil.findNodeInSchemaContext(mockSchemaContext, Collections.singleton(qName)));
+
+        assertEquals("Should be null.", null, SchemaContextUtil.findParentModule(mockSchemaContext, schemaNode));
+    }
+
+    @Test
+    public void findNodeInSchemaContextTest() throws URISyntaxException, IOException, YangSyntaxErrorException,
+            ParseException {
+
+        File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+        File resourceDir = resourceFile.getParentFile();
+
+        YangParserImpl parser = YangParserImpl.getInstance();
+        SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-leaf-in-container");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-leaf-in-container"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        Set<RpcDefinition> rpcs = myModule.getRpcs();
+        RpcDefinition rpc = rpcs.iterator().next();
+        testNode = rpc.getInput().getDataChildByName("my-input-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "input"),
+                QName.create(myModule.getQNameModule(), "my-input-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        rpc = myModule.getRpcs().iterator().next();
+        testNode = rpc.getOutput().getDataChildByName("my-output-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "output"),
+                QName.create(myModule.getQNameModule(), "my-output-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        NotificationDefinition notification = myModule.getNotifications().iterator().next();
+        testNode = notification.getDataChildByName("my-notification-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+                QName.create(myModule.getQNameModule(), "my-notification-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+        testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+                .getDataChildByName("my-leaf-in-grouping");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+                QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+                QName.create(myModule.getQNameModule(), "my-leaf-in-grouping"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((ChoiceNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+                "my-choice-leaf-one");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+                QName.create(myModule.getQNameModule(), "one"),
+                QName.create(myModule.getQNameModule(), "my-choice-leaf-one"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("my-leaf-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "my-leaf-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("my-leaf-list-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "my-leaf-list-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test
+    public void findNodeInSchemaContextTest2() throws URISyntaxException, IOException, YangSyntaxErrorException,
+            ParseException {
+
+        File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+        File resourceDir = resourceFile.getParentFile();
+
+        YangParserImpl parser = YangParserImpl.getInstance();
+        SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-leaf-not-in-container");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-leaf-not-in-container"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        Set<RpcDefinition> rpcs = myModule.getRpcs();
+        RpcDefinition rpc = rpcs.iterator().next();
+        testNode = rpc.getInput().getDataChildByName("no-input-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"),
+                QName.create(myModule.getQNameModule(), "input"),
+                QName.create(myModule.getQNameModule(), "no-input-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        NotificationDefinition notification = myModule.getNotifications().iterator().next();
+        testNode = notification.getDataChildByName("no-notification-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"),
+                QName.create(myModule.getQNameModule(), "no-notification-leaf"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        GroupingDefinition grouping = myModule.getGroupings().iterator().next();
+        testNode = ((ContainerSchemaNode) grouping.getDataChildByName("my-container-in-grouping"))
+                .getDataChildByName("no-leaf-in-grouping");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"),
+                QName.create(myModule.getQNameModule(), "my-container-in-grouping"),
+                QName.create(myModule.getQNameModule(), "no-leaf-in-grouping"));
+
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        testNode = ((ChoiceNode) myModule.getDataChildByName("my-choice")).getCaseNodeByName("one").getDataChildByName(
+                "no-choice-leaf");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"),
+                QName.create(myModule.getQNameModule(), "one"),
+                QName.create(myModule.getQNameModule(), "no-choice-leaf"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        ListSchemaNode listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("no-leaf-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "no-leaf-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+        listNode = (ListSchemaNode) ((ContainerSchemaNode) myModule.getDataChildByName("my-container"))
+                .getDataChildByName("my-list");
+
+        testNode = listNode.getDataChildByName("no-leaf-list-in-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"),
+                QName.create(myModule.getQNameModule(), "no-leaf-list-in-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNull(testNode);
+        assertNull(foundNode);
+
+    }
+
+    @Test
+    public void findNodeInSchemaContextTest3() throws URISyntaxException, IOException, YangSyntaxErrorException,
+            ParseException {
+
+        File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+        File resourceDir = resourceFile.getParentFile();
+
+        YangParserImpl parser = YangParserImpl.getInstance();
+        SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = myModule.getDataChildByName("my-container");
+
+        SchemaPath path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"));
+        SchemaNode foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = myModule.getRpcs().iterator().next();
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-rpc"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = myModule.getNotifications().iterator().next();
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-notification"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = myModule.getGroupings().iterator().next();
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-grouping"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = myModule.getDataChildByName("my-choice");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-choice"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+        testNode = ((ContainerSchemaNode) myModule.getDataChildByName("my-container")).getDataChildByName("my-list");
+
+        path = SchemaPath.create(true, QName.create(myModule.getQNameModule(), "my-container"),
+                QName.create(myModule.getQNameModule(), "my-list"));
+        foundNode = SchemaContextUtil.findNodeInSchemaContext(context, path.getPathFromRoot());
+
+        assertNotNull(testNode);
+        assertNotNull(foundNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test
+    public void findParentModuleTest() throws URISyntaxException, IOException, YangSyntaxErrorException, ParseException {
+
+        File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+        File resourceDir = resourceFile.getParentFile();
+
+        YangParserImpl parser = YangParserImpl.getInstance();
+        SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+        Module myModule = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        DataSchemaNode node = myModule.getDataChildByName("my-container");
+
+        Module foundModule = SchemaContextUtil.findParentModule(context, node);
+
+        assertEquals(myModule, foundModule);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findParentModuleIllegalArgumentTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        SchemaContextUtil.findParentModule(mockContext, null);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findParentModuleIllegalArgumentTest2() {
+
+        SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+        SchemaContextUtil.findParentModule(null, mockSchemaNode);
+
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void findParentModuleIllegalStateTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        SchemaNode mockSchemaNode = Mockito.mock(SchemaNode.class);
+        Mockito.when(mockSchemaNode.getPath()).thenReturn(null);
+        SchemaContextUtil.findParentModule(mockContext, mockSchemaNode);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeIllegalArgumentTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        SchemaContextUtil.findDataSchemaNode(mockContext, null);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeIllegalArgumentTest2() {
+
+        SchemaPath mockSchemaPath = Mockito.mock(SchemaPath.class);
+        SchemaContextUtil.findDataSchemaNode(null, mockSchemaPath);
+
+    }
+
+    @Test
+    public void findDataSchemaNodeTest() throws URISyntaxException, IOException, YangSyntaxErrorException {
+
+        File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+        File resourceDir = resourceFile.getParentFile();
+
+        YangParserImpl parser = YangParserImpl.getInstance();
+        SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+        Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+        Module importedModule = context.findModuleByNamespaceAndRevision(new URI("uri:imported-module"),
+                QName.parseRevision("2014-10-07"));
+
+        SchemaNode testNode = ((ContainerSchemaNode) importedModule.getDataChildByName("my-imported-container"))
+                .getDataChildByName("my-imported-leaf");
+
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("imp:my-imported-container/imp:my-imported-leaf", true);
+
+        SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+        assertNotNull(foundNode);
+        assertNotNull(testNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test
+    public void findDataSchemaNodeTest2() throws URISyntaxException, IOException, YangSyntaxErrorException {
+        // findDataSchemaNode(final SchemaContext context, final Module module,
+        // final RevisionAwareXPath nonCondXPath) {
+
+        File resourceFile = new File(getClass().getResource("/schema-context-util-test/my-module.yang").toURI());
+        File resourceDir = resourceFile.getParentFile();
+
+        YangParserImpl parser = YangParserImpl.getInstance();
+        SchemaContext context = parser.parseFile(resourceFile, resourceDir);
+
+        Module module = context.findModuleByNamespaceAndRevision(new URI("uri:my-module"),
+                QName.parseRevision("2014-10-07"));
+
+        GroupingDefinition grouping = module.getGroupings().iterator().next();
+        SchemaNode testNode = grouping.getDataChildByName("my-leaf-in-gouping2");
+
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+        SchemaNode foundNode = SchemaContextUtil.findDataSchemaNode(context, module, xpath);
+
+        assertNotNull(foundNode);
+        assertNotNull(testNode);
+        assertEquals(testNode, foundNode);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+
+        SchemaContextUtil.findDataSchemaNode(mockContext, module, null);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest2() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+        SchemaContextUtil.findDataSchemaNode(mockContext, null, xpath);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest3() {
+
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", true);
+
+        SchemaContextUtil.findDataSchemaNode(null, module, xpath);
+
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void findDataSchemaNodeFromXPathIllegalArgumentTest4() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping[@con='NULL']/my:my-leaf-in-gouping2",
+                true);
+
+        SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath);
+
+    }
+
+    @Test
+    public void findDataSchemaNodeFromXPathNullTest() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = Mockito.mock(RevisionAwareXPath.class);
+
+        Mockito.when(xpath.toString()).thenReturn(null);
+        assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+    }
+
+    @Test
+    public void findDataSchemaNodeFromXPathNullTest2() {
+
+        SchemaContext mockContext = Mockito.mock(SchemaContext.class);
+        Module module = Mockito.mock(Module.class);
+        RevisionAwareXPath xpath = new RevisionAwareXPathImpl("my:my-grouping/my:my-leaf-in-gouping2", false);
+
+        assertNull(SchemaContextUtil.findDataSchemaNode(mockContext, module, xpath));
+
+    }
+
+}
\ No newline at end of file
diff --git a/yang/yang-parser-impl/src/test/resources/schema-context-util-test/imported-module.yang b/yang/yang-parser-impl/src/test/resources/schema-context-util-test/imported-module.yang
new file mode 100644 (file)
index 0000000..bba0989
--- /dev/null
@@ -0,0 +1,16 @@
+module imported-module {
+    yang-version 1;
+    namespace "uri:imported-module";
+    prefix imp;
+
+    revision 2014-10-07 {
+        description
+                "Imported yang model";
+    }
+
+    container my-imported-container {
+        leaf my-imported-leaf {
+            type string;
+        }
+    }
+}
diff --git a/yang/yang-parser-impl/src/test/resources/schema-context-util-test/my-module.yang b/yang/yang-parser-impl/src/test/resources/schema-context-util-test/my-module.yang
new file mode 100644 (file)
index 0000000..2ea1fe2
--- /dev/null
@@ -0,0 +1,72 @@
+module my-module {
+    yang-version 1;
+    namespace "uri:my-module";
+    prefix my;
+
+    import imported-module { prefix imp; revision-date 2014-10-07; }
+
+    revision 2014-10-07 {
+        description
+                "My yang model";
+    }
+
+    grouping my-grouping {
+        container my-container-in-grouping {
+            leaf my-leaf-in-grouping {
+                type int16;
+            }
+        }
+        leaf my-leaf-in-gouping2 {
+            type string;
+        }
+    }
+
+    container my-container {
+        leaf my-leaf-in-container {
+            type int32;
+        }
+        uses my-grouping;
+        list my-list {
+            leaf my-leaf-in-list {
+                type string;
+            }
+            leaf-list my-leaf-list-in-list {
+                type int16;
+            }
+        }
+    }
+
+    rpc my-rpc {
+        input {
+            leaf my-input-leaf {
+                type string;
+            }
+        }
+
+        output {
+            leaf my-output-leaf {
+                type int16;
+            }
+        }
+    }
+
+    notification my-notification {
+        leaf my-notification-leaf {
+            type string;
+        }
+    }
+
+    choice my-choice {
+        case one {
+            leaf my-choice-leaf-one {
+                type string;
+            }
+        }
+        case two {
+            leaf my-choice-leaf-two {
+                type int16;
+            }
+        }
+    }
+}
+