@Test public void representation() throws ResourceException, IOException { Variant variant = context.mock(Variant.class); final Recommendation recommendation = new Recommendation(SUBJECT_OPENSOCIAL_ID, AUTHOR_OPENSOCIAL_ID, RECO_TEXT); recommendation.setDate(RECO_DATE); final Recommendation recoMock = context.mock(Recommendation.class); final List<String> openSocialIds = new ArrayList<String>(); openSocialIds.add(AUTHOR_OPENSOCIAL_ID); openSocialIds.add(SUBJECT_OPENSOCIAL_ID); context.checking(new Expectations() { { oneOf(recoMapper).findById(RECOMMENDATION_ID); will(returnValue(recommendation)); allowing(recoMock).getId(); will(returnValue(RECOMMENDATION_ID)); allowing(recoMock).getAuthorOpenSocialId(); will(returnValue(AUTHOR_OPENSOCIAL_ID)); allowing(recoMock).getSubjectOpenSocialId(); will(returnValue(SUBJECT_OPENSOCIAL_ID)); allowing(recoMock).getDate(); will(returnValue(RECO_DATE)); allowing(recoMock).getText(); will(returnValue(RECO_TEXT)); oneOf(personMapper).findPeopleByOpenSocialIds(openSocialIds); will(returnValue(people)); } }); Representation actual = sut.represent(variant); JSONObject jsonActual = JSONObject.fromObject(actual.getText()); assertEquals("0", jsonActual.getString(RecommendationsResource.ID_KEY)); assertEquals(AUTHOR_OPENSOCIAL_ID, jsonActual.getJSONObject(RecommendationsResource.AUTHOR_KEY) .getString(RecommendationsResource.ID_KEY)); assertEquals(SUBJECT_OPENSOCIAL_ID, jsonActual.getJSONObject(RecommendationsResource.SUBJECT_KEY) .getString(RecommendationsResource.ID_KEY)); assertEquals(formattedJSONDate, jsonActual.getString(RecommendationsResource.DATE_KEY)); assertEquals(RECO_TEXT, jsonActual.getString(RecommendationsResource.TEXT_KEY)); context.assertIsSatisfied(); }
@Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Attempting to GET recommendation by Id: " + recommendationId); Recommendation reco = getRecommendationMapper().findById(recommendationId); if (null == reco) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } Map<String, Person> people = getPeopleInfoForRecommendations(reco); JSONObject jsonReco = convertRecoToJSON(reco, people.get(reco.getAuthorOpenSocialId()), people.get(reco.getSubjectOpenSocialId())); Representation rep = new StringRepresentation(jsonReco.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }
RecommendationsEntryResource extends RecommendationsResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Attempting to GET recommendation by Id: " + recommendationId); Recommendation reco = getRecommendationMapper().findById(recommendationId); if (null == reco) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } Map<String, Person> people = getPeopleInfoForRecommendations(reco); JSONObject jsonReco = convertRecoToJSON(reco, people.get(reco.getAuthorOpenSocialId()), people.get(reco.getSubjectOpenSocialId())); Representation rep = new StringRepresentation(jsonReco.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } }
RecommendationsEntryResource extends RecommendationsResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Attempting to GET recommendation by Id: " + recommendationId); Recommendation reco = getRecommendationMapper().findById(recommendationId); if (null == reco) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } Map<String, Person> people = getPeopleInfoForRecommendations(reco); JSONObject jsonReco = convertRecoToJSON(reco, people.get(reco.getAuthorOpenSocialId()), people.get(reco.getSubjectOpenSocialId())); Representation rep = new StringRepresentation(jsonReco.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }  }
RecommendationsEntryResource extends RecommendationsResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Attempting to GET recommendation by Id: " + recommendationId); Recommendation reco = getRecommendationMapper().findById(recommendationId); if (null == reco) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } Map<String, Person> people = getPeopleInfoForRecommendations(reco); JSONObject jsonReco = convertRecoToJSON(reco, people.get(reco.getAuthorOpenSocialId()), people.get(reco.getSubjectOpenSocialId())); Representation rep = new StringRepresentation(jsonReco.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }  @Override void removeRepresentations(); @Override Representation represent(final Variant variant); }
RecommendationsEntryResource extends RecommendationsResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Attempting to GET recommendation by Id: " + recommendationId); Recommendation reco = getRecommendationMapper().findById(recommendationId); if (null == reco) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } Map<String, Person> people = getPeopleInfoForRecommendations(reco); JSONObject jsonReco = convertRecoToJSON(reco, people.get(reco.getAuthorOpenSocialId()), people.get(reco.getSubjectOpenSocialId())); Representation rep = new StringRepresentation(jsonReco.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }  @Override void removeRepresentations(); @Override Representation represent(final Variant variant);  }