Package br.com.caelum.vraptor.validator

Examples of br.com.caelum.vraptor.validator.ValidationMessage


  private <T> Answer<T> addErrorsToListAndReturn(final T value, final String... messages) {
    return new Answer<T>() {

      public T answer(InvocationOnMock invocation) throws Throwable {
        for (String message : messages) {
          errors.add(new ValidationMessage(message, "test"));
        }
        return value;
      }

    };
View Full Code Here


    verify(response).addHeader("Location", "http://myapp.com/resource/method");
  }

  @Test
  public void shouldSerializeErrorMessages() throws Exception {
    Message normal = new ValidationMessage("The message", "category");
    I18nMessage i18ned = new I18nMessage("category", "message");
    i18ned.setBundle(new SingletonResourceBundle("message", "Something else"));
   
    MockSerializationResult result = new MockSerializationResult(XStreamBuilderImpl.cleanInstance(new MessageConverter()));
    DefaultStatus status = new DefaultStatus(response, result, config, new JavassistProxifier(new ObjenesisInstanceCreator()), router);
View Full Code Here

    assertThat(serialized, not(containsString("<validationMessage>")));
    assertThat(serialized, not(containsString("<i18nMessage>")));
  }
  @Test
  public void shouldSerializeErrorMessagesInJSON() throws Exception {
    Message normal = new ValidationMessage("The message", "category");
    I18nMessage i18ned = new I18nMessage("category", "message");
    i18ned.setBundle(new SingletonResourceBundle("message", "Something else"));

    MockSerializationResult result = new MockSerializationResult(XStreamBuilderImpl.cleanInstance(new MessageConverter())) {
      @Override
View Full Code Here

      try {
        Parameter parameter = parameters.namedAfter(target);
        return converterForTarget(target).convert(parameter.getValue(), target.getClassType(), localization.getBundle());
      }
      catch (ConversionError ex) {
        validator.add(new ValidationMessage(ex.getMessage(), target.getName()));
      }
      catch (Exception e) {
        if (e.getClass().isAnnotationPresent(ValidationException.class)) {
          validator.add(new ValidationMessage(e.getLocalizedMessage(), target.getName()));
        } else {
          throw new InvalidParameterException("Exception when trying to instantiate " + target, e);
        }
      }
      return null;
View Full Code Here

        if (logger.isDebugEnabled()) {
          logger.debug("Applying " + key + " with " + Arrays.toString(values));
        }
        Ognl.setValue(key, context, root, values.length == 1 ? values[0] : values);
      } catch (ConversionError ex) {
        errors.add(new ValidationMessage(ex.getMessage(), key));
      } catch (MethodFailedException e) { // setter threw an exception

        Throwable cause = e.getCause();
        if (cause.getClass().isAnnotationPresent(ValidationException.class)) {
          errors.add(new ValidationMessage(cause.getLocalizedMessage(), key));
        } else {
          throw new InvalidParameterException("unable to parse expression '" + key + "'", e);
        }

      } catch (NoSuchPropertyException ex) {
View Full Code Here

      try {
        Parameter parameter = parameters.namedAfter(target);
        return converterForTarget(target).convert(parameter.getValue(), target.getClassType(), localization.getBundle());
      }
      catch (ConversionError ex) {
        validator.add(new ValidationMessage(ex.getMessage(), target.getName()));
      }
      catch (Exception e) {
        if (e.getClass().isAnnotationPresent(ValidationException.class)) {
          validator.add(new ValidationMessage(e.getLocalizedMessage(), target.getName()));
        } else {
          throw new InvalidParameterException("Exception when trying to instantiate " + target, e);
        }
      }
      return null;
View Full Code Here

    IModel model = null;
    try {
      model = newInstanceModel();
      model.setId(id);
    } catch (InstantiationException | IllegalAccessException e) {
      validator().add(new ValidationMessage(e.getMessage(), "exception"));
      validator().onErrorSendBadRequest();
    }
    return model;
  }
View Full Code Here

    for (ConstraintViolation<Object> v : violations) {
      BeanValidatorContext ctx = new BeanValidatorContext(v);
      String msg = interpolator.interpolate(v.getMessageTemplate(), ctx, locale);
      String category = extractCategory(names, v);
      validator.add(new ValidationMessage(msg, category));
     
      logger.debug("added message {}={} for contraint violation", msg, category);
    }

    stack.next(method, controllerInstance);
View Full Code Here

      return null;
    }
  }
  private void handleException(Target<?> target, Throwable e) {
    if (e.getClass().isAnnotationPresent(ValidationException.class)) {
      errors.add(new ValidationMessage(e.getLocalizedMessage(), target.getName()));
    } else if (e.getCause() == null) {
      throw new InvalidParameterException("Exception when trying to instantiate " + target, e);
    } else {
      handleException(target, e.getCause());
    }
View Full Code Here

    if (requestNames.containsKey(param.name)) {
      String[] values = requestNames.get(param.name);
      try {
        return createSimpleParameter(param, values, bundle);
      } catch(ConversionError ex) {
        errors.add(new ValidationMessage(ex.getMessage(), param.name));
        return null;
      }
    }

    OgnlContext context = createOgnlContextFor(param, bundle);
View Full Code Here

TOP

Related Classes of br.com.caelum.vraptor.validator.ValidationMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.