@Test public void testRepresent() throws ResourceException, IOException { final Variant variant = context.mock(Variant.class); context.checking(new Expectations() { { oneOf(mapper).findOrCreatePersonBackground(with(uuid)); will(returnValue(background)); } }); Representation actual = sut.represent(variant); assertEquals("MediaType should be application/json", MediaType.APPLICATION_JSON, actual.getMediaType()); JSONObject json = JSONObject.fromObject(actual.getText()); JSONArray affiliationsArray = json.getJSONArray(PersonBackgroundResource.AFFILIATIONS_KEY); JSONArray honorsawardsArray = json.getJSONArray(PersonBackgroundResource.HONORSAWARDS_KEY); JSONArray interestshobbiesArray = json.getJSONArray(PersonBackgroundResource.INTERESTSHOBBIES_KEY); JSONArray skillsspecialtiesArray = json.getJSONArray(PersonBackgroundResource.SKILLSSPECIALTIES_KEY); assertNotNull("Affiliations array is null and should not be", affiliationsArray); assertNotNull("Honors Awards array is null and should not be", honorsawardsArray); assertNotNull("Interests Hobbies array is null and should not be", interestshobbiesArray); assertNotNull("Skills Specialties array is null and should not be", skillsspecialtiesArray); assertEquals("Affiliations array should contain 3 items and does not", 3, affiliationsArray.size()); assertEquals("Honors Awards array should contain 3 items and does not", 3, honorsawardsArray.size()); assertEquals("Interests Hobbies array should contain 3 items and does not", 3, interestshobbiesArray.size()); assertEquals("Skills Specialties array should contain 3 items and does not", 3, skillsspecialtiesArray.size()); context.assertIsSatisfied(); }
@Override public Representation represent(final Variant variant) throws ResourceException { Background bg = mapper.findOrCreatePersonBackground(uuid); JSONObject bgAsJson = convertBackgroundToJSON(bg); String json = bgAsJson.toString(); log.debug("PersonBackgroundResource accepted json for uuid: " + uuid); log.debug("PersonBackgroundResource constructed json: " + json); Representation rep = new StringRepresentation(json, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }
PersonBackgroundResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { Background bg = mapper.findOrCreatePersonBackground(uuid); JSONObject bgAsJson = convertBackgroundToJSON(bg); String json = bgAsJson.toString(); log.debug("PersonBackgroundResource accepted json for uuid: " + uuid); log.debug("PersonBackgroundResource constructed json: " + json); Representation rep = new StringRepresentation(json, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } }
PersonBackgroundResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { Background bg = mapper.findOrCreatePersonBackground(uuid); JSONObject bgAsJson = convertBackgroundToJSON(bg); String json = bgAsJson.toString(); log.debug("PersonBackgroundResource accepted json for uuid: " + uuid); log.debug("PersonBackgroundResource constructed json: " + json); Representation rep = new StringRepresentation(json, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }  }
PersonBackgroundResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { Background bg = mapper.findOrCreatePersonBackground(uuid); JSONObject bgAsJson = convertBackgroundToJSON(bg); String json = bgAsJson.toString(); log.debug("PersonBackgroundResource accepted json for uuid: " + uuid); log.debug("PersonBackgroundResource constructed json: " + json); Representation rep = new StringRepresentation(json, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }  void setMapper(final BackgroundMapper inMapper); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); JSONObject convertBackgroundToJSON(final Background bg); }
PersonBackgroundResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { Background bg = mapper.findOrCreatePersonBackground(uuid); JSONObject bgAsJson = convertBackgroundToJSON(bg); String json = bgAsJson.toString(); log.debug("PersonBackgroundResource accepted json for uuid: " + uuid); log.debug("PersonBackgroundResource constructed json: " + json); Representation rep = new StringRepresentation(json, MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }  void setMapper(final BackgroundMapper inMapper); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); JSONObject convertBackgroundToJSON(final Background bg); static final String MAIN_KEY; static final String UUID_KEY; static final String AFFILIATIONS_KEY; static final String HONORSAWARDS_KEY; static final String INTERESTSHOBBIES_KEY; static final String SKILLSSPECIALTIES_KEY; }