Test for class RefineHolder.java
authorJozef Gloncak <jgloncak@cisco.com>
Fri, 13 Sep 2013 07:01:42 +0000 (09:01 +0200)
committerMartin Vitez <mvitez@cisco.com>
Tue, 17 Sep 2013 09:26:30 +0000 (11:26 +0200)
+ test for identityref built-in YANG type
+ test for NodeWrappedType class
+ test for BitImpl was added
+ test for MustDefinitionImpl class

Change-Id: Ib64cbfafcc88a6de56b5a132736081a649f7d8e7
Signed-off-by: Jozef Gloncak <jgloncak@cisco.com>
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java [new file with mode: 0644]
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/NodeWrappedTypeTest.java [new file with mode: 0644]
code-generator/binding-generator-impl/src/test/resources/identityref.yang [new file with mode: 0644]

diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java
new file mode 100644 (file)
index 0000000..1521f27
--- /dev/null
@@ -0,0 +1,101 @@
+/*
+ * Copyright (c) 2013 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.sal.binding.generator.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
+import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+public class IdentityrefTypeTest {
+
+    private static List<File> testModels = null;
+
+    @Before
+    public void loadTestResources() {
+        String folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").getPath();
+        File folderFile = new File(folderPath);
+        testModels = new ArrayList<File>();
+
+        if (folderFile.isFile()) {
+            testModels.add(folderFile);
+        } else {
+            for (File file : folderFile.listFiles()) {
+                if (file.isFile()) {
+                    testModels.add(file);
+                }
+            }
+        }
+    }
+
+    /**
+     * Test mainly for the method
+     * {@link TypeProviderImpl#provideTypeForIdentityref()
+     * provideTypeForIdentityref}
+     */
+    @Test
+    public void testIdentityrefYangBuiltInType() {
+        loadTestResources();
+        final YangModelParser parser = new YangParserImpl();
+        final Set<Module> modules = parser.parseYangModels(testModels);
+        final SchemaContext context = parser.resolveSchemaContext(modules);
+
+        assertNotNull(context);
+        final BindingGenerator bindingGen = new BindingGeneratorImpl();
+        final List<Type> genTypes = bindingGen.generateTypes(context);
+
+        GeneratedType moduleGenType = null;
+        for (Type type : genTypes) {
+            if (type.getName().equals("ModuleIdentityrefData")) {
+                if (type instanceof GeneratedType) {
+                    moduleGenType = (GeneratedType) type;
+                }
+            }
+        }
+
+        assertNotNull("Generated type for whole module wasn't found", moduleGenType);
+
+        String typeName = null;
+        String actualTypeName = "";
+        int numOfActualTypes = 0;
+        List<MethodSignature> methodSignatures = moduleGenType.getMethodDefinitions();
+        for (MethodSignature methodSignature : methodSignatures) {
+            if (methodSignature.getName().equals("getLf")) {
+                Type returnType = methodSignature.getReturnType();
+                if (returnType instanceof ParameterizedType) {
+                    typeName = returnType.getName();
+                    Type[] actualTypes = ((ParameterizedType) returnType).getActualTypeArguments();
+                    numOfActualTypes = actualTypes.length;
+                    actualTypeName = actualTypes[0].getName();
+                }
+            }
+        }
+        assertNotNull("The method 'getLf' wasn't found", typeName);
+        assertEquals("Return type has incorrect name", "Class", typeName);
+        assertEquals("Incorrect number of type parameters", 1, numOfActualTypes);
+        assertEquals("Return type has incorrect actual parameter", "SomeIdentity", actualTypeName);
+
+    }
+
+}
diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/NodeWrappedTypeTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/NodeWrappedTypeTest.java
new file mode 100644 (file)
index 0000000..d31f2a4
--- /dev/null
@@ -0,0 +1,24 @@
+package org.opendaylight.yangtools.sal.binding.yang.types;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class NodeWrappedTypeTest {
+
+    @Test
+    public void test() {
+        NodeWrappedType nwt1 = new NodeWrappedType("obj1");
+        NodeWrappedType nwt2 = new NodeWrappedType("obj2");
+        NodeWrappedType nwt3 = new NodeWrappedType("obj1");
+        String str = "obj3";
+
+        assertTrue("Node nwt1 should equal to itself.", nwt1.equals(nwt1));
+        assertFalse("It can't be possible to compare nwt with string.", nwt1.equals(str));
+        assertFalse("nwt1 shouldn't equal to nwt2.", nwt1.equals(nwt2));
+        assertTrue("Node nwt1 should equal to nwt3.", nwt1.equals(nwt3));
+
+        assertEquals("toString method is returning incorrect value.", "NodeWrappedType{wrappedType=obj1}",
+                nwt1.toString());
+    }
+}
diff --git a/code-generator/binding-generator-impl/src/test/resources/identityref.yang b/code-generator/binding-generator-impl/src/test/resources/identityref.yang
new file mode 100644 (file)
index 0000000..1255185
--- /dev/null
@@ -0,0 +1,20 @@
+module module-identityref {
+
+    namespace "urn:identityref:module";
+    prefix "sbd";
+
+    organization "OPEN DAYLIGHT";
+    contact "http://www.opendaylight.org/";
+
+    revision 2013-11-09 {
+    }
+
+    identity some-identity {
+    }
+
+    leaf lf {
+        type identityref {
+            base "some-identity";
+        }
+    }
+}
\ No newline at end of file