@Test public void testGetJson() throws ResourceException, IOException { context.checking(new Expectations() { { oneOf(serviceActionController).execute(with(any(ServiceActionContext.class)), with(equal(getPersonAdditionalPropertiesAction))); will(returnValue(personObjects)); } }); Representation response = sut.represent(null); assertEquals(MediaType.APPLICATION_JSON, response.getMediaType()); JSONObject responseJs = JSONObject.fromObject(response.getText()); assertTrue(responseJs.containsKey("personProperties")); assertEquals(2, responseJs.getJSONArray("personProperties").size()); assertEquals("testaccountid1", responseJs.getJSONArray("personProperties").getJSONObject(0).getString( "accountId")); assertEquals("value1", responseJs.getJSONArray("personProperties").getJSONObject(0).getString("property1")); assertEquals(4, responseJs.getJSONArray("personProperties").getJSONObject(0).keySet().size()); }
@Override public Representation represent(final Variant variant) throws ResourceException { String jsString = new String(); JSONObject responseJson = new JSONObject(); List<Map<String, Object>> people; try { people = (ArrayList<Map<String, Object>>) serviceActionController.execute(new ServiceActionContext(null, null), getAllPersonAdditionalPropertiesAction); } catch (Exception ex) { logger.error("Error occurred retrieving the users from the db.", ex); throw new ResourceException(Status.SERVER_ERROR_INTERNAL); } JSONArray personProperties = new JSONArray(); JSONObject personJs; for (Map<String, Object> currentPersonProperties : people) { personJs = new JSONObject(); personJs.put("accountId", (String) currentPersonProperties.get("accountId")); if (currentPersonProperties.get("additionalProperties") != null) { for (Entry<String, String> currentAddlProperty : ((Map<String, String>) currentPersonProperties .get("additionalProperties")).entrySet()) { personJs.put(currentAddlProperty.getKey(), currentAddlProperty.getValue()); } } personProperties.add(personJs); } responseJson.put("personProperties", personProperties); Representation rep = new StringRepresentation(responseJson.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; }
PersonPropertiesResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { String jsString = new String(); JSONObject responseJson = new JSONObject(); List<Map<String, Object>> people; try { people = (ArrayList<Map<String, Object>>) serviceActionController.execute(new ServiceActionContext(null, null), getAllPersonAdditionalPropertiesAction); } catch (Exception ex) { logger.error("Error occurred retrieving the users from the db.", ex); throw new ResourceException(Status.SERVER_ERROR_INTERNAL); } JSONArray personProperties = new JSONArray(); JSONObject personJs; for (Map<String, Object> currentPersonProperties : people) { personJs = new JSONObject(); personJs.put("accountId", (String) currentPersonProperties.get("accountId")); if (currentPersonProperties.get("additionalProperties") != null) { for (Entry<String, String> currentAddlProperty : ((Map<String, String>) currentPersonProperties .get("additionalProperties")).entrySet()) { personJs.put(currentAddlProperty.getKey(), currentAddlProperty.getValue()); } } personProperties.add(personJs); } responseJson.put("personProperties", personProperties); Representation rep = new StringRepresentation(responseJson.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } }
PersonPropertiesResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { String jsString = new String(); JSONObject responseJson = new JSONObject(); List<Map<String, Object>> people; try { people = (ArrayList<Map<String, Object>>) serviceActionController.execute(new ServiceActionContext(null, null), getAllPersonAdditionalPropertiesAction); } catch (Exception ex) { logger.error("Error occurred retrieving the users from the db.", ex); throw new ResourceException(Status.SERVER_ERROR_INTERNAL); } JSONArray personProperties = new JSONArray(); JSONObject personJs; for (Map<String, Object> currentPersonProperties : people) { personJs = new JSONObject(); personJs.put("accountId", (String) currentPersonProperties.get("accountId")); if (currentPersonProperties.get("additionalProperties") != null) { for (Entry<String, String> currentAddlProperty : ((Map<String, String>) currentPersonProperties .get("additionalProperties")).entrySet()) { personJs.put(currentAddlProperty.getKey(), currentAddlProperty.getValue()); } } personProperties.add(personJs); } responseJson.put("personProperties", personProperties); Representation rep = new StringRepresentation(responseJson.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } PersonPropertiesResource(final ActionController inServiceActionController,
            final ServiceAction inGetAllPersonAdditionalPropertiesAction); }
PersonPropertiesResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { String jsString = new String(); JSONObject responseJson = new JSONObject(); List<Map<String, Object>> people; try { people = (ArrayList<Map<String, Object>>) serviceActionController.execute(new ServiceActionContext(null, null), getAllPersonAdditionalPropertiesAction); } catch (Exception ex) { logger.error("Error occurred retrieving the users from the db.", ex); throw new ResourceException(Status.SERVER_ERROR_INTERNAL); } JSONArray personProperties = new JSONArray(); JSONObject personJs; for (Map<String, Object> currentPersonProperties : people) { personJs = new JSONObject(); personJs.put("accountId", (String) currentPersonProperties.get("accountId")); if (currentPersonProperties.get("additionalProperties") != null) { for (Entry<String, String> currentAddlProperty : ((Map<String, String>) currentPersonProperties .get("additionalProperties")).entrySet()) { personJs.put(currentAddlProperty.getKey(), currentAddlProperty.getValue()); } } personProperties.add(personJs); } responseJson.put("personProperties", personProperties); Representation rep = new StringRepresentation(responseJson.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } PersonPropertiesResource(final ActionController inServiceActionController,
            final ServiceAction inGetAllPersonAdditionalPropertiesAction); @Override Representation represent(final Variant variant); }
PersonPropertiesResource extends SmpResource { @Override public Representation represent(final Variant variant) throws ResourceException { String jsString = new String(); JSONObject responseJson = new JSONObject(); List<Map<String, Object>> people; try { people = (ArrayList<Map<String, Object>>) serviceActionController.execute(new ServiceActionContext(null, null), getAllPersonAdditionalPropertiesAction); } catch (Exception ex) { logger.error("Error occurred retrieving the users from the db.", ex); throw new ResourceException(Status.SERVER_ERROR_INTERNAL); } JSONArray personProperties = new JSONArray(); JSONObject personJs; for (Map<String, Object> currentPersonProperties : people) { personJs = new JSONObject(); personJs.put("accountId", (String) currentPersonProperties.get("accountId")); if (currentPersonProperties.get("additionalProperties") != null) { for (Entry<String, String> currentAddlProperty : ((Map<String, String>) currentPersonProperties .get("additionalProperties")).entrySet()) { personJs.put(currentAddlProperty.getKey(), currentAddlProperty.getValue()); } } personProperties.add(personJs); } responseJson.put("personProperties", personProperties); Representation rep = new StringRepresentation(responseJson.toString(), MediaType.APPLICATION_JSON); rep.setExpirationDate(new Date(0L)); return rep; } PersonPropertiesResource(final ActionController inServiceActionController,
            final ServiceAction inGetAllPersonAdditionalPropertiesAction); @Override Representation represent(final Variant variant);  }