@Test public void storeRepresentationWithBadData() throws IOException, ResourceException { final Representation rep = context.mock(Representation.class); context.checking(new Expectations() { { oneOf(personMapper).findByOpenSocialId(SAMPLE_UUID); will(returnValue(person)); oneOf(rep).getText(); will(throwException(new IOException())); } }); try { sut.storeRepresentation(rep); fail("Should have thrown ResourceException"); } catch (ResourceException resExc) { assertEquals(Status.CLIENT_ERROR_BAD_REQUEST, resExc.getStatus()); } }
@Override public void storeRepresentation(final Representation entity) throws ResourceException { Person person = personMapper.findByOpenSocialId(uuid); if (null == person) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } try { String text = entity.getText(); log.debug("PUT person overview for " + uuid + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String bio = jsonObject.getString(OVERVIEW_KEY); person.setOverview(bio); personMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + uuid, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Error storing overview for " + uuid, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing provided Representation"); } }
PersonOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { Person person = personMapper.findByOpenSocialId(uuid); if (null == person) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } try { String text = entity.getText(); log.debug("PUT person overview for " + uuid + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String bio = jsonObject.getString(OVERVIEW_KEY); person.setOverview(bio); personMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + uuid, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Error storing overview for " + uuid, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing provided Representation"); } } }
PersonOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { Person person = personMapper.findByOpenSocialId(uuid); if (null == person) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } try { String text = entity.getText(); log.debug("PUT person overview for " + uuid + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String bio = jsonObject.getString(OVERVIEW_KEY); person.setOverview(bio); personMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + uuid, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Error storing overview for " + uuid, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing provided Representation"); } }  }
PersonOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { Person person = personMapper.findByOpenSocialId(uuid); if (null == person) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } try { String text = entity.getText(); log.debug("PUT person overview for " + uuid + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String bio = jsonObject.getString(OVERVIEW_KEY); person.setOverview(bio); personMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + uuid, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Error storing overview for " + uuid, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing provided Representation"); } }  Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); void setPersonMapper(final PersonMapper inPersonMapper); }
PersonOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { Person person = personMapper.findByOpenSocialId(uuid); if (null == person) { throw new ResourceException(Status.CLIENT_ERROR_NOT_FOUND); } try { String text = entity.getText(); log.debug("PUT person overview for " + uuid + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String bio = jsonObject.getString(OVERVIEW_KEY); person.setOverview(bio); personMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + uuid, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Error storing overview for " + uuid, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing provided Representation"); } }  Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); void setPersonMapper(final PersonMapper inPersonMapper); static final String OVERVIEW_KEY; }