AbstractResourceDescriptor extends BaseObjectModel implements ResourceDescriptor { @Override public Map<String, List<ResourceMethodDescriptor>> getResourceMethods() { return resourceMethods; } AbstractResourceDescriptor(Class<?> resourceClass);  AbstractResourceDescriptor(String path, Class<?> resourceClass);  AbstractResourceDescriptor(Object resource);  AbstractResourceDescriptor(String path, Object resource); @Override PathValue getPathValue(); @Override Map<String, List<ResourceMethodDescriptor>> getResourceMethods(); @Override Map<UriPattern, SubResourceLocatorDescriptor> getSubResourceLocators(); @Override Map<UriPattern, Map<String, List<SubResourceMethodDescriptor>>> getSubResourceMethods(); @Override UriPattern getUriPattern(); @Override boolean isRootResource(); @Override String toString();  }
@Test public void adds_OPTIONS_HttpMethodThatGenerated_WADL_Response() { ResourceDescriptor resource = new AbstractResourceDescriptor(SampleRootResource.class); assertNotNull(resource.getResourceMethods().get("OPTIONS")); assertEquals(1, resource.getResourceMethods().get("OPTIONS").size()); ResourceMethodDescriptor methodDescriptor = resource.getResourceMethods().get("OPTIONS").get(0); assertNull(methodDescriptor.getMethod()); assertEquals("OPTIONS", methodDescriptor.getHttpMethod()); assertEquals(newArrayList(WILDCARD_TYPE), methodDescriptor.consumes()); assertEquals(newArrayList(new MediaType("application", "vnd.sun.wadl+xml")), methodDescriptor.produces()); assertEquals(SampleRootResource.class, methodDescriptor.getParentResource().getObjectClass()); assertTrue(methodDescriptor.getMethodParameters().isEmpty()); }
@Test public void sortsResourceMethodsByConsumesAndProducesTypes() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceForTestSortingOfResourceMethods.class); List<String> methodNames = resource.getResourceMethods().get("GET").stream().map(resourceMethod -> resourceMethod.getMethod().getName()).collect(toList()); assertEquals(newArrayList("first", "second", "third", "fourth", "fifth", "last"), methodNames); }
@Test public void processesSecurityAnnotationFromMethod() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceWithMethodWithSecurityAnnotation.class); List<ResourceMethodDescriptor> resourceMethods = resource.getResourceMethods().get("GET"); assertEquals(1, resourceMethods.get(0).getAnnotations().length); RolesAllowed rolesAllowed = (RolesAllowed)resourceMethods.get(0).getAnnotations()[0]; assertNotNull(rolesAllowed); }
@Test public void processesSecurityAnnotationFromClass() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceWithSecurityAnnotation.class); List<ResourceMethodDescriptor> resourceMethods = resource.getResourceMethods().get("GET"); assertEquals(1, resourceMethods.get(0).getAnnotations().length); RolesAllowed rolesAllowed = (RolesAllowed)resourceMethods.get(0).getAnnotations()[0]; assertNotNull(rolesAllowed); }
@Test public void ignoresSecurityAnnotationFromClassWhenMethodHasOwn() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceWithSecurityAnnotationOnClassAndMethod.class); List<ResourceMethodDescriptor> resourceMethods = resource.getResourceMethods().get("GET"); assertEquals(1, resourceMethods.get(0).getAnnotations().length); PermitAll permitAll = (PermitAll)resourceMethods.get(0).getAnnotations()[0]; assertNotNull(permitAll); }
@Test public void inheritsSecurityAnnotationFromMethodOnParentInterface() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceWithSecurityAnnotationOnMethodInParentInterface.class); List<ResourceMethodDescriptor> resourceMethods = resource.getResourceMethods().get("GET"); assertEquals(1, resourceMethods.get(0).getAnnotations().length); RolesAllowed rolesAllowed = (RolesAllowed)resourceMethods.get(0).getAnnotations()[0]; assertNotNull(rolesAllowed); }
@Test public void inheritsSecurityAnnotationFromParentInterface() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceWithSecurityAnnotationOnParentInterface.class); List<ResourceMethodDescriptor> resourceMethods = resource.getResourceMethods().get("GET"); assertEquals(1, resourceMethods.get(0).getAnnotations().length); RolesAllowed rolesAllowed = (RolesAllowed)resourceMethods.get(0).getAnnotations()[0]; assertNotNull(rolesAllowed); }
@Test public void inheritsSecurityAnnotationFromMethodOnParentClass() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceWithSecurityAnnotationOnMethodInParentClass.class); List<ResourceMethodDescriptor> resourceMethods = resource.getResourceMethods().get("GET"); assertEquals(1, resourceMethods.get(0).getAnnotations().length); RolesAllowed rolesAllowed = (RolesAllowed)resourceMethods.get(0).getAnnotations()[0]; assertNotNull(rolesAllowed); }
@Test public void inheritsSecurityAnnotationFromParentClass() { ResourceDescriptor resource = new AbstractResourceDescriptor(ResourceWithSecurityAnnotationOnParentClass.class); List<ResourceMethodDescriptor> resourceMethods = resource.getResourceMethods().get("GET"); assertEquals(1, resourceMethods.get(0).getAnnotations().length); RolesAllowed rolesAllowed = (RolesAllowed)resourceMethods.get(0).getAnnotations()[0]; assertNotNull(rolesAllowed); }
@Test public void processesResourceWithOverriddenMethods() throws Exception { ResourceDescriptor resource = new AbstractResourceDescriptor(Resource2.class); assertEquals(1, resource.getResourceMethods().get("GET").size()); assertEquals(1, resource.getResourceMethods().get("POST").size()); }