Package org.crank.validation

Examples of org.crank.validation.ValidatorMetaData


  @Test()
  public void testReadMetaData() {
    List<ValidatorMetaData> list = annotationValidatorMetaDataReader.readMetaData(Employee.class, "age");
    assertNotNull(list);
    ValidatorMetaData required = list.get(0);
    assertEquals("required", required.getName());
    ValidatorMetaData range = list.get(1);
    assertEquals("range", range.getName());
    assertEquals("10",range.getProperties().get("max"));
    assertEquals("1",range.getProperties().get("min"));
   
  }
View Full Code Here


  public void testReadMetaDataWithNonStringValues() {
    List<ValidatorMetaData> list =
      annotationValidatorMetaDataReader.readMetaData(Employee.class, "iq");
    assertNotNull(list);
    assertEquals(2, list.size());
    ValidatorMetaData range = list.get(1);
    assertEquals("longRange", range.getName());
    assertEquals(100L,range.getProperties().get("max"));
    assertEquals(1L,range.getProperties().get("min"));
   
  }
View Full Code Here

    private List<ValidatorMetaData> extractMetaDataFromAnnotations(
            Collection<AnnotationData> annotations) {
        List<ValidatorMetaData> list = new ArrayList<ValidatorMetaData>();

        for (AnnotationData annotationData : annotations) {
            ValidatorMetaData validatorMetaData = convertAnnotationDataToValidatorMetaData(annotationData);
            list.add(validatorMetaData);
        }

        return list;
    }
View Full Code Here

            "Therefore, we must cache the results of getValues as the annoationData is static " +
            "per property per class. ")
    private ValidatorMetaData convertAnnotationDataToValidatorMetaData(
            AnnotationData annotationData) {
       
        ValidatorMetaData metaData = new ValidatorMetaData();
        metaData.setName(annotationData.getName());

        /* INNEFFECIENT... FIX THIS... see @NeedRefactoring at
         * getValues and above.*/
        metaData.setProperties(annotationData.getValues());

        return metaData;
    }
View Full Code Here

             ["required",
             *  ["length min=10, max=100"]
             *
             */
            for (String validatorString : validatorsParts) {
                ValidatorMetaData validatorMetaData = new ValidatorMetaData();
                validatorMetaDataList.add(validatorMetaData);
               
                /* Now we split one of the string (we will use length)
                 * as follows:
                 * parts=["length", "min=10", "max=100"]
                 * */
                String[] parts = validatorString.trim().split("[ ,]");
               
                /* The first part is the name of the validation,
                 * e.g., "length".
                 *
                 */
                validatorMetaData.setName(parts[0]);

                /* If the string has more than one part, then there must
                 * be arguments as in: ["min=10", "max=100"]
                 *
                 * Parse the arguments and add them to the list as well.
                 */
                if (parts.length > 1) {

                    /* This line converts:
                     *
                     * ["length", "min=10", "max=100"]
                     *
                     * into:
                     *
                     * ["min=10", "max=100"]
                     */
                    List<String> values =
                        Arrays.asList(parts).subList(1, parts.length);
                   
                    /* For each value convert it into name value pairs. */
                    for (String value : values) {
                       
                        if (value.indexOf("=") != -1) {
                            /* Split "min=10" into ["min", "10"] */
                            String[] valueParts = value.split("[=]");
                            /* Stick this value into validatorMetaData's
                             * list of properties.
                             */
                            validatorMetaData.getProperties().put(
                                    valueParts[0], valueParts[1]);
                        }
                    }
                }
            }
View Full Code Here

TOP

Related Classes of org.crank.validation.ValidatorMetaData

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.