From: Filip Gregor Date: Fri, 13 May 2016 09:42:05 +0000 (+0200) Subject: Bug 5882: Wrong placement of deprecated annotation X-Git-Tag: release/beryllium-sr3~9 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=mdsal.git;a=commitdiff_plain;h=030f7d42bfd1e63f50387c07e2432daa1efd17ed Bug 5882: Wrong placement of deprecated annotation Removed @Deprecated from generated Yang in javadoc added deprecated annotation for generated getters and typedefs Change-Id: I251faabd0cdc051a646ead6f4bf65a17509b90c5 Signed-off-by: Filip Gregor --- diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java index 5e719b49fe..f44afa2cb4 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -102,7 +102,6 @@ import org.opendaylight.yangtools.yang.model.api.UsesNode; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition; -import org.opendaylight.yangtools.yang.model.util.BaseTypes; import org.opendaylight.yangtools.yang.model.util.DataNodeIterator; import org.opendaylight.yangtools.yang.model.util.ExtendedType; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; @@ -332,7 +331,7 @@ public class BindingGeneratorImpl implements BindingGenerator { final GeneratedTypeBuilder parent, final GeneratedTypeBuilder childOf, final ContainerSchemaNode node) { final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node); if (genType != null) { - constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), genType); + constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), genType, node.getStatus()); resolveDataSchemaNodes(module, basePackageName, genType, genType, node.getChildNodes()); } } @@ -342,7 +341,7 @@ public class BindingGeneratorImpl implements BindingGenerator { final GeneratedTypeBuilder genType = processDataSchemaNode(module, basePackageName, childOf, node); if (genType != null) { constructGetter(parent, node.getQName().getLocalName(), node.getDescription(), - Types.listTypeFor(genType)); + Types.listTypeFor(genType), node.getStatus()); final List listKeys = listKeys(node); final String packageName = packageNameForGeneratedType(basePackageName, node.getPath()); @@ -1171,7 +1170,7 @@ public class BindingGeneratorImpl implements BindingGenerator { final String packageName = packageNameForGeneratedType(basePackageName, choiceNode.getPath()); final GeneratedTypeBuilder choiceTypeBuilder = addRawInterfaceDefinition(packageName, choiceNode); constructGetter(parent, choiceNode.getQName().getLocalName(), - choiceNode.getDescription(), choiceTypeBuilder); + choiceNode.getDescription(), choiceTypeBuilder, choiceNode.getStatus()); choiceTypeBuilder.addImplementsType(typeForClass(DataContainer.class)); annotateDeprecatedIfNecessary(choiceNode.getStatus(), choiceTypeBuilder); genCtx.get(module).addChildNodeType(choiceNode, choiceTypeBuilder); @@ -1453,7 +1452,7 @@ public class BindingGeneratorImpl implements BindingGenerator { leafDesc = ""; } - final MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType); + final MethodSignatureBuilder getter = constructGetter(typeBuilder, leafName, leafDesc, returnType, leaf.getStatus()); processContextRefExtension(leaf, getter, parentModule); return returnType; } @@ -1656,7 +1655,7 @@ public class BindingGeneratorImpl implements BindingGenerator { } final ParameterizedType listType = Types.listTypeFor(returnType); - constructGetter(typeBuilder, nodeName.getLocalName(), node.getDescription(), listType); + constructGetter(typeBuilder, nodeName.getLocalName(), node.getDescription(), listType, node.getStatus()); return true; } @@ -1876,13 +1875,18 @@ public class BindingGeneratorImpl implements BindingGenerator { * string with comment for the getter method * @param returnType * type which represents the return type of the getter method + * @param status + * status from yang file, for deprecated annotation * @return method signature builder which represents the getter method of * interfaceBuilder */ private static MethodSignatureBuilder constructGetter(final GeneratedTypeBuilder interfaceBuilder, - final String schemaNodeName, final String comment, final Type returnType) { + final String schemaNodeName, final String comment, final Type returnType, final Status status) { final MethodSignatureBuilder getMethod = interfaceBuilder .addMethod(getterMethodName(schemaNodeName, returnType)); + if (status == Status.DEPRECATED) { + getMethod.addAnnotation("", "Deprecated"); + } getMethod.setComment(encodeAngleBrackets(comment)); getMethod.setReturnType(returnType); return getMethod; @@ -1948,7 +1952,7 @@ public class BindingGeneratorImpl implements BindingGenerator { if (genTOBuilder != null) { final GeneratedTransferObject genTO = genTOBuilder.toInstance(); - constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO); + constructGetter(typeBuilder, "key", "Returns Primary Key of Yang List Type", genTO, Status.CURRENT); genCtx.get(module).addGeneratedTOBuilder(genTOBuilder); } } diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend index df1cc86b08..09764442ba 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/YangTemplate.xtend @@ -7,6 +7,7 @@ */ package org.opendaylight.yangtools.sal.binding.generator.impl +import com.google.common.base.CharMatcher import java.util.Collection import java.util.Date import java.util.List @@ -14,6 +15,7 @@ import java.util.Map import java.util.Set import java.util.StringTokenizer import org.opendaylight.yangtools.yang.common.QName +import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode import org.opendaylight.yangtools.yang.model.api.AugmentationSchema import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode @@ -40,8 +42,6 @@ import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode import org.opendaylight.yangtools.yang.model.api.UsesNode import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil -import com.google.common.base.CharMatcher class YangTemplate { @@ -211,9 +211,6 @@ class YangTemplate { def static writeRPC(RpcDefinition rpc) { var boolean isStatusDeprecated = rpc.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» rpc «rpc.QName.localName» { «IF !rpc.description.nullOrEmpty» "«rpc.description»"; @@ -278,9 +275,6 @@ class YangTemplate { def static writeNotification(NotificationDefinition notification) { var boolean isStatusDeprecated = notification.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» notification «notification.QName.localName» { «IF !notification.description.nullOrEmpty» description @@ -382,9 +376,6 @@ class YangTemplate { def static writeTypeDefinition(TypeDefinition typeDefinition) { var boolean isStatusDeprecated = typeDefinition.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» type «typeDefinition.QName.localName»«IF !isStatusDeprecated»;«ELSE» { status «typeDefinition.status»; } @@ -475,12 +466,7 @@ class YangTemplate { } def static writeExtension(ExtensionDefinition extensionDef) { - var boolean isStatusDeprecated = extensionDef.status == Status::DEPRECATED - ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» extension «extensionDef.QName.localName» { «IF !extensionDef.description.nullOrEmpty» description @@ -582,9 +568,6 @@ class YangTemplate { def static writeGroupingDef(GroupingDefinition groupingDef) { var boolean isStatusDeprecated = groupingDef.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» grouping «groupingDef.QName.localName» { «IF !groupingDef.groupings.nullOrEmpty» «writeGroupingDefs(groupingDef.groupings)» @@ -605,9 +588,6 @@ class YangTemplate { def static writeContSchemaNode(ContainerSchemaNode contSchemaNode) { var boolean isStatusDeprecated = contSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» container «contSchemaNode.getQName.localName» { «IF !contSchemaNode.childNodes.nullOrEmpty» «writeDataSchemaNodes(contSchemaNode.childNodes)» @@ -634,9 +614,6 @@ class YangTemplate { def static writeAnyXmlSchemaNode(AnyXmlSchemaNode anyXmlSchemaNode) { var boolean isStatusDeprecated = anyXmlSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» anyxml «anyXmlSchemaNode.getQName.localName»«IF !isStatusDeprecated»;«ELSE» { status «anyXmlSchemaNode.status»; } @@ -647,9 +624,6 @@ class YangTemplate { def static writeLeafSchemaNode(LeafSchemaNode leafSchemaNode) { var boolean isStatusDeprecated = leafSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» leaf «leafSchemaNode.getQName.localName» { type «leafSchemaNode.type.getQName.localName»; «IF isStatusDeprecated» @@ -662,9 +636,6 @@ class YangTemplate { def static writeLeafListSchemaNode(LeafListSchemaNode leafListSchemaNode) { var boolean isStatusDeprecated = leafListSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» leaf-list «leafListSchemaNode.getQName.localName» { type «leafListSchemaNode.type.getQName.localName»; «IF isStatusDeprecated» @@ -677,9 +648,6 @@ class YangTemplate { def static writeChoiceCaseNode(ChoiceCaseNode choiceCaseNode) { var boolean isStatusDeprecated = choiceCaseNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» case «choiceCaseNode.getQName.localName» { «FOR childNode : choiceCaseNode.childNodes» «writeDataSchemaNode(childNode)» @@ -694,9 +662,6 @@ class YangTemplate { def static writeChoiceNode(ChoiceSchemaNode choiceNode) { var boolean isStatusDeprecated = choiceNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» choice «choiceNode.getQName.localName» { «FOR child : choiceNode.cases» «writeDataSchemaNode(child)» @@ -712,9 +677,6 @@ class YangTemplate { var boolean isStatusDeprecated = listSchemaNode.status == Status::DEPRECATED ''' - «IF isStatusDeprecated» - @deprecated - status DEPRECATED - «ENDIF» list «listSchemaNode.getQName.localName» { key «FOR listKey : listSchemaNode.keyDefinition SEPARATOR " "»"«listKey.localName»" «ENDFOR» diff --git a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java index 80571e4b6a..405a71d922 100644 --- a/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java +++ b/binding/mdsal-binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/yang/types/TypeProviderImpl.java @@ -493,9 +493,8 @@ public final class TypeProviderImpl implements TypeProvider { } else { dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath); } - Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s) at %s", - strXPath, this.getParentModule(parentNode).getName(), - parentNode.getQName().getModule(), this.getParentModule(parentNode).getModuleSourcePath()); + Preconditions.checkArgument(dataNode != null, "Failed to find leafref target: %s in module %s (%s)", + strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule()); if (leafContainsEnumDefinition(dataNode)) { returnType = referencedTypes.get(dataNode.getPath()); @@ -508,9 +507,8 @@ public final class TypeProviderImpl implements TypeProvider { returnType = Types.typeForClass(Object.class); } } - Preconditions.checkArgument(returnType != null, "Failed to find leafref target: %s in module %s (%s) at %s", - strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule(), this - .getParentModule(parentNode).getModuleSourcePath()); + Preconditions.checkArgument(returnType != null, "Failed to find leafref target: %s in module %s (%s)", + strXPath, this.getParentModule(parentNode).getName(), parentNode.getQName().getModule(), this); return returnType; } @@ -1547,7 +1545,7 @@ public final class TypeProviderImpl implements TypeProvider { private static final Comparator BIT_NAME_COMPARATOR = new Comparator() { @Override - public int compare(final Bit o1, final Bit o2) { + public int compare(Bit o1, Bit o2) { return o1.getName().compareTo(o2.getName()); } }; @@ -1633,7 +1631,7 @@ public final class TypeProviderImpl implements TypeProvider { List modulesList = new ArrayList<>(modules); Collections.sort(modulesList, new Comparator() { @Override - public int compare(final Module o1, final Module o2) { + public int compare(Module o1, Module o2) { return o1.getRevision().compareTo(o2.getRevision()); } }); diff --git a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java index e4fe8f4ca6..944e5f4c0e 100644 --- a/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java +++ b/binding/mdsal-binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/GeneratedTypesLeafrefTest.java @@ -258,7 +258,7 @@ public class GeneratedTypesLeafrefTest { bindingGen.generateTypes(context); fail("Expected IllegalArgumentException caused by invalid leafref path"); } catch (IllegalArgumentException e) { - String expected = "Failed to find leafref target: ../id in module foo (QNameModule{ns=urn:yang.foo, rev=2014-03-10}) at"; + String expected = "Failed to find leafref target: ../id in module foo (QNameModule{ns=urn:yang.foo, rev=2014-03-10})"; assertTrue(e.getMessage().startsWith(expected)); } } diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend index eba6b3a39d..f39f7a3d1d 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/BaseTemplate.xtend @@ -18,13 +18,13 @@ import java.util.StringTokenizer import java.util.regex.Pattern import org.opendaylight.yangtools.binding.generator.util.Types import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType +import org.opendaylight.yangtools.sal.binding.model.api.Constant import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject 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.Restrictions import org.opendaylight.yangtools.sal.binding.model.api.Type -import org.opendaylight.yangtools.sal.binding.model.api.Constant import org.opendaylight.yangtools.yang.common.QName abstract class BaseTemplate { diff --git a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend index 8dec19fc92..6e1875a632 100644 --- a/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend +++ b/binding/mdsal-binding-java-api-generator/src/main/java/org/opendaylight/yangtools/sal/java/api/generator/ClassTemplate.xtend @@ -113,6 +113,7 @@ class ClassTemplate extends BaseTemplate { */ def protected generateBody(boolean isInnerClass) ''' «wrapToDocumentation(formatDataForJavaDoc(type))» + «annotationDeclaration» «generateClassDeclaration(isInnerClass)» { «suidDeclaration» «innerClassesDeclarations» @@ -417,6 +418,14 @@ class ClassTemplate extends BaseTemplate { «ENDIF» ''' + def protected annotationDeclaration() ''' + «IF genTO.getAnnotations != null» + «FOR e : genTO.getAnnotations» + @«e.getName» + «ENDFOR» + «ENDIF» + ''' + /** * Template method which generates JAVA constants. * diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java index d8701b5ef4..0902c19296 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. + * Copyright (c) 2016 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, @@ -9,24 +9,6 @@ package org.opendaylight.yangtools.sal.java.api.generator.test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.FS; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAR; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAZ; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_FOO; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_TEST; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsConstructor; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsField; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsMethod; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsRestrictionCheck; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertFilesCount; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsParameterizedIfc; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles; -import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; @@ -52,6 +34,7 @@ import java.util.List; import org.junit.Test; import org.opendaylight.yangtools.sal.binding.model.api.Type; import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile; +import org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.RetestUtils; import org.opendaylight.yangtools.yang.binding.ChildOf; import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext; import org.opendaylight.yangtools.yang.model.api.SchemaContext; @@ -79,15 +62,15 @@ public class CompilationTest extends BaseCompilationTest { @Test public void testListGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "list-gen"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "list-gen"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/list-gen", sourcesOutputDir); // Test if all sources are generated - File parent = new File(sourcesOutputDir, NS_TEST); + File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST); final File keyArgs = new File(parent, "KeyArgs.java"); final File links = new File(parent, "Links.java"); final File linksBuilder = new File(parent, "LinksBuilder.java"); @@ -98,9 +81,9 @@ public class CompilationTest extends BaseCompilationTest { assertTrue(linksBuilder.exists()); assertTrue(linksKey.exists()); assertTrue(testData.exists()); - assertFilesCount(parent, 6); + CompilationTestUtils.assertFilesCount(parent, 6); - parent = new File(sourcesOutputDir, NS_TEST + FS + "links"); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST + CompilationTestUtils.FS + "links"); final File level = new File(parent, "Level.java"); final File linkGroup = new File(parent, "LinkGroup.java"); final File node = new File(parent, "Node.java"); @@ -115,154 +98,154 @@ public class CompilationTest extends BaseCompilationTest { assertTrue(nodeList.exists()); assertTrue(nodeListBuilder.exists()); assertTrue(nodesType.exists()); - assertFilesCount(parent, 7); + CompilationTestUtils.assertFilesCount(parent, 7); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class keyArgsClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader); - final Class linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader); - final Class linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader); + final Class keyArgsClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader); + final Class linksClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader); + final Class linksKeyClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader); // Test generated 'grouping key-args' assertTrue(keyArgsClass.isInterface()); - assertContainsMethod(keyArgsClass, String.class, "getName"); - assertContainsMethod(keyArgsClass, Integer.class, "getSize"); + CompilationTestUtils.assertContainsMethod(keyArgsClass, String.class, "getName"); + CompilationTestUtils.assertContainsMethod(keyArgsClass, Integer.class, "getSize"); assertEquals(2, abstractMethods(keyArgsClass).size()); // Test generated 'list links' assertTrue(linksClass.isInterface()); - assertImplementsIfc(linksClass, keyArgsClass); + CompilationTestUtils.assertImplementsIfc(linksClass, keyArgsClass); // TODO: anyxml assertEquals(6, abstractMethods(linksClass).size()); // Test list key constructor arguments ordering - assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class); + CompilationTestUtils.assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class); // Test serialVersionUID generation - final Field suid = assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE); + final Field suid = CompilationTestUtils.assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE); suid.setAccessible(true); assertEquals(-8829501012356283881L, suid.getLong(null)); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testAugmentUnderUsesGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "augment-under-uses"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "augment-under-uses"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/augment-under-uses", sourcesOutputDir); // Test if all sources were generated from 'module foo' - File parent = new File(sourcesOutputDir, NS_FOO); + File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); assertTrue(new File(parent, "Object.java").exists()); assertTrue(new File(parent, "ClosedObject.java").exists()); assertTrue(new File(parent, "OpenObject.java").exists()); assertTrue(new File(parent, "ExplicitRouteObject.java").exists()); assertTrue(new File(parent, "PathKeySubobject.java").exists()); - assertFilesCount(parent, 9); + CompilationTestUtils.assertFilesCount(parent, 9); parent = new File(parent, "object"); assertTrue(new File(parent, "Nodes.java").exists()); assertTrue(new File(parent, "NodesBuilder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); - parent = new File(sourcesOutputDir, NS_FOO + FS + "closed"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "closed"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "object"); assertTrue(new File(parent, "Link1.java").exists()); assertTrue(new File(parent, "Link1Builder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); - parent = new File(sourcesOutputDir, NS_FOO + FS + "open"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "open"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "object"); assertTrue(new File(parent, "Nodes1.java").exists()); assertTrue(new File(parent, "Nodes1Builder.java").exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "nodes"); assertTrue(new File(parent, "Links.java").exists()); assertTrue(new File(parent, "LinksBuilder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); - parent = new File(sourcesOutputDir, NS_FOO + FS + "explicit"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "explicit"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "route"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "object"); assertTrue(new File(parent, "Subobjects.java").exists()); assertTrue(new File(parent, "SubobjectsBuilder.java").exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "subobjects"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "subobject"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); assertTrue(new File(parent, "PathKey.java").exists()); assertTrue(new File(parent, "PathKeyBuilder.java").exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "path"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "key"); assertTrue(new File(parent, "PathKey.java").exists()); assertTrue(new File(parent, "PathKeyBuilder.java").exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); // Test if all sources were generated from 'module bar' - parent = new File(sourcesOutputDir, NS_BAR); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR); assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists()); assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists()); assertTrue(new File(parent, "RouteSubobjects.java").exists()); - assertFilesCount(parent, 5); + CompilationTestUtils.assertFilesCount(parent, 5); parent = new File(parent, "route"); - assertFilesCount(parent, 1); - parent = new File(new File(sourcesOutputDir, NS_BAR), "basic"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); + parent = new File(new File(sourcesOutputDir, CompilationTestUtils.NS_BAR), "basic"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "explicit"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "route"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "subobjects"); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); assertTrue(new File(parent, "SubobjectType.java").exists()); parent = new File(parent, "subobject"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); assertTrue(new File(parent, "IpPrefix.java").exists()); assertTrue(new File(parent, "IpPrefixBuilder.java").exists()); assertTrue(new File(parent, "Label.java").exists()); assertTrue(new File(parent, "LabelBuilder.java").exists()); - assertFilesCount(parent, 4); + CompilationTestUtils.assertFilesCount(parent, 4); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testAugmentOfAugmentGeneration() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "aug-of-aug"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "aug-of-aug"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/augment-of-augment", sourcesOutputDir); // Test if all sources were generated from 'module foo' - File parent = new File(sourcesOutputDir, NS_FOO); + File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); final File fooListener = new File(parent, "FooListener.java"); File pathAttributes = new File(parent, "PathAttributes.java"); final File update = new File(parent, "Update.java"); @@ -271,220 +254,220 @@ public class CompilationTest extends BaseCompilationTest { assertTrue(pathAttributes.exists()); assertTrue(update.exists()); assertTrue(updateBuilder.exists()); - assertFilesCount(parent, 6); + CompilationTestUtils.assertFilesCount(parent, 6); - parent = new File(sourcesOutputDir, NS_FOO + FS + "path"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "path"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "attributes"); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); final File origin = new File(parent, "Origin.java"); final File originBuilder = new File(parent, "OriginBuilder.java"); assertTrue(origin.exists()); assertTrue(originBuilder.exists()); - parent = new File(sourcesOutputDir, NS_FOO + FS + "update"); - assertFilesCount(parent, 2); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "update"); + CompilationTestUtils.assertFilesCount(parent, 2); pathAttributes = new File(parent, "PathAttributes.java"); final File pathAttributesBuilder = new File(parent, "PathAttributesBuilder.java"); assertTrue(pathAttributes.exists()); assertTrue(pathAttributesBuilder.exists()); // Test if all sources were generated from 'module bar' - parent = new File(sourcesOutputDir, NS_BAR); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR); final File destination = new File(parent, "Destination.java"); final File pathAttributes1 = new File(parent, "PathAttributes1.java"); final File pathAttributes1Builder = new File(parent, "PathAttributes1Builder.java"); assertTrue(destination.exists()); assertTrue(pathAttributes1.exists()); assertTrue(pathAttributes1Builder.exists()); - assertFilesCount(parent, 5); + CompilationTestUtils.assertFilesCount(parent, 5); - parent = new File(sourcesOutputDir, NS_BAR + FS + "destination"); - assertFilesCount(parent, 2); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "destination"); + CompilationTestUtils.assertFilesCount(parent, 2); final File destinationType = new File(parent, "DestinationType.java"); assertTrue(destinationType.exists()); parent = new File(parent, "destination"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); final File destinationIpv4 = new File(parent, "DestinationIp.java"); final File destinationIpv4Builder = new File(parent, "DestinationIpBuilder.java"); assertTrue(destinationIpv4.exists()); assertTrue(destinationIpv4Builder.exists()); - parent = new File(sourcesOutputDir, NS_BAR + FS + "update"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "update"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "path"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "attributes"); final File mpUnreachNlri = new File(parent, "MpUnreachNlri.java"); final File mpUnreachNlriBuilder = new File(parent, "MpUnreachNlriBuilder.java"); assertTrue(mpUnreachNlri.exists()); assertTrue(mpUnreachNlriBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "mp"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "unreach"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "nlri"); final File withdrawnRoutes = new File(parent, "WithdrawnRoutes.java"); final File withdrawnRoutesBuilder = new File(parent, "WithdrawnRoutesBuilder.java"); assertTrue(withdrawnRoutes.exists()); assertTrue(withdrawnRoutesBuilder.exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); // Test if all sources were generated from 'module baz' - parent = new File(sourcesOutputDir, NS_BAZ); - assertFilesCount(parent, 2); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ); + CompilationTestUtils.assertFilesCount(parent, 2); final File linkstateDestination = new File(parent, "LinkstateDestination.java"); assertTrue(linkstateDestination.exists()); - parent = new File(sourcesOutputDir, NS_BAZ + FS + "update"); - assertFilesCount(parent, 1); + parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ + CompilationTestUtils.FS + "update"); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "path"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "attributes"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "mp"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "unreach"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "nlri"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "withdrawn"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "routes"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "destination"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "type"); final File destinationLinkstate = new File(parent, "DestinationLinkstate.java"); final File destinationLinkstateBuilder = new File(parent, "DestinationLinkstateBuilder.java"); assertTrue(destinationLinkstate.exists()); assertTrue(destinationLinkstateBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "destination"); - assertFilesCount(parent, 1); + CompilationTestUtils.assertFilesCount(parent, 1); parent = new File(parent, "linkstate"); final File links = new File(parent, "Links.java"); final File linksBuilder = new File(parent, "LinksBuilder.java"); assertTrue(links.exists()); assertTrue(linksBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "links"); final File source = new File(parent, "Source.java"); final File sourceBuilder = new File(parent, "SourceBuilder.java"); assertTrue(source.exists()); assertTrue(sourceBuilder.exists()); - assertFilesCount(parent, 3); + CompilationTestUtils.assertFilesCount(parent, 3); parent = new File(parent, "source"); final File address = new File(parent, "Address.java"); final File addressBuilder = new File(parent, "AddressBuilder.java"); assertTrue(address.exists()); assertTrue(addressBuilder.exists()); - assertFilesCount(parent, 2); + CompilationTestUtils.assertFilesCount(parent, 2); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testLeafReturnTypes() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "leaf-return-types"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "leaf-return-types"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/leaf-return-types", sourcesOutputDir); - final File parent = new File(sourcesOutputDir, NS_TEST); + final File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST); assertTrue(new File(parent, "TestData.java").exists()); assertTrue(new File(parent, "Nodes.java").exists()); assertTrue(new File(parent, "NodesBuilder.java").exists()); assertTrue(new File(parent, "Alg.java").exists()); assertTrue(new File(parent, "NodesIdUnionBuilder.java").exists()); - assertFilesCount(parent, 5); + CompilationTestUtils.assertFilesCount(parent, 5); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - final String pkg = BASE_PKG + ".urn.opendaylight.test.rev131008"; + final String pkg = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008"; final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); final Class nodesClass = Class.forName(pkg + ".Nodes", true, loader); final Class builderClass = Class.forName(pkg + ".NodesBuilder", true, loader); // Test methods return type final byte[] b = new byte[] {}; - assertContainsMethod(nodesClass, b.getClass(), "getIdBinary"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader); - assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean"); - assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64"); - assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader); + CompilationTestUtils.assertContainsMethod(nodesClass, b.getClass(), "getIdBinary"); + CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader); + CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean"); + CompilationTestUtils.assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64"); + CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty"); + CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader); testReturnTypeIdentityref(nodesClass, "getIdIdentityref", pkg + ".Alg"); testReturnTypeInstanceIdentitifer(loader, nodesClass, "getIdInstanceIdentifier"); - assertContainsMethod(nodesClass, Byte.class, "getId8"); - assertContainsMethod(nodesClass, Short.class, "getId16"); - assertContainsMethod(nodesClass, Integer.class, "getId32"); - assertContainsMethod(nodesClass, Long.class, "getId64"); - assertContainsMethod(nodesClass, Long.class, "getIdLeafref"); - assertContainsMethod(nodesClass, String.class, "getIdString"); - assertContainsMethod(nodesClass, Short.class, "getIdU8"); - assertContainsMethod(nodesClass, Integer.class, "getIdU16"); - assertContainsMethod(nodesClass, Long.class, "getIdU32"); - assertContainsMethod(nodesClass, BigInteger.class, "getIdU64"); - assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader); + CompilationTestUtils.assertContainsMethod(nodesClass, Byte.class, "getId8"); + CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getId16"); + CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getId32"); + CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getId64"); + CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdLeafref"); + CompilationTestUtils.assertContainsMethod(nodesClass, String.class, "getIdString"); + CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getIdU8"); + CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getIdU16"); + CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdU32"); + CompilationTestUtils.assertContainsMethod(nodesClass, BigInteger.class, "getIdU64"); + CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader); final Object builderObj = builderClass.newInstance(); - Method m = assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass()); + Method m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass()); final List> lengthConstraints = new ArrayList<>(); lengthConstraints.add(Range.closed(1, 10)); byte[] arg = new byte[] {}; String expectedMsg = String.format("Invalid length: %s, expected: %s.", Arrays.toString(arg), lengthConstraints); - assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg); + CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg); - m = assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class); + m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class); final List> rangeConstraints = new ArrayList<>(); rangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5"))); Object arg1 = new BigDecimal("1.4"); expectedMsg = String.format("Invalid range: %s, expected: %s.", arg1, rangeConstraints); - assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1); + CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testGenerationContextReferenceExtension() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "context-reference"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "context-reference"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/context-reference", sourcesOutputDir); // Test if all sources are generated - final File fooParent = new File(sourcesOutputDir, NS_FOO); - assertFilesCount(fooParent, 3); + final File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO); + CompilationTestUtils.assertFilesCount(fooParent, 3); assertTrue(new File(fooParent, "FooData.java").exists()); assertTrue(new File(fooParent, "Nodes.java").exists()); assertTrue(new File(fooParent, "NodesBuilder.java").exists()); - final File barParent = new File(sourcesOutputDir, NS_BAR); - assertFilesCount(barParent, 1); + final File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR); + CompilationTestUtils.assertFilesCount(barParent, 1); assertTrue(new File(barParent, "IdentityClass.java").exists()); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class nodesClass = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader); + final Class nodesClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader); final Class identityClass = Class - .forName(BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader); + .forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader); // test identity try { @@ -506,37 +489,52 @@ public class CompilationTest extends BaseCompilationTest { throw new AssertionError("Method getId() not found"); } - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void compilationTest() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "yang"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "yang"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "yang"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "yang"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/yang", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void testBug586() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug586"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug586"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug586"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug586"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/bug586", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); + } + + @Test + public void testBug4760() throws Exception { + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760"); + assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760"); + assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); + + generateTestSources("/compilation/bug4760", sourcesOutputDir); + + // Test if sources are compilable + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } /** @@ -546,17 +544,47 @@ public class CompilationTest extends BaseCompilationTest { */ @Test public void testBug1172() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1172"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1172"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/bug1172", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); + } + + @Test + public void testBug5461() throws Exception { + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461"); + assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461"); + assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); + + generateTestSources("/compilation/bug5461", sourcesOutputDir); + + // Test if sources are compilable + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); + } + + @Test + public void testBug5788() throws Exception { + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788"); + assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788"); + assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); + + generateTestSources("/compilation/bug5788", sourcesOutputDir); + + // Test if sources are compilable + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } /** @@ -566,43 +594,43 @@ public class CompilationTest extends BaseCompilationTest { */ @Test public void testBug1377() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1377"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1377"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/bug1377", sourcesOutputDir); // Test if sources are compilable - testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() }); - final Class outputActionClass = Class.forName(BASE_PKG + final Class outputActionClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.test.foo.rev140717.action.action.output.action._case.OutputAction", true, loader); - final Class actionClass = Class.forName(BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader); + final Class actionClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader); // Test generated 'container output-action' assertTrue(outputActionClass.isInterface()); - assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName()); + CompilationTestUtils.assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName()); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } @Test public void classNamesColisionTest() throws Exception { - final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "class-name-collision"); + final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision"); assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir()); - final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "class-name-collision"); + final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision"); assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir()); generateTestSources("/compilation/class-name-collision", sourcesOutputDir); - testCompilation(sourcesOutputDir, compiledOutputDir); - cleanUp(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir); + CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir); } private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception { - final List sourceFiles = getSourceFiles(resourceDirPath); - final SchemaContext context = parser.parseFiles(sourceFiles); + final List sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath); + final SchemaContext context = RetestUtils.parseYangSources(sourceFiles); final List types = bindingGenerator.generateTypes(context); Collections.sort(types, new Comparator() { @Override diff --git a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java index 118fa94b1e..3e591023d1 100644 --- a/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java +++ b/binding/mdsal-binding-java-api-generator/src/test/java/org/opendaylight/yangtools/sal/java/api/generator/test/CompilationTestUtils.java @@ -11,6 +11,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; + import java.io.File; import java.io.FileNotFoundException; import java.lang.reflect.Constructor; @@ -26,7 +27,7 @@ import java.util.List; import javax.tools.JavaCompiler; import javax.tools.JavaFileObject; import javax.tools.StandardJavaFileManager; -import javax.tools.ToolProvider; +import javax.tools.ToolProvider;; public class CompilationTestUtils { public static final String FS = File.separator; @@ -41,12 +42,12 @@ public class CompilationTestUtils { static final File COMPILER_OUTPUT_DIR = new File(COMPILER_OUTPUT_PATH); static final String AUGMENTATION = "interface org.opendaylight.yangtools.yang.binding.Augmentation"; - static final String BASE_PATH = "org" + FS + "opendaylight" + FS + "yang" + FS + "gen" + FS + "v1"; static final String NS_TEST = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "test" + FS + "rev131008"; static final String NS_FOO = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "foo" + FS + "rev131008"; static final String NS_BAR = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "bar" + FS + "rev131008"; static final String NS_BAZ = BASE_PATH + FS + "urn" + FS + "opendaylight" + FS + "baz" + FS + "rev131008"; + static final String NS_BUG5882 = BASE_PATH + FS + "urn" + FS + "yang" + FS + "foo" + FS + "rev160102"; /** * Method to clean resources. It is manually called at the end of each test diff --git a/binding/mdsal-binding-java-api-generator/src/test/resources/compilation/bug5882/foo.yang b/binding/mdsal-binding-java-api-generator/src/test/resources/compilation/bug5882/foo.yang new file mode 100644 index 0000000000..e77ac966c5 --- /dev/null +++ b/binding/mdsal-binding-java-api-generator/src/test/resources/compilation/bug5882/foo.yang @@ -0,0 +1,201 @@ +module foo { + namespace "urn:yang.foo"; + prefix "foo"; + + revision "2016-01-02" { + } + + typedef typedef1 { + type typedef-deprecated; + description "current"; + } + + typedef typedef2 { + status deprecated; + type typedef1; + description "deprecated"; + } + + typedef typedef3 { + type typedef2; + description "current"; + } + + typedef typedef-deprecated { + status deprecated; + type string; + description "deprecated"; + } + + typedef typedef-current { + status current; + type uint8 { + range "0 .. 100"; + } + description "current"; + } + + container container-main { + leaf container-main-leaf-depr { + status deprecated; + type string; + } + + leaf container-main-leaf-current { + type typedef-current; + } + + list container-main-list-depr { + status deprecated; + key "test"; + leaf test { + type int8; + } + } + + list container-main-list-current { + key "test"; + leaf test { + type int8; + } + } + + choice container-main-choice-depr { + status deprecated; + case depCase { + status deprecated; + leaf one { + type string; + } + } + case depLeaf { + leaf one { + status deprecated; + type string; + } + } + case cur { + leaf two { + type string; + } + } + } + + choice container-main-choice-cur { + case depCase { + status deprecated; + leaf one { + type string; + } + } + case depLeaf { + leaf one { + status deprecated; + type string; + } + } + case cur { + leaf two { + type string; + } + } + } + } + + leaf container-main-leaf-depr { + status deprecated; + type string; + } + + leaf container-main-leaf-current { + type typedef-current; + } + + list container-main-list-depr { + status deprecated; + key "test"; + leaf test { + type int8; + } + } + + list container-main-list-current { + key "test"; + leaf test { + type int8; + } + } + + choice container-main-choice-depr { + status deprecated; + case depCase { + status deprecated; + leaf one { + type string; + } + } + case depLeaf { + leaf one { + status deprecated; + type string; + } + } + case cur { + leaf two { + type string; + } + } + } + + choice container-main-choice-cur { + case depCase { + status deprecated; + leaf one { + type string; + } + } + case depLeaf { + leaf one { + status deprecated; + type string; + } + } + case cur { + leaf two { + type string; + } + } + } + + leaf leaf-deprecated { + status deprecated; + type typedef-deprecated; + } + + leaf leaf-current { + type typedef-current; + } + + grouping grouping-deprecated { + status deprecated; + leaf leaf-deprecated { + status deprecated; + type typedef-deprecated; + } + + leaf leaf-current { + type typedef-current; + } + } + + grouping grouping-current { + leaf leaf-deprecated { + status deprecated; + type typedef-deprecated; + } + + leaf leaf-current { + type typedef-current; + } + } +} \ No newline at end of file