MapLayerGroupsHandler extends RestActionHandler { public void handleGet(ActionParameters params) throws ActionException { final int id = params.getHttpParam(PARAM_ID, -1); if (id != -1) { final MaplayerGroup maplayerGroup = oskariMapLayerGroupService.find(id); ResponseHelper.writeResponse(params, maplayerGroup.getAsJSON()); return; } final List<MaplayerGroup> maplayerGroups = oskariMapLayerGroupService.findAll(); final JSONArray list = new JSONArray(); for (MaplayerGroup maplayerGroup : maplayerGroups) { list.put(maplayerGroup.getAsJSON()); } final JSONObject result = new JSONObject(); JSONHelper.putValue(result, "mapLayerGroups", list); ResponseHelper.writeResponse(params, result); }  void setOskariMapLayerGroupService(final OskariMapLayerGroupService service); void setLinkService(OskariLayerGroupLinkService linkService); void init(); void handleGet(ActionParameters params); void handlePut(ActionParameters params); void handlePost(ActionParameters params); void handleDelete(ActionParameters params);  }
@Test public void testHandleGetAll() throws Exception { ActionParameters params = createActionParams(); handler.handleGet(params); verifyResponseContent(ResourceHelper.readJSONResource("MapLayerGroupsHandlerTest-findall-expected.json", this)); }
@Test public void testHandleGetSingle() throws Exception { Map<String, String> map = buildParams().put(ActionConstants.PARAM_ID, 1).done(); ActionParameters params = createActionParams(map); handler.handleGet(params); verifyResponseContent(ResourceHelper.readJSONResource("MapLayerGroupsHandlerTest-find-expected.json", this)); }