summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStuart Halloway <stu@thinkrelevance.com>2010-04-29 13:03:13 -0400
committerStuart Halloway <stu@thinkrelevance.com>2010-05-01 03:31:21 -0400
commit423e0b7c7d38fc5eb759829c3b38965c2784ab65 (patch)
tree1a2d8f572f128acfa645f39ef50b3c669c20e73e
parent762d1531b6440722d5d1c0dfee4776d99289385e (diff)
split annotations test into java 5 / later
Signed-off-by: Stuart Halloway <stu@thinkrelevance.com>
-rw-r--r--test/clojure/test_clojure.clj2
-rw-r--r--test/clojure/test_clojure/annotations.clj90
-rw-r--r--test/clojure/test_clojure/annotations/java_5.clj54
-rw-r--r--test/clojure/test_clojure/annotations/java_6_and_later.clj73
4 files changed, 144 insertions, 75 deletions
diff --git a/test/clojure/test_clojure.clj b/test/clojure/test_clojure.clj
index fa9286d0..bb5e8412 100644
--- a/test/clojure/test_clojure.clj
+++ b/test/clojure/test_clojure.clj
@@ -52,7 +52,7 @@
:genclass
:main
:vectors
- ;:annotations
+ :annotations
])
(def test-namespaces
diff --git a/test/clojure/test_clojure/annotations.clj b/test/clojure/test_clojure/annotations.clj
index f5b4f4a2..842906e2 100644
--- a/test/clojure/test_clojure/annotations.clj
+++ b/test/clojure/test_clojure/annotations.clj
@@ -11,77 +11,19 @@
(ns clojure.test-clojure.annotations
(:use clojure.test))
-(import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType]
- [javax.xml.ws WebServiceRef WebServiceRefs])
-(definterface Foo (foo []))
-
-;annotation on type
-(deftype #^{Deprecated true
- Retention RetentionPolicy/RUNTIME
- javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
- javax.xml.ws.soap.Addressing {:enabled false :required true}
- WebServiceRefs [(WebServiceRef {:name "fred" :type String})
- (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
- Bar [#^int a
- ;on field
- #^{:tag int
- Deprecated true
- Retention RetentionPolicy/RUNTIME
- javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
- javax.xml.ws.soap.Addressing {:enabled false :required true}
- WebServiceRefs [(WebServiceRef {:name "fred" :type String})
- (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
- b]
- ;on method
- Foo (#^{Deprecated true
- Retention RetentionPolicy/RUNTIME
- javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
- javax.xml.ws.soap.Addressing {:enabled false :required true}
- WebServiceRefs [(WebServiceRef {:name "fred" :type String})
- (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
- foo [this] 42))
-
-(defn annotation->map
- "Converts a Java annotation (which conceals data)
- into a map (which makes is usable). Not lazy.
- Works recursively. Returns non-annotations unscathed."
- [#^java.lang.annotation.Annotation o]
- (cond
- (instance? Annotation o)
- (let [type (.annotationType o)
- itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation))
- data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))]
- (into
- {:annotation-type (.annotationType o)}
- (map
- (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))])
- data-methods)))
- (or (sequential? o) (.isArray (class o)))
- (map annotation->map o)
- :else o))
-
-(def expected-annotations
- #{{:annotation-type java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME}
- {:annotation-type javax.xml.ws.WebServiceRefs,
- :value [{:annotation-type javax.xml.ws.WebServiceRef, :name "fred", :mappedName "", :type java.lang.String, :wsdlLocation "", :value java.lang.Object}
- {:annotation-type javax.xml.ws.WebServiceRef, :name "ethel", :mappedName "lucy", :type java.lang.Object, :wsdlLocation "", :value java.lang.Object}]}
- {:annotation-type javax.xml.ws.soap.Addressing, :enabled false, :required true}
- {:annotation-type javax.annotation.processing.SupportedOptions, :value ["foo" "bar" "baz"]}
- {:annotation-type java.lang.Deprecated}})
-
-(deftest test-annotations-on-type
- (is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations Bar))))))
-
-(deftest test-annotations-on-field
- (is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations (.getField Bar "b")))))))
-
-(deftest test-annotations-on-method
- (is (=
- expected-annotations
- (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
-
-
+(defn vm-has-ws-annotations?
+ "Does the vm have the ws annotations we use to test some
+ annotation features. If not, fall back to Java 5 tests."
+ []
+ (try
+ (doseq [n ["javax.xml.ws.soap.Addressing"
+ "javax.xml.ws.WebServiceRef"
+ "javax.xml.ws.WebServiceRefs"]]
+ (Class/forName n))
+ true
+ (catch ClassNotFoundException e
+ false)))
+
+(if (vm-has-ws-annotations?)
+ (load "annotations/java_6_and_later")
+ (load "annotations/java_5"))
diff --git a/test/clojure/test_clojure/annotations/java_5.clj b/test/clojure/test_clojure/annotations/java_5.clj
new file mode 100644
index 00000000..28daae19
--- /dev/null
+++ b/test/clojure/test_clojure/annotations/java_5.clj
@@ -0,0 +1,54 @@
+;; java 5 annotation tests
+(in-ns 'clojure.test-clojure.annotations)
+
+(import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType])
+(definterface Foo (foo []))
+
+(deftype #^{Deprecated true
+ Retention RetentionPolicy/RUNTIME}
+ Bar [#^int a
+ #^{:tag int
+ Deprecated true
+ Retention RetentionPolicy/RUNTIME} b]
+ Foo (#^{Deprecated true
+ Retention RetentionPolicy/RUNTIME}
+ foo [this] 42))
+
+(defn annotation->map
+ "Converts a Java annotation (which conceals data)
+ into a map (which makes is usable). Not lazy.
+ Works recursively. Returns non-annotations unscathed."
+ [#^java.lang.annotation.Annotation o]
+ (cond
+ (instance? Annotation o)
+ (let [type (.annotationType o)
+ itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation))
+ data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))]
+ (into
+ {:annotationType (.annotationType o)}
+ (map
+ (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))])
+ data-methods)))
+ (or (sequential? o) (.isArray (class o)))
+ (map annotation->map o)
+ :else o))
+
+(def expected-annotations
+ #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME}
+ {:annotationType java.lang.Deprecated}})
+
+(deftest test-annotations-on-type
+ (is (=
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations Bar))))))
+
+(deftest test-annotations-on-field
+ (is (=
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getField Bar "b")))))))
+
+(deftest test-annotations-on-method
+ (is (=
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
+
diff --git a/test/clojure/test_clojure/annotations/java_6_and_later.clj b/test/clojure/test_clojure/annotations/java_6_and_later.clj
new file mode 100644
index 00000000..49d2404e
--- /dev/null
+++ b/test/clojure/test_clojure/annotations/java_6_and_later.clj
@@ -0,0 +1,73 @@
+;; java 6 annotation tests
+(in-ns 'clojure.test-clojure.annotations)
+
+(import [java.lang.annotation Annotation Retention RetentionPolicy Target ElementType]
+ [javax.xml.ws WebServiceRef WebServiceRefs])
+(definterface Foo (foo []))
+
+(deftype #^{Deprecated true
+ Retention RetentionPolicy/RUNTIME
+ javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
+ javax.xml.ws.soap.Addressing {:enabled false :required true}
+ WebServiceRefs [(WebServiceRef {:name "fred" :type String})
+ (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
+ Bar [#^int a
+ #^{:tag int
+ Deprecated true
+ Retention RetentionPolicy/RUNTIME
+ javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
+ javax.xml.ws.soap.Addressing {:enabled false :required true}
+ WebServiceRefs [(WebServiceRef {:name "fred" :type String})
+ (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
+ b]
+ Foo (#^{Deprecated true
+ Retention RetentionPolicy/RUNTIME
+ javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
+ javax.xml.ws.soap.Addressing {:enabled false :required true}
+ WebServiceRefs [(WebServiceRef {:name "fred" :type String})
+ (WebServiceRef {:name "ethel" :mappedName "lucy"})]}
+ foo [this] 42))
+
+(defn annotation->map
+ "Converts a Java annotation (which conceals data)
+ into a map (which makes is usable). Not lazy.
+ Works recursively. Returns non-annotations unscathed."
+ [#^java.lang.annotation.Annotation o]
+ (cond
+ (instance? Annotation o)
+ (let [type (.annotationType o)
+ itfs (-> (into #{type} (supers type)) (disj java.lang.annotation.Annotation))
+ data-methods (into #{} (mapcat #(.getDeclaredMethods %) itfs))]
+ (into
+ {:annotationType (.annotationType o)}
+ (map
+ (fn [m] [(keyword (.getName m)) (annotation->map (.invoke m o nil))])
+ data-methods)))
+ (or (sequential? o) (.isArray (class o)))
+ (map annotation->map o)
+ :else o))
+
+(def expected-annotations
+ #{{:annotationType java.lang.annotation.Retention, :value RetentionPolicy/RUNTIME}
+ {:annotationType javax.xml.ws.WebServiceRefs,
+ :value [{:annotationType javax.xml.ws.WebServiceRef, :name "fred", :mappedName "", :type java.lang.String, :wsdlLocation "", :value java.lang.Object}
+ {:annotationType javax.xml.ws.WebServiceRef, :name "ethel", :mappedName "lucy", :type java.lang.Object, :wsdlLocation "", :value java.lang.Object}]}
+ {:annotationType javax.xml.ws.soap.Addressing, :enabled false, :required true}
+ {:annotationType javax.annotation.processing.SupportedOptions, :value ["foo" "bar" "baz"]}
+ {:annotationType java.lang.Deprecated}})
+
+(deftest test-annotations-on-type
+ (is (=
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations Bar))))))
+
+(deftest test-annotations-on-field
+ (is (=
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getField Bar "b")))))))
+
+(deftest test-annotations-on-method
+ (is (=
+ expected-annotations
+ (into #{} (map annotation->map (.getAnnotations (.getMethod Bar "foo" nil)))))))
+