@Test public void testRepresent() throws ResourceException, IOException { final Variant variant = context.mock(Variant.class); setupCommonInitExpectations(); setupCommonRepresentExpectations(); context.checking(new Expectations() { { oneOf(fr).getId(); will(returnValue(0L)); oneOf(fr).getFeedTitle(); will(returnValue(testFeedTitle)); oneOf(fr).getUrl(); will(returnValue(testUrl)); oneOf(fr).getOpenSocialId(); will(returnValue(testOSId)); oneOf(fr).getModuleId(); will(returnValue(testModuleId)); oneOf(fr).getDateAdded(); } }); sut.init(restContext, request, response); Representation actual = sut.represent(variant); assertEquals("MediaType should be application/json", MediaType.APPLICATION_JSON, actual.getMediaType()); JSONObject json = JSONObject.fromObject(actual.getText()); assertNotNull("JSON text isn't right", json); context.assertIsSatisfied(); }
@Override public Representation represent(final Variant variant) throws ResourceException { try { FeedReader feedReader = entityMapper.findFeedByOpenSocialIdAndModuleId(userId, moduleId); String stringRep; JSONObject json = new JSONObject(); json = convertFeedToJSON(feedReader); stringRep = json.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving feed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error when retrieving feed"); } }
FeedReaderEntityResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { FeedReader feedReader = entityMapper.findFeedByOpenSocialIdAndModuleId(userId, moduleId); String stringRep; JSONObject json = new JSONObject(); json = convertFeedToJSON(feedReader); stringRep = json.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving feed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error when retrieving feed"); } } }
FeedReaderEntityResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { FeedReader feedReader = entityMapper.findFeedByOpenSocialIdAndModuleId(userId, moduleId); String stringRep; JSONObject json = new JSONObject(); json = convertFeedToJSON(feedReader); stringRep = json.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving feed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error when retrieving feed"); } } protected  FeedReaderEntityResource(); }
FeedReaderEntityResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { FeedReader feedReader = entityMapper.findFeedByOpenSocialIdAndModuleId(userId, moduleId); String stringRep; JSONObject json = new JSONObject(); json = convertFeedToJSON(feedReader); stringRep = json.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving feed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error when retrieving feed"); } } protected  FeedReaderEntityResource(); @Override void removeRepresentations(); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); @Override void acceptRepresentation(final Representation entity); }
FeedReaderEntityResource extends FeedReaderResource { @Override public Representation represent(final Variant variant) throws ResourceException { try { FeedReader feedReader = entityMapper.findFeedByOpenSocialIdAndModuleId(userId, moduleId); String stringRep; JSONObject json = new JSONObject(); json = convertFeedToJSON(feedReader); stringRep = json.toString(); Representation rep = new StringRepresentation(stringRep, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } catch (Exception e) { logger.error("Error when retrieving feed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error when retrieving feed"); } } protected  FeedReaderEntityResource(); @Override void removeRepresentations(); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); @Override void acceptRepresentation(final Representation entity);  }