From d7fa125266964d5f8a65f116c332e1ec1449a429 Mon Sep 17 00:00:00 2001 From: Peter Bandzi Date: Thu, 11 Sep 2014 14:04:41 +0200 Subject: [PATCH] very basic tests for yang-binding-util Change-Id: I7f5b646062dcb3619cd7912d37ef8574db56c5c6 Signed-off-by: Peter Bandzi --- yang/yang-binding/pom.xml | 5 ++ .../binding/util/BindingReflectionsTest.java | 34 +++++++++ .../util/DataObjectReadingUtilTest.java | 72 +++++++++++++++++++ 3 files changed, 111 insertions(+) create mode 100644 yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/BindingReflectionsTest.java create mode 100644 yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/DataObjectReadingUtilTest.java diff --git a/yang/yang-binding/pom.xml b/yang/yang-binding/pom.xml index f4efbc3c7a..ad339e8668 100644 --- a/yang/yang-binding/pom.xml +++ b/yang/yang-binding/pom.xml @@ -43,5 +43,10 @@ junit test + + org.mockito + mockito-core + test + 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 index 0000000000..694c807c1f --- /dev/null +++ b/yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/BindingReflectionsTest.java @@ -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 index 0000000000..e2400f9f3d --- /dev/null +++ b/yang/yang-binding/src/test/java/org/opendaylight/yangtools/yang/binding/util/DataObjectReadingUtilTest.java @@ -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 pathNull; + @Mock private Map.Entry, DataObject> entryNull; + @Mock private DataObject mockedDataObject; + private InstanceIdentifier path; + private Map.Entry, DataObject> entry; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + + path = InstanceIdentifier.builder(Nodes.class).toInstance(); + ImmutableMap map = ImmutableMap., + 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 -- 2.36.6