@Test(expected = ValidationException.class) public void testInvalidEmpty() { Stream stream = new Stream(); stream.setName(""); PrincipalActionContext actionContext = new ServiceActionContext(stream, null); sut.validate(actionContext); }
@Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException valEx = new ValidationException(); Stream stream = (Stream) inActionContext.getParams(); JSONObject object = null; try { object = JSONObject.fromObject(stream.getRequest()); } catch (JSONException ex) { valEx.addError("stream", "Malformed JSON. Try again later."); throw valEx; } if (stream.getName() == null || stream.getName().length() == 0) { valEx.addError("name", "Stream must have a name."); throw valEx; } JSONObject query = object.getJSONObject("query"); for (Object key : query.keySet()) { String keyStr = (String) key; try { JSONArray arr = query.getJSONArray(keyStr); if (arr.size() == 0) { valEx.addError("stream", "Add at least one stream"); throw valEx; } else if (arr.size() > MAX_STREAMS) { valEx.addError("stream", "Maximum number of streams allowed is " + MAX_STREAMS); throw valEx; } } catch (JSONException ex) { log.trace("Item is not an array. Ignored"); } } }
ModifyStreamForCurrentUserValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException valEx = new ValidationException(); Stream stream = (Stream) inActionContext.getParams(); JSONObject object = null; try { object = JSONObject.fromObject(stream.getRequest()); } catch (JSONException ex) { valEx.addError("stream", "Malformed JSON. Try again later."); throw valEx; } if (stream.getName() == null || stream.getName().length() == 0) { valEx.addError("name", "Stream must have a name."); throw valEx; } JSONObject query = object.getJSONObject("query"); for (Object key : query.keySet()) { String keyStr = (String) key; try { JSONArray arr = query.getJSONArray(keyStr); if (arr.size() == 0) { valEx.addError("stream", "Add at least one stream"); throw valEx; } else if (arr.size() > MAX_STREAMS) { valEx.addError("stream", "Maximum number of streams allowed is " + MAX_STREAMS); throw valEx; } } catch (JSONException ex) { log.trace("Item is not an array. Ignored"); } } } }
ModifyStreamForCurrentUserValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException valEx = new ValidationException(); Stream stream = (Stream) inActionContext.getParams(); JSONObject object = null; try { object = JSONObject.fromObject(stream.getRequest()); } catch (JSONException ex) { valEx.addError("stream", "Malformed JSON. Try again later."); throw valEx; } if (stream.getName() == null || stream.getName().length() == 0) { valEx.addError("name", "Stream must have a name."); throw valEx; } JSONObject query = object.getJSONObject("query"); for (Object key : query.keySet()) { String keyStr = (String) key; try { JSONArray arr = query.getJSONArray(keyStr); if (arr.size() == 0) { valEx.addError("stream", "Add at least one stream"); throw valEx; } else if (arr.size() > MAX_STREAMS) { valEx.addError("stream", "Maximum number of streams allowed is " + MAX_STREAMS); throw valEx; } } catch (JSONException ex) { log.trace("Item is not an array. Ignored"); } } }  }
ModifyStreamForCurrentUserValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException valEx = new ValidationException(); Stream stream = (Stream) inActionContext.getParams(); JSONObject object = null; try { object = JSONObject.fromObject(stream.getRequest()); } catch (JSONException ex) { valEx.addError("stream", "Malformed JSON. Try again later."); throw valEx; } if (stream.getName() == null || stream.getName().length() == 0) { valEx.addError("name", "Stream must have a name."); throw valEx; } JSONObject query = object.getJSONObject("query"); for (Object key : query.keySet()) { String keyStr = (String) key; try { JSONArray arr = query.getJSONArray(keyStr); if (arr.size() == 0) { valEx.addError("stream", "Add at least one stream"); throw valEx; } else if (arr.size() > MAX_STREAMS) { valEx.addError("stream", "Maximum number of streams allowed is " + MAX_STREAMS); throw valEx; } } catch (JSONException ex) { log.trace("Item is not an array. Ignored"); } } }  @Override void validate(final PrincipalActionContext inActionContext); }
ModifyStreamForCurrentUserValidation implements ValidationStrategy<PrincipalActionContext> { @Override public void validate(final PrincipalActionContext inActionContext) throws ValidationException { ValidationException valEx = new ValidationException(); Stream stream = (Stream) inActionContext.getParams(); JSONObject object = null; try { object = JSONObject.fromObject(stream.getRequest()); } catch (JSONException ex) { valEx.addError("stream", "Malformed JSON. Try again later."); throw valEx; } if (stream.getName() == null || stream.getName().length() == 0) { valEx.addError("name", "Stream must have a name."); throw valEx; } JSONObject query = object.getJSONObject("query"); for (Object key : query.keySet()) { String keyStr = (String) key; try { JSONArray arr = query.getJSONArray(keyStr); if (arr.size() == 0) { valEx.addError("stream", "Add at least one stream"); throw valEx; } else if (arr.size() > MAX_STREAMS) { valEx.addError("stream", "Maximum number of streams allowed is " + MAX_STREAMS); throw valEx; } } catch (JSONException ex) { log.trace("Item is not an array. Ignored"); } } }  @Override void validate(final PrincipalActionContext inActionContext);  }