@Test public void storeRepresentationWithBadData() throws IOException, ResourceException { final Representation rep = context.mock(Representation.class); final CompositeEntity cmpEntity = context.mock(CompositeEntity.class); context.checking(new Expectations() { { oneOf(entityMapper).findByShortName(with(any(String.class))); will(returnValue(cmpEntity)); 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 { CompositeEntity cmpEntity = entityMapper.findByShortName(entityShortName); try { String text = entity.getText(); log.debug("PUT entity overview for " + entityShortName + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String overview = jsonObject.getString(OVERVIEW_KEY); cmpEntity.setOverview(overview); entityMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + entityShortName, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Unable to store the update for overview for " + entityShortName, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing the provided Representation"); } }
CompositeEntityOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { CompositeEntity cmpEntity = entityMapper.findByShortName(entityShortName); try { String text = entity.getText(); log.debug("PUT entity overview for " + entityShortName + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String overview = jsonObject.getString(OVERVIEW_KEY); cmpEntity.setOverview(overview); entityMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + entityShortName, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Unable to store the update for overview for " + entityShortName, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing the provided Representation"); } } }
CompositeEntityOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { CompositeEntity cmpEntity = entityMapper.findByShortName(entityShortName); try { String text = entity.getText(); log.debug("PUT entity overview for " + entityShortName + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String overview = jsonObject.getString(OVERVIEW_KEY); cmpEntity.setOverview(overview); entityMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + entityShortName, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Unable to store the update for overview for " + entityShortName, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing the provided Representation"); } }  }
CompositeEntityOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { CompositeEntity cmpEntity = entityMapper.findByShortName(entityShortName); try { String text = entity.getText(); log.debug("PUT entity overview for " + entityShortName + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String overview = jsonObject.getString(OVERVIEW_KEY); cmpEntity.setOverview(overview); entityMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + entityShortName, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Unable to store the update for overview for " + entityShortName, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing the provided Representation"); } }  void setEntityMapper(final CompositeEntityMapper inEntityMapper); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); }
CompositeEntityOverviewResource extends WritableResource { @Override public void storeRepresentation(final Representation entity) throws ResourceException { CompositeEntity cmpEntity = entityMapper.findByShortName(entityShortName); try { String text = entity.getText(); log.debug("PUT entity overview for " + entityShortName + ": " + text); JSONObject jsonObject = JSONObject.fromObject(text); String overview = jsonObject.getString(OVERVIEW_KEY); cmpEntity.setOverview(overview); entityMapper.flush(); } catch (IOException e) { log.error("Unable to read update to overview for " + entityShortName, e); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error with the provided Representation"); } catch (Exception ex) { log.error("Unable to store the update for overview for " + entityShortName, ex); throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "Error storing the provided Representation"); } }  void setEntityMapper(final CompositeEntityMapper inEntityMapper); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); static final String OVERVIEW_KEY; static final String COORDINATORS_KEY; static final String ACCOUNTID_KEY; }