From d3973e88039bb90d604ba570b0bbc6c2dc5f30aa Mon Sep 17 00:00:00 2001 From: juanf <juanf> Date: Mon, 7 Dec 2015 11:50:34 +0000 Subject: [PATCH] SSDM-2788 : Report basic tests SVN: 35222 --- .../html/test/test-jsVSjava.js | 35 ++++++++++++++++ .../ch/ethz/sis/openbis/v3/APIReport.java | 41 ++++++++++++++++++- 2 files changed, 75 insertions(+), 1 deletion(-) diff --git a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-jsVSjava.js b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-jsVSjava.js index 2453ac7020d..616c6c1ef9f 100644 --- a/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-jsVSjava.js +++ b/js-test/servers/common/core-plugins/tests/1/as/webapps/openbis-v3-api-test/html/test/test-jsVSjava.js @@ -5,6 +5,40 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common' ], function($, _, open return function() { QUnit.module("JS VS JAVA API"); +// var packageNameHandlers = { +// } +// +// var jsonObjectAnnotationHandlers = { +// +// } +// +// var standardHandler = function(javaDef, jsDef) { +// +// } + + var areClassesCorrect = function(report) { + for(var ridx = 0; ridx < report.entries.length; ridx++) { + var javaClassReport = report.entries[ridx]; + var javaClassName = javaClassReport.name; + var jsClassName = javaClassReport.jsonObjAnnotation; + if(jsClassName) { + var errorHandler = function(javaClassName) { + return function() { + console.info("Java class with jsonObjectAnnotation missing in Javascript: " + javaClassName); + }; + }; + var requireJsPath = jsClassName.replace(/\./g,'/'); + require([requireJsPath], function(myclass){ + var test = "break"; + }, errorHandler(javaClassName)); + } else { + console.info("Java class missing jsonObjectAnnotation: " + javaClassName); + } + + } + return true; + } + QUnit.test("get Java report from aggregation service", function(assert) { var c = new common(assert); c.start(); @@ -20,6 +54,7 @@ define([ 'jquery', 'underscore', 'openbis', 'test/common' ], function($, _, open } if(report) { + areClassesCorrect(report); c.ok("Report received"); } else { c.fail("Report Missing"); diff --git a/js-test/sourceTest/java/ch/ethz/sis/openbis/v3/APIReport.java b/js-test/sourceTest/java/ch/ethz/sis/openbis/v3/APIReport.java index fece36fef05..8ba2686c41d 100644 --- a/js-test/sourceTest/java/ch/ethz/sis/openbis/v3/APIReport.java +++ b/js-test/sourceTest/java/ch/ethz/sis/openbis/v3/APIReport.java @@ -15,7 +15,9 @@ package ch.ethz.sis.openbis.v3; * limitations under the License. */ +import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.util.ArrayList; @@ -109,6 +111,29 @@ public class APIReport return uniqueClasses; } + private String getJSONObjectAnnotation(Class<?> clazz) + { + Annotation[] annotations = clazz.getAnnotations(); + for(Annotation annotation:annotations) { + Class<? extends Annotation> type = annotation.annotationType(); + String name = type.getName(); + if(name.equals("ch.systemsx.cisd.base.annotation.JsonObject")) { + + for (Method method : type.getDeclaredMethods()) { + try + { + Object value = method.invoke(annotation, (Object[]) null); + return (String) value; + } catch (Exception e) + { + e.printStackTrace(); + } + } + } + } + return null; + } + private Collection<Field> getPublicFields(Class<?> clazz) { Collection<Field> fields = new ArrayList<Field>(); @@ -141,6 +166,7 @@ public class APIReport for (Class<?> clazz : classes) { Entry entry = new Entry(clazz.getName()); + entry.setJsonObjAnnotation(getJSONObjectAnnotation(clazz)); addFields(entry, getPublicFields(clazz)); addMethods(entry, getPublicMethods(clazz)); report.add(entry); @@ -183,7 +209,9 @@ public class APIReport static class Entry { private String Name; - + + private String jsonObjAnnotation; + private List<String> fields = new ArrayList<String>(); private List<String> methods = new ArrayList<String>(); @@ -199,6 +227,17 @@ public class APIReport return this.Name; } + + public String getJsonObjAnnotation() + { + return this.jsonObjAnnotation; + } + + public void setJsonObjAnnotation(String jsonObjAnnotation) + { + this.jsonObjAnnotation = jsonObjAnnotation; + } + public List<String> getFields() { return this.fields; -- GitLab