@Test public void represent() throws ResourceException, IOException { final Variant variant = context.mock(Variant.class); final CompositeEntity cmpEntity = context.mock(CompositeEntity.class); final String overview = "Entity overview"; final Set<Person> coordinators = new HashSet<Person>(); final Person person1 = context.mock(Person.class, "person1"); final Person person2 = context.mock(Person.class, "person2"); coordinators.add(person1); coordinators.add(person2); context.checking(new Expectations() { { oneOf(entityMapper).findByShortName(with(any(String.class))); will(returnValue(cmpEntity)); oneOf(cmpEntity).getOverview(); will(returnValue(overview)); oneOf(cmpEntity).getCoordinators(); will(returnValue(coordinators)); oneOf(person1).getOpenSocialId(); will(returnValue("person1")); oneOf(person2).getOpenSocialId(); will(returnValue("person2")); } }); Representation actual = sut.represent(variant); assertEquals("MediaType doesn't match", MediaType.APPLICATION_JSON, actual.getMediaType()); JSONObject json = JSONObject.fromObject(actual.getText()); assertEquals("JSON text isn't right", overview, json.get(CompositeEntityOverviewResource.OVERVIEW_KEY)); assertEquals("Got wrong number of coordinators", coordinators.size(), json .getJSONArray(CompositeEntityOverviewResource.COORDINATORS_KEY).size()); String accountId = json.getJSONArray(CompositeEntityOverviewResource.COORDINATORS_KEY).getString(0); assertTrue("Got a wrong coordinator", accountId.equals("person1") || accountId.equals("person2")); accountId = json.getJSONArray(CompositeEntityOverviewResource.COORDINATORS_KEY).getString(1); assertTrue("Got a wrong coordinator", accountId.equals("person1") || accountId.equals("person2")); context.assertIsSatisfied(); }
@Override public Representation represent(final Variant variant) throws ResourceException { CompositeEntity entity = entityMapper.findByShortName(entityShortName); Set<Person> coordinators = entity.getCoordinators(); JSONObject json = new JSONObject(); json.put(OVERVIEW_KEY, entity.getOverview()); JSONArray jsonCoordinators = new JSONArray(); for (Person person : coordinators) { jsonCoordinators.add(person.getOpenSocialId()); } json.put(COORDINATORS_KEY, jsonCoordinators); StringRepresentation response = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); response.setExpirationDate(new Date(0L)); log.debug("Sending response: " + response.getText()); return response; }
CompositeEntityOverviewResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { CompositeEntity entity = entityMapper.findByShortName(entityShortName); Set<Person> coordinators = entity.getCoordinators(); JSONObject json = new JSONObject(); json.put(OVERVIEW_KEY, entity.getOverview()); JSONArray jsonCoordinators = new JSONArray(); for (Person person : coordinators) { jsonCoordinators.add(person.getOpenSocialId()); } json.put(COORDINATORS_KEY, jsonCoordinators); StringRepresentation response = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); response.setExpirationDate(new Date(0L)); log.debug("Sending response: " + response.getText()); return response; } }
CompositeEntityOverviewResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { CompositeEntity entity = entityMapper.findByShortName(entityShortName); Set<Person> coordinators = entity.getCoordinators(); JSONObject json = new JSONObject(); json.put(OVERVIEW_KEY, entity.getOverview()); JSONArray jsonCoordinators = new JSONArray(); for (Person person : coordinators) { jsonCoordinators.add(person.getOpenSocialId()); } json.put(COORDINATORS_KEY, jsonCoordinators); StringRepresentation response = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); response.setExpirationDate(new Date(0L)); log.debug("Sending response: " + response.getText()); return response; }  }
CompositeEntityOverviewResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { CompositeEntity entity = entityMapper.findByShortName(entityShortName); Set<Person> coordinators = entity.getCoordinators(); JSONObject json = new JSONObject(); json.put(OVERVIEW_KEY, entity.getOverview()); JSONArray jsonCoordinators = new JSONArray(); for (Person person : coordinators) { jsonCoordinators.add(person.getOpenSocialId()); } json.put(COORDINATORS_KEY, jsonCoordinators); StringRepresentation response = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); response.setExpirationDate(new Date(0L)); log.debug("Sending response: " + response.getText()); return response; }  void setEntityMapper(final CompositeEntityMapper inEntityMapper); @Override Representation represent(final Variant variant); @Override void storeRepresentation(final Representation entity); }
CompositeEntityOverviewResource extends WritableResource { @Override public Representation represent(final Variant variant) throws ResourceException { CompositeEntity entity = entityMapper.findByShortName(entityShortName); Set<Person> coordinators = entity.getCoordinators(); JSONObject json = new JSONObject(); json.put(OVERVIEW_KEY, entity.getOverview()); JSONArray jsonCoordinators = new JSONArray(); for (Person person : coordinators) { jsonCoordinators.add(person.getOpenSocialId()); } json.put(COORDINATORS_KEY, jsonCoordinators); StringRepresentation response = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); response.setExpirationDate(new Date(0L)); log.debug("Sending response: " + response.getText()); return response; }  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; }