From: Jozef Gloncak Date: Fri, 13 Sep 2013 07:01:42 +0000 (+0200) Subject: Test for class RefineHolder.java X-Git-Tag: release/beryllium~784^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=35b016693352ff7a9fb6e53a3357e4ed8fc39e8a;p=mdsal.git Test for class RefineHolder.java + 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 --- 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 index 0000000000..1521f27b39 --- /dev/null +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/IdentityrefTypeTest.java @@ -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 testModels = null; + + @Before + public void loadTestResources() { + String folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").getPath(); + File folderFile = new File(folderPath); + testModels = new ArrayList(); + + 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 modules = parser.parseYangModels(testModels); + final SchemaContext context = parser.resolveSchemaContext(modules); + + assertNotNull(context); + final BindingGenerator bindingGen = new BindingGeneratorImpl(); + final List 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 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 index 0000000000..d31f2a43ae --- /dev/null +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/yang/types/NodeWrappedTypeTest.java @@ -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 index 0000000000..1255185fba --- /dev/null +++ b/code-generator/binding-generator-impl/src/test/resources/identityref.yang @@ -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