summaryrefslogtreecommitdiffstats
path: root/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor
diff options
context:
space:
mode:
Diffstat (limited to 'container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor')
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/AbstractResource.java12
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/DummyAnnotation.java11
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InnerClass.java12
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InterfaceResource.java12
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NestedClass.java12
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NonPublicNestedClass.java12
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Provider.java9
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Resource.java11
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.scala75
-rw-r--r--container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceWithMultipleAnnotations.java13
10 files changed, 179 insertions, 0 deletions
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/AbstractResource.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/AbstractResource.java
new file mode 100644
index 00000000000..9fa77b4753a
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/AbstractResource.java
@@ -0,0 +1,12 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author tonytv
+ */
+@Path("ignored")
+public abstract class AbstractResource {
+
+}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/DummyAnnotation.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/DummyAnnotation.java
new file mode 100644
index 00000000000..296615fead4
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/DummyAnnotation.java
@@ -0,0 +1,11 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * @author tonytv
+ */
+@Retention(RetentionPolicy.RUNTIME)
+public @interface DummyAnnotation {}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InnerClass.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InnerClass.java
new file mode 100644
index 00000000000..d4bcadde3fa
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InnerClass.java
@@ -0,0 +1,12 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author tonytv
+ */
+public class InnerClass {
+ @Path("ignored")
+ public class Inner {}
+}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InterfaceResource.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InterfaceResource.java
new file mode 100644
index 00000000000..f969fa2d478
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/InterfaceResource.java
@@ -0,0 +1,12 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author tonytv
+ */
+@Path("ignored")
+public interface InterfaceResource {
+
+}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NestedClass.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NestedClass.java
new file mode 100644
index 00000000000..e386f4c3cdd
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NestedClass.java
@@ -0,0 +1,12 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author tonytv
+ */
+public class NestedClass {
+ @Path("ignored")
+ public static class Nested {}
+}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NonPublicNestedClass.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NonPublicNestedClass.java
new file mode 100644
index 00000000000..3af7c0be20f
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/NonPublicNestedClass.java
@@ -0,0 +1,12 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author tonytv
+ */
+public class NonPublicNestedClass {
+ @Path("ignored")
+ static class Nested {}
+}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Provider.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Provider.java
new file mode 100644
index 00000000000..a641d934032
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Provider.java
@@ -0,0 +1,9 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+/**
+ * @author tonytv
+ */
+@javax.ws.rs.ext.Provider
+public class Provider {
+}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Resource.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Resource.java
new file mode 100644
index 00000000000..65d696aed49
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/Resource.java
@@ -0,0 +1,11 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author tonytv
+ */
+@Path("ignored")
+public class Resource {
+}
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.scala b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.scala
new file mode 100644
index 00000000000..3d4bbcecd48
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceOrProviderClassVisitorTest.scala
@@ -0,0 +1,75 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor
+
+import com.yahoo.container.servlet.jersey.{ResourceOrProviderClassVisitor, classvisitor}
+import org.junit.{Assert, Test}
+import org.objectweb.asm.ClassReader
+
+import Assert.assertThat
+import org.hamcrest.CoreMatchers.is
+
+import scala.reflect.ClassTag
+
+class ResourceOrProviderClassVisitorTest {
+ @Test
+ def resource_is_detected() {
+ assert_is_accepted[classvisitor.Resource]
+ }
+
+ @Test
+ def provider_is_detected() {
+ assert_is_accepted[classvisitor.Provider]
+ }
+
+ @Test
+ def inner_class_is_ignored() {
+ assert_is_ignored[classvisitor.InnerClass#Inner]
+ }
+
+ @Test
+ def nested_public_class_is_detected() {
+ assert_is_accepted[classvisitor.NestedClass.Nested]
+ }
+
+ @Test
+ def nested_non_public_class_is_ignored() {
+ assert_is_ignored[classvisitor.NonPublicNestedClass.Nested]
+ }
+
+ @Test
+ def resource_with_multiple_annotations_is_detected() {
+ assert_is_accepted[classvisitor.ResourceWithMultipleAnnotations]
+ }
+
+ def interface_is_ignored() {
+ assert_is_ignored[classvisitor.InterfaceResource]
+ }
+
+ @Test
+ def abstract_class_is_ignored() {
+ assert_is_ignored[classvisitor.AbstractResource]
+ }
+
+ @Test
+ def className_is_equal_to_getName() {
+ assertThat(analyzeClass[classvisitor.Resource].getClassName, is(classOf[classvisitor.Resource].getName))
+ }
+
+ def assert_is_accepted[T: ClassTag] {
+ Assert.assertTrue(className[T] + " was not accepted",
+ analyzeClass[T].isJerseyClass)
+ }
+
+ def assert_is_ignored[T: ClassTag] {
+ Assert.assertFalse(className[T] + " was not ignored",
+ analyzeClass[T].isJerseyClass)
+ }
+
+ def analyzeClass[T: ClassTag] = {
+ ResourceOrProviderClassVisitor.visit(new ClassReader(className[T]))
+ }
+
+ def className[T: ClassTag] = implicitly[ClassTag[T]].runtimeClass.getName
+}
+
+
diff --git a/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceWithMultipleAnnotations.java b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceWithMultipleAnnotations.java
new file mode 100644
index 00000000000..fbdb4cae726
--- /dev/null
+++ b/container-jersey2/src/test/java/com/yahoo/container/servlet/jersey/classvisitor/ResourceWithMultipleAnnotations.java
@@ -0,0 +1,13 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.container.servlet.jersey.classvisitor;
+
+import javax.ws.rs.Path;
+
+/**
+ * @author tonytv
+ */
+@Path("ignored")
+@DummyAnnotation
+public class ResourceWithMultipleAnnotations {
+
+}