View Javadoc

1   package com.atlassian.plugins.rest.common.feature.jersey.test;
2   
3   import com.atlassian.plugins.rest.common.feature.RequiresDarkFeature;
4   
5   import java.lang.reflect.Method;
6   import javax.ws.rs.GET;
7   import javax.ws.rs.Path;
8   import javax.ws.rs.core.Response;
9   
10  import static java.lang.String.format;
11  
12  /**
13   * A dummy resource that includes annotation and non-annotated methods.
14   * <p>
15   * For use in unit tests.
16   */
17  @SuppressWarnings("unused")
18  @Path("/darkfeaturetest")
19  public class DarkFeatureTestResource {
20      public static final String FEATURE_KEY = "feature.key";
21  
22      @GET
23      @Path("/annotated")
24      @RequiresDarkFeature(FEATURE_KEY)
25      public Response annotatedMethod() {
26          return Response.ok().build();
27      }
28  
29      @GET
30      @Path("/nonAnnotated")
31      public Response nonAnnotatedMethod() {
32          return Response.ok().build();
33      }
34  
35      public static Method getAnnotatedMethod() {
36          return getMethod("annotatedMethod");
37      }
38  
39      public static Method getNonAnnotatedMethod() {
40          return getMethod("nonAnnotatedMethod");
41      }
42  
43      private static Method getMethod(final String name) {
44          try {
45              return DarkFeatureTestResource.class.getMethod(name);
46          } catch (NoSuchMethodException e) {
47              throw new IllegalStateException(format("Method '%s' not found. Did you accidentally delete it?", name));
48          }
49      }
50  }