Bug 2528 - Binding Generator: Generated notification implements ChildOf 94/13994/10
authorPeter Kajsa <pkajsa@cisco.com>
Thu, 8 Jan 2015 12:50:02 +0000 (13:50 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 26 May 2015 12:10:16 +0000 (12:10 +0000)
interface

Generated Notification interface implements ChildOf<DataObject> 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<DataObject>" 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 <pkajsa@cisco.com>
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.java
code-generator/binding-generator-impl/src/test/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImplTest.java
code-generator/binding-generator-impl/src/test/resources/binding-generator-impl-test/notification-test.yang [new file with mode: 0644]

index 995d5ab1c10d30c451439612ec8153e35b6c3a68..c8db5f1ebc2b76a627df951d8b986b466f8b255c 100644 (file)
@@ -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);
 
index c926c77a56be5a0330c9470d6d23ece5de53cdf7..3f37dcfd98c8c9b6eaff898a21d2a04f8fa2a8ba 100644 (file)
@@ -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<Type> 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<Type> 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 (file)
index 0000000..e014af0
--- /dev/null
@@ -0,0 +1,7 @@
+module notification-test {
+    namespace "notification-test";
+    prefix test;
+
+    notification foo {
+    }
+}