GetLayerCapabilitiesHandler extends ActionHandler { @Override public void handleAction(final ActionParameters params) throws ActionException { final int layerId = params.getRequiredParamInt(ActionConstants.KEY_ID); final OskariLayer layer = permissionHelper.getLayer(layerId, params.getUser()); final String data = getCapabilities(layer); ResponseHelper.writeResponse(params, HttpServletResponse.SC_OK, "text/xml", data.getBytes(StandardCharsets.UTF_8)); }  void init(); void setCapabilitiesCacheService(CapabilitiesCacheService capabilitiesService); void setPermissionHelper(final PermissionHelper helper); @Override void handleAction(final ActionParameters params);  }
@Test(expected = ActionDeniedException.class) public void testHandleActionGuest() throws Exception { Map<String, String> httpParams = new HashMap<>(); httpParams.put(ActionConstants.KEY_ID, "1"); ActionParameters params = createActionParams(httpParams); handler.handleAction(params); fail("Should have thrown exception"); }
@Test public void testHandleActionUser() throws Exception { Map<String, String> httpParams = new HashMap<>(); httpParams.put(ActionConstants.KEY_ID, "1"); ActionParameters params = createActionParams(httpParams, getLoggedInUser()); handler.handleAction(params); verifyResponseContent(TEST_DATA); }
@Test(expected = ActionException.class) public void testHandleServiceException() throws Exception { Map<String, String> httpParams = new HashMap<>(); httpParams.put(ActionConstants.KEY_ID, "2"); ActionParameters params = createActionParams(httpParams, getLoggedInUser()); handler.handleAction(params); fail("Should have thrown exception"); }