MapLayerGroupsHandler extends RestActionHandler { public void handlePost(ActionParameters params) throws ActionException { params.requireAdminUser(); MaplayerGroup maplayerGroup = populateFromRequest(params.getPayLoadJSON()); if (maplayerGroup.getId() == -1) { maplayerGroup.setId(params.getRequiredParamInt(PARAM_ID)); } maplayerGroup.setOrderNumber(getEnsuredOrderNumber(maplayerGroup)); oskariMapLayerGroupService.update(maplayerGroup); AuditLog.user(params.getClientIp(), params.getUser()).withParam("id", maplayerGroup.getId()) .withParam("name", maplayerGroup.getName(PropertyUtil.getDefaultLanguage())) .updated(AuditLog.ResourceType.MAPLAYER_GROUP); ResponseHelper.writeResponse(params, maplayerGroup.getAsJSON()); }  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(expected = ActionDeniedException.class) public void testHandlePostGuest() throws Exception { ActionParameters params = createActionParams(createDummyLocale()); handler.handlePost(params); fail("Should have thrown denied exception"); }
@Test(expected = ActionParamsException.class) public void testHandlePostNoId() throws Exception { ActionParameters params = createActionParams(createDummyLocale(), getAdminUser()); handler.handlePost(params); fail("Should have thrown params exception"); }
@Test public void testHandlePostAdmin() throws Exception { Map<String, String> map = buildParams().put(ActionConstants.PARAM_ID, 1). put(createDummyLocale()).done(); ActionParameters params = createActionParams(map, getAdminUser()); handler.handlePost(params); verifyResponseContent(ResourceHelper.readJSONResource("MapLayerGroupsHandlerTest-update-expected.json", this)); }