Merge "BUG-1687, BUG-1689 FIx belongs-to resolution in dependency resolver"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 4 Sep 2014 09:58:15 +0000 (09:58 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 4 Sep 2014 09:58:15 +0000 (09:58 +0000)
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]

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