@Test public void acceptRepresentation() throws IOException, ResourceException { final Representation entity = context.mock(Representation.class); final String json = buildJSONRecommendation(); final List<String> openSocialIds = new ArrayList<String>(); openSocialIds.add(AUTHOR_OPENSOCIAL_ID); openSocialIds.add(SUBJECT_OPENSOCIAL_ID); context.checking(new Expectations() { { oneOf(entity).getText(); will(returnValue(json)); oneOf(recoMapper).insert(with(any(Recommendation.class))); allowing(personMapper).findPeopleByOpenSocialIds(openSocialIds); will(returnValue(people)); oneOf(responseAdapter).setEntity(buildJSONResponse(), MediaType.APPLICATION_JSON); } }); sut.acceptRepresentation(entity); context.assertIsSatisfied(); }
@Override public void acceptRepresentation(final Representation entity) throws ResourceException { String json; try { json = entity.getText(); log.debug("RecommendationsCollectionResource POST" + json); JSONObject jsonReco = JSONObject.fromObject(json); JSONObject jsonAuthor = jsonReco.getJSONObject(AUTHOR_KEY); JSONObject jsonSubject = jsonReco.getJSONObject(SUBJECT_KEY); Recommendation recommendation = new Recommendation(jsonSubject.getString(ID_KEY), jsonAuthor.getString(ID_KEY), jsonReco.getString(TEXT_KEY)); getRecommendationMapper().insert(recommendation); Map<String, Person> people = getPeopleInfoForRecommendations(recommendation); JSONObject recoJSON = convertRecoToJSON(recommendation, people.get(recommendation.getAuthorOpenSocialId()), people.get(recommendation.getSubjectOpenSocialId())); getAdaptedResponse().setEntity(recoJSON.toString(), MediaType.APPLICATION_JSON); } catch (IOException e) { log.error("POST to RecommendationsCollection failed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST); } log.debug("RecommendationsCollectionResource POST " + entity.toString()); }
RecommendationsCollectionResource extends RecommendationsResource { @Override public void acceptRepresentation(final Representation entity) throws ResourceException { String json; try { json = entity.getText(); log.debug("RecommendationsCollectionResource POST" + json); JSONObject jsonReco = JSONObject.fromObject(json); JSONObject jsonAuthor = jsonReco.getJSONObject(AUTHOR_KEY); JSONObject jsonSubject = jsonReco.getJSONObject(SUBJECT_KEY); Recommendation recommendation = new Recommendation(jsonSubject.getString(ID_KEY), jsonAuthor.getString(ID_KEY), jsonReco.getString(TEXT_KEY)); getRecommendationMapper().insert(recommendation); Map<String, Person> people = getPeopleInfoForRecommendations(recommendation); JSONObject recoJSON = convertRecoToJSON(recommendation, people.get(recommendation.getAuthorOpenSocialId()), people.get(recommendation.getSubjectOpenSocialId())); getAdaptedResponse().setEntity(recoJSON.toString(), MediaType.APPLICATION_JSON); } catch (IOException e) { log.error("POST to RecommendationsCollection failed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST); } log.debug("RecommendationsCollectionResource POST " + entity.toString()); } }
RecommendationsCollectionResource extends RecommendationsResource { @Override public void acceptRepresentation(final Representation entity) throws ResourceException { String json; try { json = entity.getText(); log.debug("RecommendationsCollectionResource POST" + json); JSONObject jsonReco = JSONObject.fromObject(json); JSONObject jsonAuthor = jsonReco.getJSONObject(AUTHOR_KEY); JSONObject jsonSubject = jsonReco.getJSONObject(SUBJECT_KEY); Recommendation recommendation = new Recommendation(jsonSubject.getString(ID_KEY), jsonAuthor.getString(ID_KEY), jsonReco.getString(TEXT_KEY)); getRecommendationMapper().insert(recommendation); Map<String, Person> people = getPeopleInfoForRecommendations(recommendation); JSONObject recoJSON = convertRecoToJSON(recommendation, people.get(recommendation.getAuthorOpenSocialId()), people.get(recommendation.getSubjectOpenSocialId())); getAdaptedResponse().setEntity(recoJSON.toString(), MediaType.APPLICATION_JSON); } catch (IOException e) { log.error("POST to RecommendationsCollection failed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST); } log.debug("RecommendationsCollectionResource POST " + entity.toString()); }  }
RecommendationsCollectionResource extends RecommendationsResource { @Override public void acceptRepresentation(final Representation entity) throws ResourceException { String json; try { json = entity.getText(); log.debug("RecommendationsCollectionResource POST" + json); JSONObject jsonReco = JSONObject.fromObject(json); JSONObject jsonAuthor = jsonReco.getJSONObject(AUTHOR_KEY); JSONObject jsonSubject = jsonReco.getJSONObject(SUBJECT_KEY); Recommendation recommendation = new Recommendation(jsonSubject.getString(ID_KEY), jsonAuthor.getString(ID_KEY), jsonReco.getString(TEXT_KEY)); getRecommendationMapper().insert(recommendation); Map<String, Person> people = getPeopleInfoForRecommendations(recommendation); JSONObject recoJSON = convertRecoToJSON(recommendation, people.get(recommendation.getAuthorOpenSocialId()), people.get(recommendation.getSubjectOpenSocialId())); getAdaptedResponse().setEntity(recoJSON.toString(), MediaType.APPLICATION_JSON); } catch (IOException e) { log.error("POST to RecommendationsCollection failed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST); } log.debug("RecommendationsCollectionResource POST " + entity.toString()); }  @Override Representation represent(final Variant variant); @Override void acceptRepresentation(final Representation entity); }
RecommendationsCollectionResource extends RecommendationsResource { @Override public void acceptRepresentation(final Representation entity) throws ResourceException { String json; try { json = entity.getText(); log.debug("RecommendationsCollectionResource POST" + json); JSONObject jsonReco = JSONObject.fromObject(json); JSONObject jsonAuthor = jsonReco.getJSONObject(AUTHOR_KEY); JSONObject jsonSubject = jsonReco.getJSONObject(SUBJECT_KEY); Recommendation recommendation = new Recommendation(jsonSubject.getString(ID_KEY), jsonAuthor.getString(ID_KEY), jsonReco.getString(TEXT_KEY)); getRecommendationMapper().insert(recommendation); Map<String, Person> people = getPeopleInfoForRecommendations(recommendation); JSONObject recoJSON = convertRecoToJSON(recommendation, people.get(recommendation.getAuthorOpenSocialId()), people.get(recommendation.getSubjectOpenSocialId())); getAdaptedResponse().setEntity(recoJSON.toString(), MediaType.APPLICATION_JSON); } catch (IOException e) { log.error("POST to RecommendationsCollection failed", e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST); } log.debug("RecommendationsCollectionResource POST " + entity.toString()); }  @Override Representation represent(final Variant variant); @Override void acceptRepresentation(final Representation entity);  }