Merge "Added test suite for parser builder implementation"
authorTony Tkacik <ttkacik@cisco.com>
Wed, 22 Oct 2014 13:08:57 +0000 (13:08 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 22 Oct 2014 13:08:57 +0000 (13:08 +0000)
23 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/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/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;
+            }
+        }
+    }
+}
+