Merge "Do not require namespace repairing"
authorTony Tkacik <ttkacik@cisco.com>
Fri, 5 Sep 2014 12:07:33 +0000 (12:07 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Fri, 5 Sep 2014 12:07:33 +0000 (12:07 +0000)
19 files changed:
code-generator/binding-generator-util/src/main/java/org/opendaylight/yangtools/binding/generator/util/Types.java
common/pom.xml
common/util/src/main/java/org/opendaylight/yangtools/util/DurationStatsTracker.java
common/util/src/main/java/org/opendaylight/yangtools/util/concurrent/QueuedNotificationManager.java
integration-test/pom.xml
pom.xml
websocket/pom.xml
yang/pom.xml
yang/yang-data-codec-gson/src/main/java/org/opendaylight/yangtools/yang/data/codec/gson/JSONNormalizedNodeStreamWriter.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/SchemaTracker.java
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlDocumentUtils.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/SchemaContext.java
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EnumerationTypeTest.java [new file with mode: 0644]
yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java [new file with mode: 0644]
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolver.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/ASTSchemaSource.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/repo/DependencyResolverTest.java

index a6a5ef5a41b699899a42c2a7d1cb615fcc65c5c6..91d56a3562bbcfcdff2f62e263c46e7e05fc3085 100644 (file)
@@ -7,6 +7,7 @@
  */
 package org.opendaylight.yangtools.binding.generator.util;
 
+import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -251,7 +252,7 @@ public final class Types {
         public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {
             super(rawType.getPackageName(), rawType.getName());
             this.rawType = rawType;
-            this.actualTypes = actTypes;
+            this.actualTypes = Arrays.copyOf(actTypes, actTypes.length);
         }
 
     }
index d35521b691b539065310cfea031cabd7a776cdb7..f566097b35067db933ae3bc19be19974535f1b96 100644 (file)
@@ -9,6 +9,12 @@
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
+    <parent>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yangtools-parent</artifactId>
+      <version>0.6.2-SNAPSHOT</version>
+      <relativePath>parent</relativePath>
+    </parent>
 
     <groupId>org.opendaylight.yangtools</groupId>
     <version>0.6.2-SNAPSHOT</version>
index 45ebd01306ced758a627bf0ad8eceac54b9f530d..21690c2864e705817a6245dc2c9ec98ac1b21675 100644 (file)
@@ -46,7 +46,7 @@ public class DurationStatsTracker {
         long newTotal = currentTotal + 1;
 
         // Calculate moving cumulative average.
-        double newAve = currentAve * currentTotal / newTotal + duration / newTotal;
+        double newAve = currentAve * (double)currentTotal / (double)newTotal + (double)duration / (double)newTotal;
 
         averageDuration.compareAndSet(currentAve, newAve);
         totalDurations.compareAndSet(currentTotal, newTotal);
index 27c81a1ee1969436c03a1405a81544c32109e6e0..0e5bd9233189de9d24ffbffe18f257498435c469 100644 (file)
@@ -121,7 +121,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
 
         if( LOG.isTraceEnabled() ) {
             LOG.trace( "{}: submitNotifications for listener {}: {}",
-                       name, listener.getClass(), notifications );
+                       name, listener.toString(), notifications );
         }
 
         ListenerKey<L> key = new ListenerKey<>( listener );
@@ -157,7 +157,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
                         // to the caller.
 
                         LOG.debug( "{}: Submitting NotificationTask for listener {}",
-                                   name, listener.getClass() );
+                                   name, listener.toString() );
 
                         executor.execute( newNotificationTask );
                         break;
@@ -175,12 +175,12 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
             // telling us to quit.
 
             LOG.debug( "{}: Interrupted trying to add to {} listener's queue",
-                       name, listener.getClass() );
+                       name, listener.toString() );
         }
 
         if( LOG.isTraceEnabled() ) {
             LOG.trace( "{}: submitNotifications dine for listener {}",
-                       name, listener.getClass() );
+                       name, listener.toString() );
         }
     }
 
@@ -192,8 +192,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
         List<ListenerNotificationQueueStats> statsList = new ArrayList<>( listenerCache.size() );
         for( NotificationTask task: listenerCache.values() ) {
             statsList.add( new ListenerNotificationQueueStats(
-                    task.listenerKey.getListener().getClass().getName(),
-                    task.notificationQueue.size() ) );
+                    task.listenerKey.toString(), task.notificationQueue.size() ) );
         }
 
         return statsList ;
@@ -249,6 +248,11 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
             ListenerKey<?> other = (ListenerKey<?>) obj;
             return listener == other.listener;
         }
+
+        @Override
+        public String toString() {
+            return listener.toString();
+        }
     }
 
     /**
@@ -305,7 +309,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
 
                         if( LOG.isDebugEnabled() ) {
                             LOG.debug( "{}: Offering notification to the queue for listener {}: {}",
-                                       name, listenerKey.getListener().getClass(), notification );
+                                       name, listenerKey.toString(), notification );
                         }
 
                         if( notificationQueue.offer( notification, 1, TimeUnit.MINUTES ) ) {
@@ -315,7 +319,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
                         LOG.warn(
                             "{}: Timed out trying to offer a notification to the queue for listener {}." +
                             "The queue has reached its capacity of {}",
-                            name, listenerKey.getListener().getClass(), maxQueueCapacity );
+                            name, listenerKey.toString(), maxQueueCapacity );
                     }
                 }
 
@@ -381,7 +385,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
 
                 // The executor is probably shutting down so log as debug.
                 LOG.debug( "{}: Interrupted trying to remove from {} listener's queue",
-                           name, listenerKey.getListener().getClass() );
+                           name, listenerKey.toString() );
             } finally {
 
                 // We're exiting, gracefully or not - either way make sure we always remove
@@ -401,7 +405,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
 
                 if( LOG.isDebugEnabled() ) {
                     LOG.debug( "{}: Invoking listener {} with notification: {}",
-                               name, listenerKey.getListener().getClass(), notification );
+                               name, listenerKey.toString(), notification );
                 }
 
                 listenerInvoker.invokeListener( listenerKey.getListener(), notification );
@@ -412,7 +416,7 @@ public class QueuedNotificationManager<L,N> implements NotificationManager<L,N>
                 // remaining notifications.
 
                 LOG.error( String.format( "%1$s: Error notifying listener %2$s", name,
-                           listenerKey.getListener().getClass() ), e );
+                           listenerKey.toString() ), e );
 
             } catch( Error e ) {
 
index d3f59410967062ebf89dff773ee18bcbe887364c..997549c6ec69c14415ec4f1c41e002bc6e6ab270 100644 (file)
@@ -7,6 +7,13 @@
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
+    <parent>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yangtools-parent</artifactId>
+      <version>0.6.2-SNAPSHOT</version>
+      <relativePath>../common/parent</relativePath>
+    </parent>
+
     <groupId>org.opendaylight.yangtools</groupId>
     <version>0.6.2-SNAPSHOT</version>
     <modelVersion>4.0.0</modelVersion>
diff --git a/pom.xml b/pom.xml
index 7ad393fbc312e5dcc184b7c9d8f7f77f9b17a0c3..ab46986476808eb7474c9a677e40a9e7f5b91d24 100644 (file)
--- a/pom.xml
+++ b/pom.xml
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
+    <parent>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yangtools-parent</artifactId>
+      <version>0.6.2-SNAPSHOT</version>
+      <relativePath>common/parent</relativePath>
+    </parent>
+
     <modelVersion>4.0.0</modelVersion>
     <artifactId>yangtools-aggregator</artifactId>
     <groupId>org.opendaylight.yangtools</groupId>
index 40abaa394d5413b4855b39e0cc0363ae426c3a6e..2edd23b4b130f0e0267c1e0fc392556def4d2fcb 100644 (file)
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     <modelVersion>4.0.0</modelVersion>
-
+    <parent>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yangtools-parent</artifactId>
+      <version>0.6.2-SNAPSHOT</version>
+      <relativePath>../common/parent</relativePath>
+    </parent>
     <groupId>org.opendaylight.yangtools</groupId>
     <version>0.6.2-SNAPSHOT</version>
     <artifactId>websocket-aggregator</artifactId>
index 2e12378abbe72c837203188ccc92c6859202a9d2..269ad48ec10e2658a0574413368be51b78881f9d 100644 (file)
@@ -9,6 +9,12 @@
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 
+    <parent>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>yangtools-parent</artifactId>
+      <version>0.6.2-SNAPSHOT</version>
+      <relativePath>../common/parent</relativePath>
+    </parent>
     <groupId>org.opendaylight.yangtools</groupId>
     <version>0.6.2-SNAPSHOT</version>
     <modelVersion>4.0.0</modelVersion>
index f8b0303802e8e2cf63b83afe056ed28340a62d74..c7755b83bd42ac282f309014ff4d20963a4873e3 100644 (file)
@@ -246,10 +246,10 @@ public class JSONNormalizedNodeStreamWriter implements NormalizedNodeStreamWrite
 
     @Override
     public void startOrderedMapNode(final NodeIdentifier name, final int childSizeHint) throws IOException {
-        tracker.startListItem(name);
+        tracker.startList(name);
 
-        stack.push(new TypeInfo(NodeType.LIST, name.getNodeType().getNamespace()));
         separateElementFromPreviousElement();
+        stack.push(new TypeInfo(NodeType.LIST, name.getNodeType().getNamespace()));
         writeJsonIdentifier(name);
         writeStartList();
         indentRight();
index cb7747fc6c70ea2451629b943d14fc680f5f40db..39181ae49fbf93ae556d1a4e092b671f26cfb2f9 100644 (file)
@@ -9,11 +9,14 @@ package org.opendaylight.yangtools.yang.data.impl.codec;
 
 import com.google.common.annotations.Beta;
 import com.google.common.base.Preconditions;
+
 import java.io.IOException;
 import java.util.ArrayDeque;
 import java.util.Deque;
 import java.util.HashSet;
+
 import javax.xml.stream.XMLStreamWriter;
+
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -117,7 +120,7 @@ public final class SchemaTracker {
         return schema;
     }
 
-    public void startList(final NodeIdentifier name) {
+    public void startList(final PathArgument name) {
         final SchemaNode schema = getSchema(name);
         Preconditions.checkArgument(schema instanceof ListSchemaNode, "Node %s is not a list", schema.getPath());
         schemaStack.push(schema);
index 68fc432e96952789b42d8164e7e25d39b347b138..d944842bf983ca534804929c2cd3b28143b2f577 100644 (file)
@@ -57,6 +57,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Attr;
@@ -65,10 +66,6 @@ import org.w3c.dom.Element;
 import org.w3c.dom.NodeList;
 
 public class XmlDocumentUtils {
-    private final static String RPC_REPLY_LOCAL_NAME = "rpc-reply";
-    private final static String RPC_REPLY_NAMESPACE = "urn:ietf:params:xml:ns:netconf:base:1.0";
-    private final static QName RPC_REPLY_QNAME = QName.create(URI.create(RPC_REPLY_NAMESPACE), null, RPC_REPLY_LOCAL_NAME);
-
     private static class ElementWithSchemaContext {
         Element element;
         SchemaContext schemaContext;
@@ -87,8 +84,9 @@ public class XmlDocumentUtils {
         }
     }
 
-    public static final QName OPERATION_ATTRIBUTE_QNAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), null, "operation");
-    private static final Logger logger = LoggerFactory.getLogger(XmlDocumentUtils.class);
+    public static final QName OPERATION_ATTRIBUTE_QNAME = QName.create(SchemaContext.NAME, "operation");
+    private static final QName RPC_REPLY_QNAME = QName.create(SchemaContext.NAME, "rpc-reply");
+    private static final Logger LOG = LoggerFactory.getLogger(XmlDocumentUtils.class);
     private static final XMLOutputFactory FACTORY = XMLOutputFactory.newFactory();
 
     /**
@@ -119,7 +117,7 @@ public class XmlDocumentUtils {
             writer.close();
             return (Document)result.getNode();
         } catch (XMLStreamException e) {
-            logger.error("Failed to serialize data {}", data, e);
+            LOG.error("Failed to serialize data {}", data, e);
             return null;
         }
     }
@@ -154,7 +152,7 @@ public class XmlDocumentUtils {
             writer.close();
             return (Document)result.getNode();
         } catch (XMLStreamException e) {
-            logger.error("Failed to serialize data {}", data, e);
+            LOG.error("Failed to serialize data {}", data, e);
             return null;
         }
     }
@@ -230,22 +228,22 @@ public class XmlDocumentUtils {
 
     protected static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafSchemaNode schema,
             final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
-        TypeDefinitionAwareCodec<? extends Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
-        String text = xmlElement.getTextContent();
-        Object value = null;
-        if (codec != null) {
-            value = codec.deserialize(text);
-        }
         final TypeDefinition<?> baseType = XmlUtils.resolveBaseTypeFrom(schema.getType());
+        final String text = xmlElement.getTextContent();
+        final Object value;
 
-        if (baseType instanceof org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType) {
-            value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx);
-        } else if(baseType instanceof IdentityrefTypeDefinition){
-            value = InstanceIdentifierForXmlCodec.toIdentity(xmlElement.getTextContent(), xmlElement, schemaCtx);
-        }
-
-        if (value == null) {
-            value = xmlElement.getTextContent();
+        if (baseType instanceof InstanceIdentifierType) {
+            value = InstanceIdentifierForXmlCodec.deserialize(xmlElement, schemaCtx);
+        } else if (baseType instanceof IdentityrefTypeDefinition) {
+            value = InstanceIdentifierForXmlCodec.toIdentity(text, xmlElement, schemaCtx);
+        } else {
+            final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(schema.getType());
+            if (codec == null) {
+                LOG.info("No codec for schema {}, falling back to text", schema);
+                value = text;
+            } else {
+                value = codec.deserialize(text);
+            }
         }
 
         Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
@@ -254,17 +252,20 @@ public class XmlDocumentUtils {
 
     private static Node<?> toSimpleNodeWithType(final Element xmlElement, final LeafListSchemaNode schema,
             final XmlCodecProvider codecProvider,final SchemaContext schemaCtx) {
-        TypeDefinitionAwareCodec<? extends Object, ? extends TypeDefinition<?>> codec = codecProvider.codecFor(schema.getType());
-        String text = xmlElement.getTextContent();
-        Object value = null;
-        if (codec != null) {
-            value = codec.deserialize(text);
-        }
-        if (schema.getType() instanceof org.opendaylight.yangtools.yang.model.util.InstanceIdentifierType) {
-            value = InstanceIdentifierForXmlCodec.deserialize(xmlElement,schemaCtx);
-        }
-        if (value == null) {
-            value = xmlElement.getTextContent();
+        final Object value;
+
+        if (schema.getType() instanceof InstanceIdentifierType) {
+            value = InstanceIdentifierForXmlCodec.deserialize(xmlElement, schemaCtx);
+        } else {
+            final TypeDefinitionAwareCodec<?, ?> codec = codecProvider.codecFor(schema.getType());
+            final String text = xmlElement.getTextContent();
+
+            if (codec == null) {
+                LOG.info("No codec for schema {}, falling back to text", schema);
+                value = text;
+            } else {
+                value = codec.deserialize(text);
+            }
         }
 
         Optional<ModifyAction> modifyAction = getModifyOperationFromAttributes(xmlElement);
index 2bb1d993d9f12dcb2f486aa5064b0129d7177386..dec334dc7f420404deb81fed0a1bdb273c17a8b0 100644 (file)
@@ -8,12 +8,11 @@
 package org.opendaylight.yangtools.yang.model.api;
 
 import com.google.common.base.Optional;
-import javax.annotation.concurrent.Immutable;
-import org.opendaylight.yangtools.yang.common.QName;
-
 import java.net.URI;
 import java.util.Date;
 import java.util.Set;
+import javax.annotation.concurrent.Immutable;
+import org.opendaylight.yangtools.yang.common.QName;
 
 /**
  * The interface represents static view of compiled yang files,
@@ -25,7 +24,9 @@ import java.util.Set;
  */
 @Immutable
 public interface SchemaContext extends ContainerSchemaNode {
-
+    /**
+     * QName of NETCONF top-level data node.
+     */
     public static final QName NAME = QName.create(URI.create("urn:ietf:params:xml:ns:netconf:base:1.0"), null, "data");
 
     /**
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/BitsTypeTest.java
new file mode 100644 (file)
index 0000000..47e8a76
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.model.util;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
+
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class BitsTypeTest {
+
+    @Mock
+    private BitsTypeDefinition.Bit bit;
+
+    @Test
+    public void canCreateBitsType(){
+        MockitoAnnotations.initMocks(this);
+
+        QName qName = QName.create("TestQName");
+        SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+        List<BitsTypeDefinition.Bit> listBit = Collections.singletonList(bit);
+        BitsType bitsType = BitsType.create(schemaPath, listBit);
+
+        assertNotEquals("Description is not null", null, bitsType.getDescription());
+        assertEquals("QName", BaseTypes.BITS_QNAME, bitsType.getQName());
+        assertEquals("Should be empty string", "", bitsType.getUnits());
+        assertNotEquals("Description should not be null", null, bitsType.toString());
+        assertNotEquals("Reference is not null", null, bitsType.getReference());
+        assertEquals("BaseType should be null", null, bitsType.getBaseType());
+        assertEquals("Default value should be list of bit", listBit, bitsType.getDefaultValue());
+        assertEquals("getPath should equal schemaPath", schemaPath, bitsType.getPath());
+        assertEquals("Status should be CURRENT", Status.CURRENT, bitsType.getStatus());
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, bitsType.getUnknownSchemaNodes());
+        assertEquals("Values should be [enumPair]", listBit, bitsType.getBits());
+
+        assertEquals("Hash code of bitsType should be equal",
+                bitsType.hashCode(), bitsType.hashCode());
+        assertNotEquals("bitsType shouldn't equal to null", null, bitsType);
+        assertEquals("bitsType should equals to itself", bitsType, bitsType);
+        assertNotEquals("bitsType shouldn't equal to object of other type", "str", bitsType);
+
+    }
+
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/DataNodeIteratorTest.java
new file mode 100644 (file)
index 0000000..f5b2705
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * 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.model.util;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
+
+import java.util.Collections;
+import java.util.NoSuchElementException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.Mockito.mock;
+
+public class DataNodeIteratorTest {
+
+    private DataNodeIterator dataNodeIterator;
+
+    @Before
+    public void setUp() {
+        DataNodeContainer dataNodeContainer = mock(DataNodeContainer.class);
+        this.dataNodeIterator = new DataNodeIterator(dataNodeContainer);
+    }
+
+    @Test(expected=IllegalArgumentException.class)
+    public void createDataNodeIteratorWithNullArgument() {
+        new DataNodeIterator(null);
+    }
+
+    @Test(expected=UnsupportedOperationException.class)
+    public void removeFromEmptyDataNodeContainer() {
+        dataNodeIterator.remove();
+    }
+
+    @Test(expected = NoSuchElementException.class)
+    public void tryNextOnEmptyDataContainer() {
+        dataNodeIterator.next();
+    }
+
+    @Test
+    public void createDataNodeIteratorWith() {
+        assertFalse("Has no next", dataNodeIterator.hasNext());
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allChoices());
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allContainers());
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allTypedefs());
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allGroupings());
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, dataNodeIterator.allLists());
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EnumerationTypeTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/EnumerationTypeTest.java
new file mode 100644 (file)
index 0000000..986c27b
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * 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.model.util;
+
+import com.google.common.base.Optional;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+
+import java.util.Collections;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+
+public class EnumerationTypeTest {
+
+    @Mock private EnumTypeDefinition.EnumPair enumPair;
+
+    @Test
+    public void canCreateEnumerationType(){
+        MockitoAnnotations.initMocks(this);
+
+        QName qName = QName.create("TestQName");
+        SchemaPath schemaPath = SchemaPath.create(Collections.singletonList(qName), true);
+
+        List<EnumTypeDefinition.EnumPair> listEnumPair = Collections.singletonList(enumPair);
+        Optional<EnumTypeDefinition.EnumPair> defaultValue = Optional.of(enumPair);
+
+        EnumerationType enumerationType = EnumerationType.create(schemaPath, listEnumPair, defaultValue);
+
+        assertNotEquals("Description is not null", null, enumerationType.getDescription());
+        assertEquals("QName", BaseTypes.ENUMERATION_QNAME, enumerationType.getQName());
+        assertEquals("Should be empty string", "", enumerationType.getUnits());
+        assertNotEquals("Description should not be null", null, enumerationType.toString());
+        assertNotEquals("Reference is not null", null, enumerationType.getReference());
+        assertEquals("BaseType should be null", null, enumerationType.getBaseType());
+        assertEquals("Default value should be enumPair", enumPair, enumerationType.getDefaultValue());
+        assertEquals("getPath should equal schemaPath", schemaPath, enumerationType.getPath());
+        assertEquals("Status should be CURRENT", Status.CURRENT, enumerationType.getStatus());
+        assertEquals("Should be empty list", Collections.EMPTY_LIST, enumerationType.getUnknownSchemaNodes());
+        assertEquals("Values should be [enumPair]", listEnumPair, enumerationType.getValues());
+
+        assertEquals("Hash code of enumerationType should be equal",
+                enumerationType.hashCode(), enumerationType.hashCode());
+        assertNotEquals("EnumerationType shouldn't equal to null", null, enumerationType);
+        assertEquals("EnumerationType should equals to itself", enumerationType, enumerationType);
+        assertNotEquals("EnumerationType shouldn't equal to object of other type", "str", enumerationType);
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java b/yang/yang-model-util/src/test/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtilTest.java
new file mode 100644 (file)
index 0000000..93038e2
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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.model.util;
+
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.common.QName;
+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 java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+
+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));
+    }
+}
\ No newline at end of file
index d9b74fe93aff48079fc33dc3660d8dd83da79da4..972f4689d547e2c491f1c774183946fe5d5f94d0 100644 (file)
@@ -7,7 +7,13 @@
  */
 package org.opendaylight.yangtools.yang.parser.repo;
 
-import com.google.common.collect.Sets;
+import com.google.common.base.Objects;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ImmutableMultimap;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimap;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -15,7 +21,6 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.ModuleImport;
 import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
@@ -23,12 +28,6 @@ import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ImmutableMultimap;
-import com.google.common.collect.Multimap;
-
 /**
  * Inter-module dependency resolved. Given a set of schema source identifiers and their
  * corresponding dependency information, the {@link #create(Map)} method creates a
@@ -53,7 +52,7 @@ final class DependencyResolver {
     }
 
     private static SourceIdentifier findWildcard(final Iterable<SourceIdentifier> haystack, final String needle) {
-        for (SourceIdentifier r : haystack) {
+        for (final SourceIdentifier r : haystack) {
             if (r.getName().equals(needle)) {
                 return r;
             }
@@ -77,9 +76,10 @@ final class DependencyResolver {
 
 
 
-    public static final DependencyResolver create(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
+    public static DependencyResolver create(final Map<SourceIdentifier, YangModelDependencyInfo> depInfo) {
         final Collection<SourceIdentifier> resolved = new ArrayList<>(depInfo.size());
         final Collection<SourceIdentifier> pending = new ArrayList<>(depInfo.keySet());
+        final Map<SourceIdentifier, BelongsToDependency> submodules = Maps.newHashMap();
 
         boolean progress;
         do {
@@ -92,16 +92,15 @@ final class DependencyResolver {
 
                 boolean okay = true;
 
-                Set<ModuleImport> dependencies = dep.getDependencies();
+                final Set<ModuleImport> dependencies = dep.getDependencies();
 
-                // in case of submodule, make its parent also a dependency
+                // in case of submodule, remember belongs to
                 if(dep instanceof YangModelDependencyInfo.SubmoduleDependencyInfo) {
                     final String parent = ((YangModelDependencyInfo.SubmoduleDependencyInfo) dep).getParentModule();
-                    dependencies = Sets.newHashSet(dependencies);
-                    dependencies.add(new BelongsToDependency(parent));
+                    submodules.put(id, new BelongsToDependency(parent));
                 }
 
-                for (ModuleImport mi : dependencies) {
+                for (final ModuleImport mi : dependencies) {
                     if (!isKnown(resolved, mi)) {
                         LOG.debug("Source {} is missing import {}", id, mi);
                         okay = false;
@@ -118,11 +117,21 @@ final class DependencyResolver {
             }
         } while (progress);
 
+        /// Additional check only for belongs-to statement
+        for (final SourceIdentifier sourceIdentifier : submodules.keySet()) {
+            final BelongsToDependency belongs = submodules.get(sourceIdentifier);
+            if (!isKnown(resolved, belongs)) {
+                LOG.debug("Source {} is missing parent {}", sourceIdentifier, belongs);
+                pending.add(sourceIdentifier);
+                resolved.remove(sourceIdentifier);
+            }
+        }
+
         if (!pending.isEmpty()) {
             final Multimap<SourceIdentifier, ModuleImport> imports = ArrayListMultimap.create();
-            for (SourceIdentifier id : pending) {
+            for (final SourceIdentifier id : pending) {
                 final YangModelDependencyInfo dep = depInfo.get(id);
-                for (ModuleImport mi : dep.getDependencies()) {
+                for (final ModuleImport mi : dep.getDependencies()) {
                     if (!isKnown(pending, mi) && !isKnown(resolved, mi)) {
                         imports.put(id, mi);
                     }
@@ -196,5 +205,12 @@ final class DependencyResolver {
         public String getPrefix() {
             return null;
         }
+
+        @Override
+        public String toString() {
+            return Objects.toStringHelper(this)
+                    .add("parent", parent)
+                    .toString();
+        }
     }
 }
index 25e08c21d2edc7d74e145b41a09a78e619a17cf9..9a1cd57005b8146029d924c692df3da1ad629067 100644 (file)
@@ -30,19 +30,22 @@ import org.opendaylight.yangtools.yang.parser.impl.util.YangModelDependencyInfo;
 public final class ASTSchemaSource implements SchemaSourceRepresentation {
     public static final Function<ASTSchemaSource, SourceIdentifier> GET_IDENTIFIER = new Function<ASTSchemaSource, SourceIdentifier>() {
         @Override
-        public SourceIdentifier apply(final ASTSchemaSource input) {
+        public SourceIdentifier apply(@Nonnull final ASTSchemaSource input) {
+            Preconditions.checkNotNull(input);
             return input.getIdentifier();
         }
     };
     public static final Function<ASTSchemaSource, YangModelDependencyInfo> GET_DEPINFO = new Function<ASTSchemaSource, YangModelDependencyInfo>() {
         @Override
-        public YangModelDependencyInfo apply(final ASTSchemaSource input) {
+        public YangModelDependencyInfo apply(@Nonnull final ASTSchemaSource input) {
+            Preconditions.checkNotNull(input);
             return input.getDependencyInformation();
         }
     };
     public static final Function<ASTSchemaSource, ParserRuleContext> GET_AST = new Function<ASTSchemaSource, ParserRuleContext>() {
         @Override
-        public ParserRuleContext apply(final ASTSchemaSource input) {
+        public ParserRuleContext apply(@Nonnull final ASTSchemaSource input) {
+            Preconditions.checkNotNull(input);
             return input.getAST();
         }
     };
@@ -52,11 +55,11 @@ public final class ASTSchemaSource implements SchemaSourceRepresentation {
     private final SourceIdentifier id;
     private final String text;
 
-    private ASTSchemaSource(final @Nonnull SourceIdentifier id, @Nonnull final ParserRuleContext tree, final @Nonnull YangModelDependencyInfo depInfo, final @Nonnull String text) {
+    private ASTSchemaSource(final @Nonnull SourceIdentifier id, @Nonnull final ParserRuleContext tree, final @Nonnull YangModelDependencyInfo depInfo, final String text) {
         this.depInfo = Preconditions.checkNotNull(depInfo);
         this.tree = Preconditions.checkNotNull(tree);
         this.id = Preconditions.checkNotNull(id);
-        this.text = Preconditions.checkNotNull(text);
+        this.text = text;
     }
 
     /**
index 3f1265b0e1c63acd99cc36e55ee1b74dcf6e535d..a8aef6984b964177e98270b7492b31b254fb4e40 100644 (file)
@@ -44,10 +44,27 @@ public class DependencyResolverTest {
 
         final DependencyResolver resolved = DependencyResolver.create(map);
 
+        assertEquals(2, resolved.getResolvedSources().size());
         assertEquals(1, resolved.getUnresolvedSources().size());
         assertEquals(0, resolved.getUnsatisfiedImports().size());
     }
 
+    @Test
+    public void testSubmodule() throws Exception {
+        final Map<SourceIdentifier, YangModelDependencyInfo> map = new HashMap<>();
+
+        addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/subfoo.yang")));
+        addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/foo.yang")));
+        addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/bar.yang")));
+        addToMap(map, YangModelDependencyInfo.ModuleDependencyInfo.fromInputStream(getClass().getResourceAsStream("/model/baz.yang")));
+
+        final DependencyResolver resolved = DependencyResolver.create(map);
+
+        assertEquals(4, resolved.getResolvedSources().size());
+        assertEquals(0, resolved.getUnresolvedSources().size());
+        assertEquals(0, resolved.getUnsatisfiedImports().size());
+    }
+
     private void addToMap(final Map<SourceIdentifier, YangModelDependencyInfo> map, final YangModelDependencyInfo yangModelDependencyInfo) {
         map.put(getSourceId(yangModelDependencyInfo), yangModelDependencyInfo);
     }