very basic tests for yang-binding-util 42/11042/1
authorPeter Bandzi <pbandzi@cisco.com>
Thu, 11 Sep 2014 12:04:41 +0000 (14:04 +0200)
committerPeter Bandzi <pbandzi@cisco.com>
Thu, 11 Sep 2014 12:06:56 +0000 (14:06 +0200)
Change-Id: I7f5b646062dcb3619cd7912d37ef8574db56c5c6
Signed-off-by: Peter Bandzi <pbandzi@cisco.com>
yang/yang-binding/pom.xml
yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/BindingReflectionsTest.java [new file with mode: 0644]
yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/DataObjectReadingUtilTest.java [new file with mode: 0644]

index f4efbc3c7aeadadc5cd79f620ee463c49eeb98bb..ad339e8668b02542d6363eaf2bb11eb0597f2065 100644 (file)
             <artifactId>junit</artifactId>
             <scope>test</scope>
         </dependency>
+        <dependency>
+            <groupId>org.mockito</groupId>
+            <artifactId>mockito-core</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 </project>
diff --git a/yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/BindingReflectionsTest.java b/yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/BindingReflectionsTest.java
new file mode 100644 (file)
index 0000000..694c807
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * 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.binding.util;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+
+import java.util.Collections;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class BindingReflectionsTest {
+
+    @Test
+    public void testBindingWithDummyObject() {
+        assertEquals("Package name should be equal to string", "org.opendaylight.yang.gen.v1.test.rev990939",
+                BindingReflections.getModelRootPackageName("org.opendaylight.yang.gen.v1.test.rev990939"));
+        assertEquals("ModuleInfoClassName should be equal to string", "test.$YangModuleInfoImpl",
+                BindingReflections.getModuleInfoClassName("test"));
+        assertEquals("Module info should be empty Set", Collections.EMPTY_SET,
+                BindingReflections.loadModuleInfos());
+        assertFalse("Should not be RpcType", BindingReflections.isRpcType(DataObject.class));
+        assertFalse("Should not be AugmentationChild", BindingReflections.isAugmentationChild(DataObject.class));
+        assertTrue("Should be BindingClass", BindingReflections.isBindingClass(DataObject.class));
+        assertFalse("Should not be Notification", BindingReflections.isNotification(DataObject.class));
+    }
+}
\ No newline at end of file
diff --git a/yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/DataObjectReadingUtilTest.java b/yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/DataObjectReadingUtilTest.java
new file mode 100644 (file)
index 0000000..e2400f9
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * 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.binding.util;
+
+import com.google.common.collect.ImmutableMap;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.test.mock.Nodes;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import static org.junit.Assert.assertTrue;
+
+public class DataObjectReadingUtilTest {
+    @Mock private InstanceIdentifier<? extends DataObject> pathNull;
+    @Mock private Map.Entry<InstanceIdentifier<? extends DataObject>, DataObject> entryNull;
+    @Mock private DataObject mockedDataObject;
+    private InstanceIdentifier<? extends DataObject> path;
+    private Map.Entry<InstanceIdentifier<? extends DataObject>, DataObject> entry;
+
+    @Before
+    public void setup() {
+        MockitoAnnotations.initMocks(this);
+
+        path = InstanceIdentifier.builder(Nodes.class).toInstance();
+        ImmutableMap map = ImmutableMap.<InstanceIdentifier<? extends DataObject>,
+                DataObject>builder().put(path, mockedDataObject).build();
+
+        Set entries = map.entrySet();
+        Iterator it = entries.iterator();
+        while(it.hasNext()) {
+            entry = (Map.Entry)it.next();
+        }
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testReadDataParentNull() {
+        DataObjectReadingUtil.readData(entryNull.getValue(), (InstanceIdentifier) entryNull.getKey(), pathNull);
+    }
+
+    @Test(expected = IllegalArgumentException.class)
+    public void testReadDataParentPathNull() {
+        DataObjectReadingUtil.readData(entry.getValue(), (InstanceIdentifier) entryNull.getKey(), pathNull);
+    }
+
+    @Test
+    public void testReadDataWithThreeParams() {
+        assertTrue("Check if contains key",
+                DataObjectReadingUtil.readData(entry.getValue(),
+                        (InstanceIdentifier) entry.getKey(), path).containsKey(entry.getKey()));
+
+        assertTrue("Check if contains value",
+                DataObjectReadingUtil.readData(entry.getValue(),
+                        (InstanceIdentifier) entry.getKey(), path).containsValue(entry.getValue()));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testReadDataWithTwoParams() {
+        DataObjectReadingUtil.readData(mockedDataObject, DataObject.class);
+    }
+}
\ No newline at end of file