Expand yang-data-api test suite 61/27061/2
authorRobert Varga <rovarga@cisco.com>
Wed, 16 Sep 2015 16:02:29 +0000 (18:02 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 17 Sep 2015 08:24:34 +0000 (08:24 +0000)
This adds some trivial tests.

Change-Id: I76b2ed6d76657f9687d7ab1b449857f44ea22d67
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-data-api/pom.xml
yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/PathArgumentListTest.java [new file with mode: 0644]
yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/TreeNodeFactoryTest.java [new file with mode: 0644]
yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/VersionTest.java [new file with mode: 0644]

index 73505cd9977ba7c4f4ed73583946bd19df13d779..a5749544eaf12f2f6211dea1e37efec91f126fea 100644 (file)
@@ -47,5 +47,9 @@
           <artifactId>junit</artifactId>
           <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+        </dependency>
     </dependencies>
 </project>
diff --git a/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/PathArgumentListTest.java b/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/PathArgumentListTest.java
new file mode 100644 (file)
index 0000000..1e30e8a
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright (c) 2015 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.data.api;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import com.google.common.collect.UnmodifiableIterator;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+
+public class PathArgumentListTest {
+    private static final class TestClass extends PathArgumentList {
+        @Override
+        public UnmodifiableIterator<PathArgument> iterator() {
+            return null;
+        }
+
+        @Override
+        public PathArgument get(final int index) {
+            return null;
+        }
+
+        @Override
+        public int size() {
+            return 0;
+        }
+    }
+
+    @Test
+    public void testIsEmpty() {
+        assertFalse(new TestClass().isEmpty());
+    }
+
+    @Test
+    public void testProtections() {
+        final PathArgumentList l = new TestClass();
+
+        try {
+            l.remove(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+        }
+
+        try {
+            l.addAll(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+        }
+
+        try {
+            l.removeAll(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+        }
+
+        try {
+            l.retainAll(null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+        }
+
+        try {
+            l.clear();
+            fail();
+        } catch (UnsupportedOperationException e) {
+        }
+
+        try {
+            l.addAll(0, null);
+            fail();
+        } catch (UnsupportedOperationException e) {
+        }
+
+    }
+}
diff --git a/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/TreeNodeFactoryTest.java b/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/TreeNodeFactoryTest.java
new file mode 100644 (file)
index 0000000..0e4c7de
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2015 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.data.api.schema.tree.spi;
+
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+
+public class TreeNodeFactoryTest {
+
+    private static void checkTreeNode(final TreeNode node, final NormalizedNode<?, ?> data, final Version version) {
+        assertSame(data, node.getData());
+        assertSame(version, node.getSubtreeVersion());
+        assertSame(version, node.getVersion());
+    }
+
+    @Test
+    public void testNormalizedNodeContainer() {
+        final ContainerNode data = Mockito.mock(ContainerNode.class);
+        final Version version = Version.initial();
+        final TreeNode node = TreeNodeFactory.createTreeNode(data, version);
+
+        assertTrue(node instanceof LazyContainerNode);
+        checkTreeNode(node, data, version);
+    }
+
+    @Test
+    public void testOrderedNodeContainer() {
+        final OrderedMapNode data = Mockito.mock(OrderedMapNode.class);
+        final Version version = Version.initial();
+        final TreeNode node = TreeNodeFactory.createTreeNode(data, version);
+
+        assertTrue(node instanceof LazyContainerNode);
+        checkTreeNode(node, data, version);
+    }
+
+    @Test
+    public void testLeaf() {
+        final LeafNode<?> data = Mockito.mock(LeafNode.class);
+        final Version version = Version.initial();
+        final TreeNode node = TreeNodeFactory.createTreeNode(data, version);
+
+        assertTrue(node instanceof ValueNode);
+        checkTreeNode(node, data, version);
+    }
+}
diff --git a/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/VersionTest.java b/yang/yang-data-api/src/test/java/org/opendaylight/yangtools/yang/data/api/schema/tree/spi/VersionTest.java
new file mode 100644 (file)
index 0000000..09b26cd
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2015 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.data.api.schema.tree.spi;
+
+import static org.junit.Assert.assertFalse;
+import org.junit.Test;
+
+public class VersionTest {
+
+    @Test
+    public void testInitial() {
+        final Version v1 = Version.initial();
+        final Version v2 = Version.initial();
+
+        assertFalse(v1.equals(v2));
+        assertFalse(v2.equals(v1));
+     }
+
+    @Test
+    public void testNext() {
+        final Version v1 = Version.initial();
+        final Version v2 = v1.next();
+        final Version v3 = v2.next();
+        final Version v4 = v1.next();
+
+        assertFalse(v3.equals(v4));
+        assertFalse(v4.equals(v3));
+    }
+}