@Test public void represent() throws ResourceException, IOException { Variant variant = context.mock(Variant.class); String prefix = "abc"; setupExpectations(prefix, TitlesCollectionResource.MAX_TITLES); Representation actual = sut.represent(variant); JSONObject json = JSONObject.fromObject(actual.getText()); JSONArray titles = json.getJSONArray(TitlesCollectionResource.TITLES_KEY); assertEquals(TitlesCollectionResource.MAX_TITLES, titles.size()); for (int i = 0; i < titles.size(); i++) { assertEquals(prefix, titles.getString(i).substring(0, prefix.length())); } context.assertIsSatisfied(); }
@Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Searching for job titles by prefix: " + prefix); List<String> titles = jobMapper.findTitlesByPrefix(prefix, MAX_TITLES); JSONArray jsonArray = new JSONArray(); if (null != titles) { for (String title : titles) { jsonArray.add(title); } } JSONObject json = new JSONObject(); json.put(TITLES_KEY, jsonArray); log.debug("Returning titles found: " + json.toString()); Representation rep = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }
TitlesCollectionResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Searching for job titles by prefix: " + prefix); List<String> titles = jobMapper.findTitlesByPrefix(prefix, MAX_TITLES); JSONArray jsonArray = new JSONArray(); if (null != titles) { for (String title : titles) { jsonArray.add(title); } } JSONObject json = new JSONObject(); json.put(TITLES_KEY, jsonArray); log.debug("Returning titles found: " + json.toString()); Representation rep = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } }
TitlesCollectionResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Searching for job titles by prefix: " + prefix); List<String> titles = jobMapper.findTitlesByPrefix(prefix, MAX_TITLES); JSONArray jsonArray = new JSONArray(); if (null != titles) { for (String title : titles) { jsonArray.add(title); } } JSONObject json = new JSONObject(); json.put(TITLES_KEY, jsonArray); log.debug("Returning titles found: " + json.toString()); Representation rep = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } TitlesCollectionResource(); }
TitlesCollectionResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Searching for job titles by prefix: " + prefix); List<String> titles = jobMapper.findTitlesByPrefix(prefix, MAX_TITLES); JSONArray jsonArray = new JSONArray(); if (null != titles) { for (String title : titles) { jsonArray.add(title); } } JSONObject json = new JSONObject(); json.put(TITLES_KEY, jsonArray); log.debug("Returning titles found: " + json.toString()); Representation rep = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } TitlesCollectionResource(); JobMapper getJobMapper(); void setJobMapper(final JobMapper inJobMapper); @Override Representation represent(final Variant variant); }
TitlesCollectionResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { log.debug("Searching for job titles by prefix: " + prefix); List<String> titles = jobMapper.findTitlesByPrefix(prefix, MAX_TITLES); JSONArray jsonArray = new JSONArray(); if (null != titles) { for (String title : titles) { jsonArray.add(title); } } JSONObject json = new JSONObject(); json.put(TITLES_KEY, jsonArray); log.debug("Returning titles found: " + json.toString()); Representation rep = new StringRepresentation(json.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } TitlesCollectionResource(); JobMapper getJobMapper(); void setJobMapper(final JobMapper inJobMapper); @Override Representation represent(final Variant variant); static final String TITLES_KEY; static final int MAX_TITLES; }