From: Peter Kajsa Date: Thu, 8 Jan 2015 12:50:02 +0000 (+0100) Subject: Bug 2528 - Binding Generator: Generated notification implements ChildOf X-Git-Tag: release/beryllium~495 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=1fa4f51ce27b8a625d01f622f1261d51c0e852cb;p=yangtools.git Bug 2528 - Binding Generator: Generated notification implements ChildOf interface Generated Notification interface implements ChildOf interface which is incorrect. Generated Notification should not implement ChildOf interface since it is not part of data tree. This could lead to use of Notification in wrong context and may confuse consumers of APIs. Notice: The solution replaces "implements ChildOf" with "implements DataObject" in generated Notification interface. Notification has structured content, so I think the generated Notification interface should implements at least DataObject interface in order to be able to construct InstanceIdentifier for the notification (analogously as it is by RPC's input and output). Change-Id: I55c7a8cc4ce450fd712c63f8e77881d4a18674e6 Signed-off-by: Peter Kajsa --- diff --git a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java index 995d5ab1c1..c8db5f1ebc 100644 --- a/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java +++ b/code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java @@ -559,7 +559,7 @@ public class BindingGeneratorImpl implements BindingGenerator { processUsesAugments(notification, module); final GeneratedTypeBuilder notificationInterface = addDefaultInterfaceDefinition(basePackageName, - notification, BindingTypes.DATA_OBJECT, module); + notification, null, module); notificationInterface.addImplementsType(NOTIFICATION); genCtx.get(module).addChildNodeType(notification, notificationInterface); diff --git a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java index c926c77a56..3f37dcfd98 100644 --- a/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java +++ b/code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java @@ -8,6 +8,7 @@ package org.opendaylight.yangtools.sal.binding.generator.impl; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; import java.io.IOException; @@ -123,4 +124,41 @@ public class BindingGeneratorImplTest { } + @Test + public void notificationGenerationTest() throws IOException, YangSyntaxErrorException, URISyntaxException { + File resourceFile = new File(getClass().getResource("/binding-generator-impl-test/notification-test.yang") + .toURI()); + File resourceDir = resourceFile.getParentFile(); + + YangParserImpl parser = YangParserImpl.getInstance(); + SchemaContext context = parser.parseFile(resourceFile, resourceDir); + + List generateTypes = new BindingGeneratorImpl(false).generateTypes(context); + + GeneratedType foo = null; + for (Type type : generateTypes) { + if (type.getName().equals("Foo")) { + foo = (GeneratedType) type; + break; + } + } + + Type childOf = null; + Type dataObject = null; + List impl = foo.getImplements(); + for (Type type : impl) { + switch (type.getName()) { + case "ChildOf": + childOf = type; + break; + case "DataObject": + dataObject = type; + break; + } + } + + assertNull(childOf); + assertNotNull(dataObject); + } + } diff --git a/code-generator/binding-generator-impl/src/test/resources/binding-generator-impl-test/notification-test.yang b/code-generator/binding-generator-impl/src/test/resources/binding-generator-impl-test/notification-test.yang new file mode 100644 index 0000000000..e014af0b31 --- /dev/null +++ b/code-generator/binding-generator-impl/src/test/resources/binding-generator-impl-test/notification-test.yang @@ -0,0 +1,7 @@ +module notification-test { + namespace "notification-test"; + prefix test; + + notification foo { + } +}