MapLayerGroupsHandler extends RestActionHandler { public void handlePut(ActionParameters params) throws ActionException { params.requireAdminUser(); MaplayerGroup maplayerGroup = populateFromRequest(params.getPayLoadJSON()); if (!isAllowedGroupDepth(maplayerGroup)) { throw new ActionParamsException("Maximum group depth is 3"); } final int id = oskariMapLayerGroupService.insert(maplayerGroup); final MaplayerGroup savedMapLayerGroup = oskariMapLayerGroupService.find(id); AuditLog.user(params.getClientIp(), params.getUser()).withParam("id", id) .withParam("name", maplayerGroup.getName(PropertyUtil.getDefaultLanguage())) .added(AuditLog.ResourceType.MAPLAYER_GROUP); ResponseHelper.writeResponse(params, savedMapLayerGroup.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 testHandlePutGuest() throws Exception { ActionParameters params = createActionParams(createDummyLocale()); handler.handlePut(params); fail("Should have thrown denied exception"); }
@Test public void testHandlePutAdmin() throws Exception { ActionParameters params = createActionParams(createDummyLocale(), getAdminUser()); handler.handlePut(params); verifyResponseContent(ResourceHelper.readJSONResource("MapLayerGroupsHandlerTest-insert-expected.json", this)); }