Gen Type and Generated TO builders moved to Util project. 61/261/1
authorlsedlak <lsedlak@cisco.com>
Fri, 26 Apr 2013 11:56:21 +0000 (13:56 +0200)
committerlsedlak <lsedlak@cisco.com>
Fri, 26 Apr 2013 11:56:21 +0000 (13:56 +0200)
GeneratedType and Generated Transfer Object builders moved from
binding-generator-impl project to binding-generator-util project;
Added test cases for testing annotations over methods and properties;

Signed-off-by: Lukas Sedlak <lsedlak@cisco.com>
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/BindingGeneratorImpl.java
opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/AnnotationBuilderTest.java [deleted file]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationTypeBuilderImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/AnnotationTypeBuilderImpl.java with 99% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/ConstantBuilderImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/ConstantBuilderImpl.java with 98% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/EnumerationBuilderImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/EnumerationBuilderImpl.java with 99% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTOBuilderImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTOBuilderImpl.java with 99% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/GeneratedTypeBuilderImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/GeneratedTypeBuilderImpl.java with 99% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodParameterImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/MethodParameterImpl.java with 96% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/main/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/MethodSignatureBuilderImpl.java [moved from opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/main/java/org/opendaylight/controller/sal/binding/generator/impl/MethodSignatureBuilderImpl.java with 99% similarity]
opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/test/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationBuilderTest.java [new file with mode: 0644]
opendaylight/sal/yang-prototype/code-generator/binding-java-api-generator/src/test/java/org/opendaylight/controller/sal/java/api/generator/test/GeneratorJavaFileTest.java

index d36f972..a161c25 100644 (file)
@@ -20,6 +20,8 @@ import java.util.Set;
 
 import org.opendaylight.controller.binding.generator.util.CodeGeneratorHelper;
 import org.opendaylight.controller.binding.generator.util.Types;
+import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
+import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
 import org.opendaylight.controller.sal.binding.generator.spi.TypeProvider;
 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/AnnotationBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-impl/src/test/java/org/opendaylight/controller/sal/binding/generator/impl/AnnotationBuilderTest.java
deleted file mode 100644 (file)
index f08b77f..0000000
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * 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.controller.sal.binding.generator.impl;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.junit.Test;
-import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
-
-public class AnnotationBuilderTest {
-
-    @Test
-    public void generatedTypeAnnotationTest() {
-        GeneratedTypeBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
-                "org.opendaylight.controller", "AnnotInterface");
-
-        genTypeBuilder.addAnnotation("javax.management", "MXBean");
-        final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation(
-                "javax.management", "Description");
-        annotDesc.addParameter("description", "some sort of interface");
-        
-        final GeneratedType genType = genTypeBuilder.toInstance();
-        
-        assertNotNull(genType);
-        assertNotNull(genType.getAnnotations());
-        assertEquals(2, genType.getAnnotations().size());
-        
-        int annotCount = 0;
-        for (final AnnotationType annotation : genType.getAnnotations()) {
-            if (annotation.getPackageName().equals("javax.management")
-                    && annotation.getName().equals("MXBean")) {
-                annotCount++;
-                assertEquals(0, annotation.getParameters().size());
-            }
-            if (annotation.getPackageName().equals("javax.management")
-                    && annotation.getName().equals("Description")) {
-                annotCount++;
-                assertEquals(1, annotation.getParameters().size());
-                AnnotationType.Parameter param = annotation.getParameter("description");
-                assertNotNull(param);
-                assertEquals("description", param.getName());
-                assertNotNull(param.getValue());
-                assertEquals("some sort of interface", param.getValue());
-                assertNotNull(param.getValues());
-                assertTrue(param.getValues().isEmpty());
-            }
-        }
-        assertEquals(2, annotCount);
-    }
-
-    @Test
-    public void methodSignatureAnnotationTest() {
-        //TODO  add test for method annotations
-    }
-
-    @Test
-    public void generatedPropertyAnnotationTest() {
-        //TODO add test for property annotations
-    }
-
-    @Test
-    public void generatedTransfeObjectAnnotationTest() {
-        final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
-                "org.opendaylight.controller", "AnnotClassCache");
-
-        genTypeBuilder.addAnnotation("javax.management", "MBean");
-        final AnnotationTypeBuilder annotNotify = genTypeBuilder.addAnnotation(
-                "javax.management", "NotificationInfo");
-
-        final List<String> notifyList = new ArrayList<String>();
-        notifyList.add("\"my.notif.type\"");
-        annotNotify.addParameters("types", notifyList);
-        annotNotify.addParameter("description",
-                "@Description(\"my notification\")");
-
-        GeneratedTransferObject genTO = genTypeBuilder.toInstance();
-
-        assertNotNull(genTO);
-        assertNotNull(genTO.getAnnotations());
-        assertEquals(2, genTO.getAnnotations().size());
-
-        int annotCount = 0;
-        for (final AnnotationType annotation : genTO.getAnnotations()) {
-            if (annotation.getPackageName().equals("javax.management")
-                    && annotation.getName().equals("MBean")) {
-                annotCount++;
-                assertEquals(0, annotation.getParameters().size());
-            }
-            if (annotation.getPackageName().equals("javax.management")
-                    && annotation.getName().equals("NotificationInfo")) {
-                annotCount++;
-                assertEquals(2, annotation.getParameters().size());
-                AnnotationType.Parameter param = annotation.getParameter("types");
-                assertNotNull(param);
-                assertEquals("types", param.getName());
-                assertNull(param.getValue());
-                assertNotNull(param.getValues());
-                assertEquals(1, param.getValues().size());
-                assertEquals("\"my.notif.type\"", param.getValues().get(0));
-                
-                param = annotation.getParameter("description");
-                assertNotNull(param);
-                assertEquals("description", param.getName());
-                assertNotNull(param.getValue());
-                assertEquals("@Description(\"my notification\")", param.getValue());
-            }
-        }
-        assertEquals(2, annotCount);
-    }
-}
@@ -5,7 +5,7 @@
  * 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.controller.sal.binding.generator.impl;
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
 import org.opendaylight.controller.sal.binding.model.api.Constant;
 import org.opendaylight.controller.sal.binding.model.api.Type;
@@ -5,7 +5,7 @@
  * 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.controller.sal.binding.generator.impl;
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -5,7 +5,7 @@
  * 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.controller.sal.binding.generator.impl;
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -26,7 +26,7 @@ import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedP
 import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
 import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
 
-final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
+public final class GeneratedTOBuilderImpl implements GeneratedTOBuilder {
     private String packageName;
     private final String name;
     private String comment = "";
@@ -5,7 +5,7 @@
  * 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.controller.sal.binding.generator.impl;
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
 import java.util.ArrayList;
 import java.util.Collections;
@@ -5,7 +5,7 @@
  * 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.controller.sal.binding.generator.impl;
+package org.opendaylight.controller.binding.generator.util.generated.type.builder;
 
 import org.opendaylight.controller.sal.binding.model.api.Type;
 import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
diff --git a/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/test/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationBuilderTest.java b/opendaylight/sal/yang-prototype/code-generator/binding-generator-util/src/test/java/org/opendaylight/controller/binding/generator/util/generated/type/builder/AnnotationBuilderTest.java
new file mode 100644 (file)
index 0000000..107dc59
--- /dev/null
@@ -0,0 +1,255 @@
+/*
+ * 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.controller.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.controller.binding.generator.util.Types;
+import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
+import org.opendaylight.controller.sal.binding.model.api.AnnotationType;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTOBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.MethodSignatureBuilder;
+
+public class AnnotationBuilderTest {
+
+    @Test
+    public void generatedTypeAnnotationTest() {
+        final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl(
+                "org.opendaylight.controller", "AnnotInterface");
+
+        genTypeBuilder.addAnnotation("javax.management", "MXBean");
+        final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation(
+                "javax.management", "Description");
+        annotDesc.addParameter("description", "some sort of interface");
+
+        final GeneratedType genType = genTypeBuilder.toInstance();
+
+        assertNotNull(genType);
+        assertNotNull(genType.getAnnotations());
+        assertEquals(2, genType.getAnnotations().size());
+
+        int annotCount = 0;
+        for (final AnnotationType annotation : genType.getAnnotations()) {
+            if (annotation.getPackageName().equals("javax.management")
+                    && annotation.getName().equals("MXBean")) {
+                annotCount++;
+                assertEquals(0, annotation.getParameters().size());
+            }
+            if (annotation.getPackageName().equals("javax.management")
+                    && annotation.getName().equals("Description")) {
+                annotCount++;
+                assertEquals(1, annotation.getParameters().size());
+                AnnotationType.Parameter param = annotation
+                        .getParameter("description");
+                assertNotNull(param);
+                assertEquals("description", param.getName());
+                assertNotNull(param.getValue());
+                assertEquals("some sort of interface", param.getValue());
+                assertNotNull(param.getValues());
+                assertTrue(param.getValues().isEmpty());
+            }
+        }
+        assertEquals(2, annotCount);
+    }
+
+    @Test
+    public void methodSignatureAnnotationTest() {
+        final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl(
+                "org.opendaylight.controller", "TransferObject");
+
+        final MethodSignatureBuilder methodBuilder = genTypeBuilder
+                .addMethod("simpleMethod");
+        methodBuilder.addReturnType(Types.typeForClass(Integer.class));
+        final AnnotationTypeBuilder annotManAttr = methodBuilder
+                .addAnnotation("org.springframework.jmx.export.annotation",
+                        "ManagedAttribute");
+
+        annotManAttr.addParameter("description", "\"The Name Attribute\"");
+        annotManAttr.addParameter("currencyTimeLimit", "20");
+        annotManAttr.addParameter("defaultValue", "\"bar\"");
+        annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
+
+        final AnnotationTypeBuilder annotManProp = methodBuilder
+                .addAnnotation("org.springframework.jmx.export.annotation",
+                        "ManagedOperation");
+
+        final List<String> typeValues = new ArrayList<String>();
+        typeValues.add("\"val1\"");
+        typeValues.add("\"val2\"");
+        typeValues.add("\"val3\"");
+        annotManProp.addParameters("types", typeValues);
+
+        final GeneratedType genType = genTypeBuilder.toInstance();
+
+        assertNotNull(genType);
+        assertNotNull(genType.getAnnotations());
+        assertNotNull(genType.getMethodDefinitions());
+        assertNotNull(genType.getMethodDefinitions().get(0));
+        assertNotNull(genType.getMethodDefinitions().get(0).getAnnotations());
+        final List<AnnotationType> annotations = genType.getMethodDefinitions()
+                .get(0).getAnnotations();
+        assertEquals(2, annotations.size());
+        
+        int annotCount = 0;
+        for (final AnnotationType annotation : annotations) {
+            if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
+                    && annotation.getName().equals("ManagedAttribute")) {
+                annotCount++;
+                assertEquals(4, annotation.getParameters().size());
+                
+                assertNotNull(annotation.getParameter("description"));
+                assertNotNull(annotation.getParameter("currencyTimeLimit"));
+                assertNotNull(annotation.getParameter("defaultValue"));
+                assertNotNull(annotation.getParameter("persistPolicy"));
+                assertEquals("\"The Name Attribute\"", annotation.getParameter("description").getValue());
+                assertEquals("20", annotation.getParameter("currencyTimeLimit").getValue());
+                assertEquals("\"bar\"", annotation.getParameter("defaultValue").getValue());
+                assertEquals("\"OnUpdate\"", annotation.getParameter("persistPolicy").getValue());
+            }
+            if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
+                    && annotation.getName().equals("ManagedOperation")) {
+                annotCount++;
+                
+                assertEquals(1, annotation.getParameters().size());
+                assertNotNull(annotation.getParameter("types"));
+                assertEquals(3, annotation.getParameter("types").getValues().size());
+            }
+        }
+        assertEquals(2, annotCount);
+    }
+
+    @Test
+    public void generatedPropertyAnnotationTest() {
+        final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(
+                "org.opendaylight.controller", "AnnotInterface");
+
+        final GeneratedPropertyBuilder propertyBuilder = genTOBuilder
+                .addProperty("simpleProperty");
+        propertyBuilder.addReturnType(Types.typeForClass(Integer.class));
+        final AnnotationTypeBuilder annotManAttr = propertyBuilder
+                .addAnnotation("org.springframework.jmx.export.annotation",
+                        "ManagedAttribute");
+
+        annotManAttr.addParameter("description", "\"The Name Attribute\"");
+        annotManAttr.addParameter("currencyTimeLimit", "20");
+        annotManAttr.addParameter("defaultValue", "\"bar\"");
+        annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
+
+        final AnnotationTypeBuilder annotManProp = propertyBuilder
+                .addAnnotation("org.springframework.jmx.export.annotation",
+                        "ManagedOperation");
+
+        final List<String> typeValues = new ArrayList<String>();
+        typeValues.add("\"val1\"");
+        typeValues.add("\"val2\"");
+        typeValues.add("\"val3\"");
+        annotManProp.addParameters("types", typeValues);
+
+        final GeneratedTransferObject genTransObj = genTOBuilder.toInstance();
+
+        assertNotNull(genTransObj);
+        assertNotNull(genTransObj.getAnnotations());
+        assertNotNull(genTransObj.getProperties());
+        assertNotNull(genTransObj.getProperties().get(0));
+        assertNotNull(genTransObj.getProperties().get(0).getAnnotations());
+        final List<AnnotationType> annotations = genTransObj.getProperties()
+                .get(0).getAnnotations();
+        assertEquals(2, annotations.size());
+        
+        int annotCount = 0;
+        for (final AnnotationType annotation : annotations) {
+            if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
+                    && annotation.getName().equals("ManagedAttribute")) {
+                annotCount++;
+                assertEquals(4, annotation.getParameters().size());
+                
+                assertNotNull(annotation.getParameter("description"));
+                assertNotNull(annotation.getParameter("currencyTimeLimit"));
+                assertNotNull(annotation.getParameter("defaultValue"));
+                assertNotNull(annotation.getParameter("persistPolicy"));
+                assertEquals("\"The Name Attribute\"", annotation.getParameter("description").getValue());
+                assertEquals("20", annotation.getParameter("currencyTimeLimit").getValue());
+                assertEquals("\"bar\"", annotation.getParameter("defaultValue").getValue());
+                assertEquals("\"OnUpdate\"", annotation.getParameter("persistPolicy").getValue());
+            }
+            if (annotation.getPackageName().equals("org.springframework.jmx.export.annotation")
+                    && annotation.getName().equals("ManagedOperation")) {
+                annotCount++;
+                
+                assertEquals(1, annotation.getParameters().size());
+                assertNotNull(annotation.getParameter("types"));
+                assertEquals(3, annotation.getParameter("types").getValues().size());
+            }
+        }
+        assertEquals(2, annotCount);
+    }
+
+    @Test
+    public void generatedTransfeObjectAnnotationTest() {
+        final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
+                "org.opendaylight.controller", "AnnotClassCache");
+
+        genTypeBuilder.addAnnotation("javax.management", "MBean");
+        final AnnotationTypeBuilder annotNotify = genTypeBuilder.addAnnotation(
+                "javax.management", "NotificationInfo");
+
+        final List<String> notifyList = new ArrayList<String>();
+        notifyList.add("\"my.notif.type\"");
+        annotNotify.addParameters("types", notifyList);
+        annotNotify.addParameter("description",
+                "@Description(\"my notification\")");
+
+        GeneratedTransferObject genTO = genTypeBuilder.toInstance();
+
+        assertNotNull(genTO);
+        assertNotNull(genTO.getAnnotations());
+        assertEquals(2, genTO.getAnnotations().size());
+
+        int annotCount = 0;
+        for (final AnnotationType annotation : genTO.getAnnotations()) {
+            if (annotation.getPackageName().equals("javax.management")
+                    && annotation.getName().equals("MBean")) {
+                annotCount++;
+                assertEquals(0, annotation.getParameters().size());
+            }
+            if (annotation.getPackageName().equals("javax.management")
+                    && annotation.getName().equals("NotificationInfo")) {
+                annotCount++;
+                assertEquals(2, annotation.getParameters().size());
+                AnnotationType.Parameter param = annotation
+                        .getParameter("types");
+                assertNotNull(param);
+                assertEquals("types", param.getName());
+                assertNull(param.getValue());
+                assertNotNull(param.getValues());
+                assertEquals(1, param.getValues().size());
+                assertEquals("\"my.notif.type\"", param.getValues().get(0));
+
+                param = annotation.getParameter("description");
+                assertNotNull(param);
+                assertEquals("description", param.getName());
+                assertNotNull(param.getValue());
+                assertEquals("@Description(\"my notification\")",
+                        param.getValue());
+            }
+        }
+        assertEquals(2, annotCount);
+    }
+}
index 4ab054d..5114457 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.controller.sal.java.api.generator.test;\r
-\r
-import static org.junit.Assert.*;\r
-\r
-import java.io.File;\r
-import java.util.ArrayList;\r
-import java.util.Arrays;\r
-import java.util.HashSet;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import javax.tools.JavaCompiler;\r
-import javax.tools.JavaFileObject;\r
-import javax.tools.StandardJavaFileManager;\r
-import javax.tools.ToolProvider;\r
-\r
-import org.junit.After;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;\r
-import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl;\r
-import org.opendaylight.controller.sal.binding.generator.impl.GeneratedTypeBuilderImpl;\r
-import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;\r
-import org.opendaylight.controller.sal.binding.model.api.GeneratedType;\r
-import org.opendaylight.controller.sal.binding.model.api.Type;\r
-import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;\r
-import org.opendaylight.controller.sal.java.api.generator.GeneratorJavaFile;\r
-import org.opendaylight.controller.sal.java.api.generator.InterfaceGenerator;\r
-import org.opendaylight.controller.yang.model.api.Module;\r
-import org.opendaylight.controller.yang.model.api.SchemaContext;\r
-import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl;\r
-\r
-public class GeneratorJavaFileTest {\r
-    private static final String FS = File.separator;\r
-    private static final String PATH = "test-dir";\r
-    private final File testDir = new File(PATH);\r
-\r
-    private static final String GENERATOR_OUTPUT_PATH = "src/test/resources/src";\r
-    private static final File GENERATOR_OUTPUT = new File(GENERATOR_OUTPUT_PATH);\r
-    private static final String COMPILER_OUTPUT_PATH = "src/test/resources/bin";\r
-    private static final File COMPILER_OUTPUT = new File(COMPILER_OUTPUT_PATH);\r
-\r
-    @Before\r
-    public void init() {\r
-        assertTrue(testDir.mkdir());\r
-        assertTrue(COMPILER_OUTPUT.mkdirs());\r
-        assertTrue(GENERATOR_OUTPUT.mkdirs());\r
-    }\r
-\r
-    @After\r
-    public void cleanUp() {\r
-        deleteTestDir(testDir);\r
-        deleteTestDir(COMPILER_OUTPUT);\r
-        deleteTestDir(GENERATOR_OUTPUT);\r
-    }\r
-\r
-    @Test\r
-    public void test() {\r
-        final Set<GeneratedType> types = new HashSet<GeneratedType>();\r
-        GeneratedType t1 = createGeneratedType(\r
-                "org.opendaylight.controller.gen", "Type1");\r
-        GeneratedType t2 = createGeneratedType(\r
-                "org.opendaylight.controller.gen", "Type2");\r
-        GeneratedType t3 = createGeneratedType(\r
-                "org.opendaylight.controller.gen", "Type3");\r
-        types.add(t1);\r
-        types.add(t2);\r
-        types.add(t3);\r
-        GeneratorJavaFile generator = new GeneratorJavaFile(\r
-                new InterfaceGenerator(), types);\r
-        generator.generateToFile(PATH);\r
-\r
-        // path: test-dir/com/cisco/yang\r
-        String[] files = new File(PATH + FS + "org" + FS + "opendaylight" + FS + "controller" + FS + "gen").list();\r
-        List<String> filesList = Arrays.asList(files);\r
-\r
-        assertEquals(3, files.length);\r
-        assertTrue(filesList.contains("Type1.java"));\r
-        assertTrue(filesList.contains("Type2.java"));\r
-        assertTrue(filesList.contains("Type3.java"));\r
-    }\r
-\r
-    @Test\r
-    public void compilationTest() throws Exception {\r
-        final YangModelParserImpl parser = new YangModelParserImpl();\r
-        final BindingGenerator bindingGenerator = new BindingGeneratorImpl();\r
-\r
-        File sourcesDir = new File("src/test/resources/yang");\r
-        File[] sourceFiles = sourcesDir.listFiles();\r
-        String[] sourcesDirPaths = new String[sourceFiles.length];\r
-        for (int i = 0; i < sourceFiles.length; i++) {\r
-            sourcesDirPaths[i] = sourceFiles[i].getAbsolutePath();\r
-        }\r
-        final Set<Module> modulesToBuild = parser\r
-                .parseYangModels(sourcesDirPaths);\r
-\r
-        final SchemaContext context = parser\r
-                .resolveSchemaContext(modulesToBuild);\r
-        final List<Type> types = bindingGenerator.generateTypes(context);\r
-        final Set<GeneratedType> typesToGenerate = new HashSet<GeneratedType>();\r
-        final Set<GeneratedTransferObject> tosToGenerate = new HashSet<GeneratedTransferObject>();\r
-        for (Type type : types) {\r
-            if (type instanceof GeneratedType) {\r
-                typesToGenerate.add((GeneratedType) type);\r
-            }\r
-\r
-            if (type instanceof GeneratedTransferObject) {\r
-                tosToGenerate.add((GeneratedTransferObject) type);\r
-            }\r
-        }\r
-\r
-        final GeneratorJavaFile generator = new GeneratorJavaFile(\r
-                typesToGenerate, tosToGenerate);\r
-        generator.generateToFile(GENERATOR_OUTPUT_PATH);\r
-\r
-        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();\r
-        StandardJavaFileManager fileManager = compiler.getStandardFileManager(\r
-                null, null, null);\r
-\r
-        List<File> filesList = getJavaFiles(new File(GENERATOR_OUTPUT_PATH));\r
-\r
-        Iterable<? extends JavaFileObject> compilationUnits = fileManager\r
-                .getJavaFileObjectsFromFiles(filesList);\r
-        Iterable<String> options = Arrays.asList(new String[] { "-d",\r
-                COMPILER_OUTPUT_PATH });\r
-        boolean compiled = compiler.getTask(null, null, null, options, null,\r
-                compilationUnits).call();\r
-        assertTrue(compiled);\r
-    }\r
-\r
-    private GeneratedType createGeneratedType(String pkgName, String name) {\r
-        GeneratedTypeBuilder builder = new GeneratedTypeBuilderImpl(pkgName,\r
-                name);\r
-        return builder.toInstance();\r
-    }\r
-\r
-    private void deleteTestDir(File file) {\r
-        if (file.isDirectory()) {\r
-            for (File f : file.listFiles()) {\r
-                deleteTestDir(f);\r
-            }\r
-        }\r
-        if (!file.delete()) {\r
-            throw new RuntimeException("Failed to clean up after test");\r
-        }\r
-    }\r
-\r
-    /**\r
-     * Search recursively given directory for *.java files.\r
-     *\r
-     * @param directory\r
-     *            directory to search\r
-     * @return List of java files found\r
-     */\r
-    private List<File> getJavaFiles(File directory) {\r
-        List<File> result = new ArrayList<File>();\r
-        for (File file : directory.listFiles()) {\r
-            if (file.isDirectory()) {\r
-                result.addAll(getJavaFiles(file));\r
-            } else {\r
-                String absPath = file.getAbsolutePath();\r
-                if (absPath.endsWith(".java")) {\r
-                    result.add(file);\r
-                }\r
-            }\r
-        }\r
-        return result;\r
-    }\r
-\r
-}\r
+/*
+ * 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.controller.sal.java.api.generator.test;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.tools.JavaCompiler;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.ToolProvider;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
+import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
+import org.opendaylight.controller.sal.binding.generator.impl.BindingGeneratorImpl;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
+import org.opendaylight.controller.sal.binding.model.api.Type;
+import org.opendaylight.controller.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
+import org.opendaylight.controller.sal.java.api.generator.GeneratorJavaFile;
+import org.opendaylight.controller.sal.java.api.generator.InterfaceGenerator;
+import org.opendaylight.controller.yang.model.api.Module;
+import org.opendaylight.controller.yang.model.api.SchemaContext;
+import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl;
+
+public class GeneratorJavaFileTest {
+    private static final String FS = File.separator;
+    private static final String PATH = "test-dir";
+    private final File testDir = new File(PATH);
+
+    private static final String GENERATOR_OUTPUT_PATH = "src/test/resources/src";
+    private static final File GENERATOR_OUTPUT = new File(GENERATOR_OUTPUT_PATH);
+    private static final String COMPILER_OUTPUT_PATH = "src/test/resources/bin";
+    private static final File COMPILER_OUTPUT = new File(COMPILER_OUTPUT_PATH);
+
+    @Before
+    public void init() {
+        assertTrue(testDir.mkdir());
+        assertTrue(COMPILER_OUTPUT.mkdirs());
+        assertTrue(GENERATOR_OUTPUT.mkdirs());
+    }
+
+    @After
+    public void cleanUp() {
+        deleteTestDir(testDir);
+        deleteTestDir(COMPILER_OUTPUT);
+        deleteTestDir(GENERATOR_OUTPUT);
+    }
+
+    @Test
+    public void test() {
+        final Set<GeneratedType> types = new HashSet<GeneratedType>();
+        GeneratedType t1 = createGeneratedType(
+                "org.opendaylight.controller.gen", "Type1");
+        GeneratedType t2 = createGeneratedType(
+                "org.opendaylight.controller.gen", "Type2");
+        GeneratedType t3 = createGeneratedType(
+                "org.opendaylight.controller.gen", "Type3");
+        types.add(t1);
+        types.add(t2);
+        types.add(t3);
+        GeneratorJavaFile generator = new GeneratorJavaFile(
+                new InterfaceGenerator(), types);
+        generator.generateToFile(PATH);
+
+        // path: test-dir/com/cisco/yang
+        String[] files = new File(PATH + FS + "org" + FS + "opendaylight" + FS + "controller" + FS + "gen").list();
+        List<String> filesList = Arrays.asList(files);
+
+        assertEquals(3, files.length);
+        assertTrue(filesList.contains("Type1.java"));
+        assertTrue(filesList.contains("Type2.java"));
+        assertTrue(filesList.contains("Type3.java"));
+    }
+
+    @Test
+    public void compilationTest() throws Exception {
+        final YangModelParserImpl parser = new YangModelParserImpl();
+        final BindingGenerator bindingGenerator = new BindingGeneratorImpl();
+
+        File sourcesDir = new File("src/test/resources/yang");
+        File[] sourceFiles = sourcesDir.listFiles();
+        String[] sourcesDirPaths = new String[sourceFiles.length];
+        for (int i = 0; i < sourceFiles.length; i++) {
+            sourcesDirPaths[i] = sourceFiles[i].getAbsolutePath();
+        }
+        final Set<Module> modulesToBuild = parser
+                .parseYangModels(sourcesDirPaths);
+
+        final SchemaContext context = parser
+                .resolveSchemaContext(modulesToBuild);
+        final List<Type> types = bindingGenerator.generateTypes(context);
+        final Set<GeneratedType> typesToGenerate = new HashSet<GeneratedType>();
+        final Set<GeneratedTransferObject> tosToGenerate = new HashSet<GeneratedTransferObject>();
+        for (Type type : types) {
+            if (type instanceof GeneratedType) {
+                typesToGenerate.add((GeneratedType) type);
+            }
+
+            if (type instanceof GeneratedTransferObject) {
+                tosToGenerate.add((GeneratedTransferObject) type);
+            }
+        }
+
+        final GeneratorJavaFile generator = new GeneratorJavaFile(
+                typesToGenerate, tosToGenerate);
+        generator.generateToFile(GENERATOR_OUTPUT_PATH);
+
+        JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
+        StandardJavaFileManager fileManager = compiler.getStandardFileManager(
+                null, null, null);
+
+        List<File> filesList = getJavaFiles(new File(GENERATOR_OUTPUT_PATH));
+
+        Iterable<? extends JavaFileObject> compilationUnits = fileManager
+                .getJavaFileObjectsFromFiles(filesList);
+        Iterable<String> options = Arrays.asList(new String[] { "-d",
+                COMPILER_OUTPUT_PATH });
+        boolean compiled = compiler.getTask(null, null, null, options, null,
+                compilationUnits).call();
+        assertTrue(compiled);
+    }
+
+    private GeneratedType createGeneratedType(String pkgName, String name) {
+        GeneratedTypeBuilder builder = new GeneratedTypeBuilderImpl(pkgName,
+                name);
+        return builder.toInstance();
+    }
+
+    private void deleteTestDir(File file) {
+        if (file.isDirectory()) {
+            for (File f : file.listFiles()) {
+                deleteTestDir(f);
+            }
+        }
+        if (!file.delete()) {
+            throw new RuntimeException("Failed to clean up after test");
+        }
+    }
+
+    /**
+     * Search recursively given directory for *.java files.
+     *
+     * @param directory
+     *            directory to search
+     * @return List of java files found
+     */
+    private List<File> getJavaFiles(File directory) {
+        List<File> result = new ArrayList<File>();
+        for (File file : directory.listFiles()) {
+            if (file.isDirectory()) {
+                result.addAll(getJavaFiles(file));
+            } else {
+                String absPath = file.getAbsolutePath();
+                if (absPath.endsWith(".java")) {
+                    result.add(file);
+                }
+            }
+        }
+        return result;
+    }
+
+}

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.