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