Resource { @GET @Path("/{resource}.{subtype}") public Response index(@PathParam("resource") final String resource, @PathParam("subtype") final String subtype) { return resource(subtype, resource, subtype); } @Inject  Resource(@Named("resource.expiryTimeInSeconds") final int expiryTimeInSeconds); @GET @Path("/{resource}.{subtype}") Response index(@PathParam("resource") final String resource, @PathParam("subtype") final String subtype); @GET @Path("/{type}/{resource}.{subtype}") Response resource(@PathParam("type") final String type, @PathParam("resource") final String resource,
                             @PathParam("subtype") final String subtype);  }
@Test public void textIndex() throws Exception { Resource resource = new Resource(5); Response response = resource.index("foo", "txt"); assertThat(response.getStatus(), is(OK.getStatusCode())); assertThat(new String((byte[]) response.getEntity()), is("ello ello")); assertThat(response.getMetadata().getFirst("Content-Type").toString(), is(TEXT_PLAIN)); }
@Test public void missingIndex() throws Exception { Resource resource = new Resource(5); Response response = resource.index("foo", "bar"); assertThat(response.getStatus(), is(INTERNAL_SERVER_ERROR.getStatusCode())); assertThat((String) response.getEntity(), startsWith("unable to load content, cause: ")); assertThat(response.getMetadata().getFirst("Content-Type").toString(), is(TEXT_PLAIN)); }
@Test public void cssIndex() throws Exception { Resource resource = new Resource(5); Response response = resource.index("jquery-ui", "css"); assertThat(response.getStatus(), is(OK.getStatusCode())); assertThat(response.getEntity(), notNullValue()); assertThat(response.getMetadata().getFirst("Content-Type").toString(), is("text/css")); }
@Test public void jsResource() throws Exception { Resource resource = new Resource(5); Response response = resource.index("jquery.min", "js"); assertThat(response.getStatus(), is(OK.getStatusCode())); assertThat(response.getEntity(), notNullValue()); assertThat(response.getMetadata().getFirst("Content-Type").toString(), is("application/javascript")); }