### Question:
EntityResource extends ServerResource { @Get("json") public Representation getEntity() { CollabinateReader reader = (CollabinateReader)getContext() .getAttributes().get("collabinateReader"); String tenantId = getAttribute("tenantId"); String entityId = getAttribute("entityId"); String result = reader.getEntity(tenantId, entityId).toString(); Representation representation = new StringRepresentation( result, MediaType.APPLICATION_JSON); representation.setTag(new Tag(Hashing.murmur3_128().hashUnencodedChars( result+tenantId+entityId) .toString(), false)); return representation; }  @Get("json") Representation getEntity(); @Delete void deleteEntity();  }### Answer:
@Test public void get_should_return_json_content_type() { assertEquals(MediaType.APPLICATION_JSON, get().getEntity().getMediaType()); }
@Test public void get_response_should_contain_etag_header() { assertTrue(null != get().getEntity().getTag()); }
@Test public void etag_should_change_when_entity_changes() { Tag tag1 = get().getEntity().getTag(); Request request = new Request(Method.POST, "riap: component.handle(request); Tag tag2 = get().getEntity().getTag(); assertNotEquals(tag1, tag2); }
@Test public void matching_etag_should_return_304_for_get() { Tag etag = get().getEntity().getTag(); Request request = getRequest(Method.GET, null); Conditions conditions = new Conditions(); conditions.getNoneMatch().add(etag); request.setConditions(conditions); assertEquals(Status.REDIRECTION_NOT_MODIFIED, getResponse(request).getStatus()); }
@Test public void matching_etag_should_return_204_for_delete() { Tag etag = get().getEntity().getTag(); Request request = getRequest(Method.DELETE, null); Conditions conditions = new Conditions(); conditions.getMatch().add(etag); request.setConditions(conditions); assertEquals(Status.SUCCESS_NO_CONTENT, getResponse(request).getStatus()); }