Esempio n. 1
0
 /**
  * Validate a set of properties for a description, and return a report.
  *
  * @param props the input properties
  * @param desc the configuration description
  * @return the validation report
  */
 public static Report validate(final Properties props, final Description desc) {
   final Report report = new Report();
   final List<Property> properties = desc.getProperties();
   if (null != properties) {
     for (final Property property : properties) {
       final String key = property.getName();
       final String value = props.getProperty(key);
       if (null == value || "".equals(value)) {
         if (property.isRequired()) {
           report.errors.put(key, "required");
           continue;
         }
       } else {
         // try to validate
         final Property.Validator validator = property.getValidator();
         if (null != validator) {
           try {
             if (!validator.isValid(value)) {
               report.errors.put(key, "Invalid value");
             }
           } catch (ValidationException e) {
             report.errors.put(key, "Invalid value: " + e.getMessage());
           }
         }
       }
     }
   }
   return report;
 }
  public void testMessageInterpolation() {
    // get validators
    List validatorList =
        annotationActionValidatorManager.getValidators(
            AnnotatedTestBean.class, "beanMessageBundle");
    assertEquals(3, validatorList.size());

    try {
      AnnotatedTestBean bean = new AnnotatedTestBean();
      bean.setName("foo");
      bean.setCount(150);

      ValidatorContext context = new GenericValidatorContext(bean);
      annotationActionValidatorManager.validate(bean, "beanMessageBundle", context);
      assertTrue(context.hasErrors());
      assertTrue(context.hasFieldErrors());

      List<String> l = context.getFieldErrors().get("count");
      assertNotNull(l);
      assertEquals(1, l.size());
      assertEquals("Count must be between 1 and 100, current value is 150.", l.get(0));
    } catch (ValidationException ex) {
      ex.printStackTrace();
      fail("Validation error: " + ex.getMessage());
    }
  }
Esempio n. 3
0
 /**
  * Get the typed value of a node that is annotated with this schema type. This method must be
  * called only for a valid type.
  *
  * @param node the node whose typed value is required
  * @return a SequenceIterator over the atomic values making up the typed value of the specified
  *     node. The objects returned by this iterator are of type {@link
  *     org.orbeon.saxon.value.AtomicValue}
  */
 public SequenceIterator getTypedValue(NodeInfo node) throws XPathException {
   try {
     return getTypedValue(
         node.getStringValue(),
         new InscopeNamespaceResolver(node),
         node.getConfiguration().getNameChecker());
   } catch (ValidationException err) {
     throw new XPathException(
         "Internal error: value doesn't match its type annotation. " + err.getMessage());
   }
 }
 public boolean isAccountCreationSuccessful() {
   try {
     gatherNewAccountInfo();
     validateCredentials();
     storeLoginAttributes();
     return true;
   } catch (ValidationException ex) {
     request.setAttribute("error", ex.getMessage());
     return false;
   }
 }
Esempio n. 5
0
  public void register() {
    if (user.getPassword().equals(verify)) {

      try {
        userService.createUser(user);
        hibernateTestService.testHibernateIntegration();
        registered = true;
      } catch (ValidationException e) {
        facesMessages.add(e.getMessage());
      }
    } else {
      facesMessages.add("verify", "Re-enter your password");
      verify = null;
    }
  }
Esempio n. 6
0
  @Override
  protected void processSubmission(String elementName) {
    String value = request.getParameter(elementName);

    tracker.recordInput(this, value);

    updateClientTimeZone(elementName);

    Date parsedValue = null;

    try {
      if (InternalUtils.isNonBlank(value)) {
        // Regardless of the timeZone set on the DateFormat, the value is parsed in
        // the current default TimeZone. Use the calendar to adjust it out.

        Date inDefaultTimeZone = format.parse(value);

        parsedValue = convertDateToClientTimeZone(inDefaultTimeZone);
      }
    } catch (ParseException ex) {
      tracker.recordError(this, messages.format("tapx-date-value-not-parseable", value));
      return;
    }

    try {
      fieldValidationSupport.validate(parsedValue, resources, validate);

    } catch (ValidationException ex) {
      tracker.recordError(this, ex.getMessage());

      return;
    }

    if (min != null && parsedValue.before(min)) {
      tracker.recordError(this, messages.get("tapx-date-value-to-early"));
      return;
    }

    if (max != null && parsedValue.after(max)) {
      tracker.recordError(this, messages.get("tapx-date-value-too-late"));
      return;
    }

    this.value = parsedValue;
  }
Esempio n. 7
0
  @SuppressWarnings({"unchecked"})
  @Override
  protected void processSubmission(String controlName) {
    UploadedFile uploaded = decoder.getFileUpload(controlName);

    if (uploaded != null
        && (uploaded.getFileName() == null || uploaded.getFileName().length() == 0)) {
      uploaded = null;
    }

    try {
      fieldValidationSupport.validate(uploaded, resources, validate);
    } catch (ValidationException ex) {
      validationTracker.recordError(this, ex.getMessage());
    }

    value = uploaded;
  }
  public void testShortCircuitNoErrors() {
    // get validators
    List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
    assertEquals(10, validatorList.size());

    try {
      AnnotationUser user = new AnnotationUser();
      user.setName("Mark");
      user.setEmail("*****@*****.**");
      user.setEmail2("*****@*****.**");

      ValidatorContext context = new GenericValidatorContext(user);
      annotationActionValidatorManager.validate(user, null, context);
      assertFalse(context.hasErrors());
    } catch (ValidationException ex) {
      ex.printStackTrace();
      fail("Validation error: " + ex.getMessage());
    }
  }
 @Test
 public void 金融機関口座を取得する() {
   tx(
       () -> {
         assertThat(
             FiAccount.load(rep, "normal", "sample", "JPY"),
             allOf(
                 hasProperty("accountId", is("normal")),
                 hasProperty("category", is("sample")),
                 hasProperty("currency", is("JPY")),
                 hasProperty("fiCode", is("sample-JPY")),
                 hasProperty("fiAccountId", is("FInormal"))));
         try {
           FiAccount.load(rep, "normal", "sample", "USD");
           fail();
         } catch (ValidationException e) {
           assertThat(e.getMessage(), is(ErrorKeys.EntityNotFound));
         }
       });
 }
Esempio n. 10
0
  @SuppressWarnings({"unchecked"})
  @Override
  protected void processSubmission(String controlName) {
    String submittedValue = request.getParameter(controlName);

    tracker.recordInput(this, submittedValue);

    Object selectedValue = toValue(submittedValue);

    putPropertyNameIntoBeanValidationContext("value");

    try {
      fieldValidationSupport.validate(selectedValue, resources, validate);

      value = selectedValue;
    } catch (ValidationException ex) {
      tracker.recordError(this, ex.getMessage());
    }

    removePropertyNameFromBeanValidationContext();
  }
  public void testSkipAllActionLevelShortCircuit2() {
    // get validators
    List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
    assertEquals(10, validatorList.size());

    try {
      AnnotationUser user = new AnnotationUser();
      user.setName("Mark");
      // * mark both email to starts with mark to get pass the action-level validator,
      // so we could concentrate on testing the field-level validators
      // (AnnotationUser-validation.xml)
      // * make both email the same to pass the action-level validator at
      // AnnotationUserMarker-validation.xml
      user.setEmail("*****@*****.**");
      user.setEmail2("*****@*****.**");

      ValidatorContext context = new GenericValidatorContext(user);
      annotationActionValidatorManager.validate(user, null, context);
      assertTrue(context.hasFieldErrors());

      // check field errors
      // we have an error in this field level, email does not ends with mycompany.com
      List l = (List) context.getFieldErrors().get("email");
      assertNotNull(l);
      assertEquals(1, l.size()); // because email-field-val is short-circuit
      assertEquals("Email not from the right company.", l.get(0));

      // check action errors
      l = (List) context.getActionErrors();
      assertFalse(context.hasActionErrors());
      assertEquals(0, l.size());

    } catch (ValidationException ex) {
      ex.printStackTrace();
      fail("Validation error: " + ex.getMessage());
    }
  }
  public void testSkipUserMarkerActionLevelShortCircuit() {
    // get validators
    List validatorList = annotationActionValidatorManager.getValidators(AnnotationUser.class, null);
    assertEquals(10, validatorList.size());

    try {
      AnnotationUser user = new AnnotationUser();
      user.setName("Mark");
      user.setEmail("bad_email");
      user.setEmail2("bad_email");

      ValidatorContext context = new GenericValidatorContext(user);
      annotationActionValidatorManager.validate(user, null, context);
      assertTrue(context.hasFieldErrors());

      // check field errors
      List<String> l = context.getFieldErrors().get("email");
      assertNotNull(l);
      assertEquals(1, l.size());
      assertEquals("Not a valid e-mail.", l.get(0));
      l = context.getFieldErrors().get("email2");
      assertNotNull(l);
      assertEquals(2, l.size());
      assertEquals("Not a valid e-mail2.", l.get(0));
      assertEquals("Email2 not from the right company.", l.get(1));

      // check action errors
      assertTrue(context.hasActionErrors());
      l = (List<String>) context.getActionErrors();
      assertNotNull(l);
      assertEquals(2, l.size()); // both expression test failed see AnnotationUser-validation.xml
      assertEquals("Email does not start with mark", l.get(0));
    } catch (ValidationException ex) {
      ex.printStackTrace();
      fail("Validation error: " + ex.getMessage());
    }
  }