• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Validator类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中net.sf.oval.Validator的典型用法代码示例。如果您正苦于以下问题:Java Validator类的具体用法?Java Validator怎么用?Java Validator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Validator类属于net.sf.oval包,在下文中一共展示了Validator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testCheckWith1

import net.sf.oval.Validator; //导入依赖的package包/类
public void testCheckWith1() {
    final Validator validator = new Validator();

    final TestEntity1 t = new TestEntity1();

    List<ConstraintViolation> violations;

    violations = validator.validate(t);
    assertEquals(1, violations.size());

    t.name = "";
    violations = validator.validate(t);
    assertEquals(1, violations.size());

    t.name = "12345";
    violations = validator.validate(t);
    assertEquals(1, violations.size());

    t.name = "1234";
    violations = validator.validate(t);
    assertEquals(0, violations.size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:23,代码来源:CheckWithListConstraintTest.java


示例2: testCheckWith2

import net.sf.oval.Validator; //导入依赖的package包/类
public void testCheckWith2() {
    final Validator validator = new Validator();

    final TestEntity2 t = new TestEntity2();

    List<ConstraintViolation> violations;

    violations = validator.validate(t);
    assertEquals(1, violations.size());

    t.name = "";
    violations = validator.validate(t);
    assertEquals(1, violations.size());

    t.name = "12345";
    violations = validator.validate(t);
    assertEquals(1, violations.size());

    t.name = "1234";
    violations = validator.validate(t);
    assertEquals(0, violations.size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:23,代码来源:CheckWithListConstraintTest.java


示例3: testAddConstraintToField

import net.sf.oval.Validator; //导入依赖的package包/类
/**
 * programmatically add a NotNull constraint to the name field
 */
public void testAddConstraintToField() throws Exception {
    final Validator validator = new Validator();

    final TestEntity entity = new TestEntity(null);
    assertTrue(validator.validate(entity).size() == 0);

    final Field field = TestEntity.class.getDeclaredField("name");
    final NotNullCheck notNullCheck = new NotNullCheck();
    notNullCheck.setMessage("NOT_NULL");

    validator.addChecks(field, notNullCheck);

    final List<ConstraintViolation> violations = validator.validate(entity);
    assertTrue(violations.size() == 1);
    assertTrue(violations.get(0).getMessage().equals("NOT_NULL"));
}
 
开发者ID:sebthom,项目名称:oval,代码行数:20,代码来源:AddingChecksTest.java


示例4: validate

import net.sf.oval.Validator; //导入依赖的package包/类
default void validate(Validator ovalValidator) {
    if (ovalValidator != null) {
        List<ConstraintViolation> constraintViolations = ovalValidator.validate(this);
        if (constraintViolations.size() > 0) {
            final Map<String, List<String>> errorMap = new HashMap<>();
            final String className = this.getClass().getName() + ".";

            constraintViolations
                    .forEach(constraintViolation ->
                            errorMap.computeIfAbsent(constraintViolation.getCheckDeclaringContext().toString().replace(className, ""), k -> new ArrayList<>())
                                    .add(constraintViolation.getMessage().replace(className, "")));

            throw new ExceptionAdapter(new CustomOvalException(errorMap));
        }
    }
}
 
开发者ID:Pivopil,项目名称:spring-boot-oauth2-rest-service-password-encoding,代码行数:17,代码来源:EntityBuilder.java


示例5: isSatisfied

import net.sf.oval.Validator; //导入依赖的package包/类
public boolean isSatisfied(final Object validatedObject, final Object valueToValidate, final OValContext context, final Validator validator)
        throws ReflectionException {
    if (valueToValidate == null && ignoreIfNull)
        return true;

    final Class<?> clazz = validatedObject.getClass();
    Method method;
    synchronized (validationMethodsByClass) {
        method = validationMethodsByClass.get(clazz);
        if (method == null) {
            method = ReflectionUtils.getMethodRecursive(clazz, methodName, parameterType);
            validationMethodsByClass.put(clazz, method);
        }
    }
    if (method == null)
        throw new InvalidConfigurationException("Method " + clazz.getName() + "." + methodName + "(" + parameterType + ") not found. Is [" + parameterType
                + "] the correct value for [@ValidateWithMethod.parameterType]?");
    //explicit cast to workaround: type parameters of <T>T cannot be determined; no unique maximal instance exists for type variable T with upper bounds boolean,java.lang.Object
    return (Boolean) ReflectionUtils.invokeMethod(method, validatedObject, valueToValidate);
}
 
开发者ID:sebthom,项目名称:oval,代码行数:21,代码来源:ValidateWithMethodCheck.java


示例6: isSatisfied

import net.sf.oval.Validator; //导入依赖的package包/类
public boolean isSatisfied(final Object validatedObject, final Object valueToValidate, final OValContext context, final Validator validator) {
    if (valueToValidate == null)
        return true;

    if (valueToValidate instanceof Number) {
        if (valueToValidate instanceof Float || valueToValidate instanceof Double)
            return ((Number) valueToValidate).doubleValue() >= 0;
        if (valueToValidate instanceof BigDecimal)
            return ((BigDecimal) valueToValidate).compareTo(ZERO) >= 0;
        return ((Number) valueToValidate).longValue() >= 0;
    }

    final String stringValue = valueToValidate.toString();
    try {
        return Double.parseDouble(stringValue) >= 0;
    } catch (final NumberFormatException e) {
        return false;
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:20,代码来源:NotNegativeCheck.java


示例7: renderMessage

import net.sf.oval.Validator; //导入依赖的package包/类
public static String renderMessage(final String messageKey, final Map<String, ?> messageValues) {
    String message = Validator.getMessageResolver().getMessage(messageKey);
    if (message == null)
        message = messageKey;

    final MessageValueFormatter formatter = Validator.getMessageValueFormatter();

    // if there are no place holders in the message simply return it
    if (message.indexOf('{') == -1)
        return message;

    if (messageValues != null && messageValues.size() > 0)
        for (final Entry<String, ?> entry : messageValues.entrySet())
        message = StringUtils.replaceAll(message, "{" + entry.getKey() + "}", formatter.format(entry.getValue()));
    return message;
}
 
开发者ID:sebthom,项目名称:oval,代码行数:17,代码来源:MessageRenderer.java


示例8: testCollectionValues

import net.sf.oval.Validator; //导入依赖的package包/类
public void testCollectionValues() {
    final Validator validator = new Validator(new CustomAnnotationConfigurer());

    final Person p = new Person();
    p.firstName = "John";
    p.lastName = "Doe";
    p.otherAddresses1 = new ArrayList<Address>();
    p.otherAddresses2 = new HashSet<Address>();
    p.otherAddresses3 = new HashSet<Address>();

    final Address a = new Address();
    a.street = "The Street";
    a.city = "The City";
    a.zipCode = null;
    assertEquals(1, validator.validate(a).size());

    p.otherAddresses1.add(a);
    assertEquals(1, validator.validate(p).size());

    p.otherAddresses1.remove(a);
    p.otherAddresses2.add(a);
    assertEquals(0, validator.validate(p).size());

    p.otherAddresses3.add(a);
    assertEquals(1, validator.validate(p).size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:27,代码来源:CustomAssertValidTest.java


示例9: testConcurrency

import net.sf.oval.Validator; //导入依赖的package包/类
public void testConcurrency() throws InterruptedException {
    final Validator validator = new Validator();

    final TestEntity1 sharedEntity = new TestEntity1();

    final boolean[] failed = { false };

    final Thread thread1 = new Thread(new TestRunner(validator, sharedEntity, failed));
    final Thread thread2 = new Thread(new TestRunner(validator, sharedEntity, failed));

    thread1.start();
    thread2.start();
    thread1.join();
    thread2.join();
    assertFalse(failed[0]);
}
 
开发者ID:sebthom,项目名称:oval,代码行数:17,代码来源:ConcurrencyTest.java


示例10: testMethodReturnValueConstraintValidation

import net.sf.oval.Validator; //导入依赖的package包/类
public void testMethodReturnValueConstraintValidation() {
    final Validator validator = new Validator();

    {
        final TestEntity t = new TestEntity();

        List<ConstraintViolation> violations = validator.validate(t);
        assertTrue(violations.size() == 1);
        assertTrue(violations.get(0).getMessage().equals("NOT_NULL"));

        t.name = "wqerwqer";
        violations = validator.validate(t);
        assertTrue(violations.size() == 1);
        assertTrue(violations.get(0).getMessage().equals("LENGTH"));
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:17,代码来源:InvariantMethodConstraintsValidationTest.java


示例11: testCheckByMethod

import net.sf.oval.Validator; //导入依赖的package包/类
public void testCheckByMethod() {
    final Validator validator = new Validator();

    final TestEntity t = new TestEntity();

    List<ConstraintViolation> violations;

    violations = validator.validate(t);
    assertTrue(violations.size() == 1);

    t.name = "";
    violations = validator.validate(t);
    assertTrue(violations.size() == 1);

    t.name = "12345";
    violations = validator.validate(t);
    assertTrue(violations.size() == 1);

    t.name = "1234";
    violations = validator.validate(t);
    assertTrue(violations.size() == 0);
}
 
开发者ID:sebthom,项目名称:oval,代码行数:23,代码来源:ValidateWithMethodConstraintTest.java


示例12: testValidatorAssert

import net.sf.oval.Validator; //导入依赖的package包/类
public void testValidatorAssert() throws Exception {
    final TestEntity e = new TestEntity();
    final Validator v = new Validator();
    try {
        v.assertValid(e);
        fail();
    } catch (final ConstraintsViolatedException ex) {
        final ConstraintViolation[] violations = ex.getConstraintViolations();
        assertEquals(2, violations.length);
        assertEquals("NOT_NULL", violations[0].getMessage());
        assertEquals("NOT_NULL", violations[1].getMessage());
    }

    e.name = "asdads";
    e.value = 5;
    v.assertValid(e);
}
 
开发者ID:sebthom,项目名称:oval,代码行数:18,代码来源:ValidatorAssertValidTest.java


示例13: testValidatorAssertField

import net.sf.oval.Validator; //导入依赖的package包/类
public void testValidatorAssertField() throws Exception {
    final Field f = TestEntity.class.getField("name");

    final TestEntity e = new TestEntity();
    final Validator v = new Validator();
    try {
        v.assertValidFieldValue(e, f, null);
        fail();
    } catch (final ConstraintsViolatedException ex) {
        final ConstraintViolation[] violations = ex.getConstraintViolations();
        assertEquals(1, violations.length);
        assertEquals("NOT_NULL", violations[0].getMessage());
    }

    v.assertValidFieldValue(e, f, "test");
}
 
开发者ID:sebthom,项目名称:oval,代码行数:17,代码来源:ValidatorAssertValidTest.java


示例14: testSerialization

import net.sf.oval.Validator; //导入依赖的package包/类
public void testSerialization() throws IOException, ClassNotFoundException {
    final Validator validator = new Validator();

    final Person p = new Person();
    p.firstName = "123456";
    List<ConstraintViolation> violations = validator.validate(p);
    assertTrue(violations.size() == 1);

    // serialize the violations
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(bos);
    oos.writeObject(violations);
    oos.flush();
    byte[] bytes = bos.toByteArray();

    // deserialize the violations
    ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
    ObjectInputStream ois = new ObjectInputStream(bis);
    assertTrue(ois.readObject() instanceof List);
}
 
开发者ID:sebthom,项目名称:oval,代码行数:21,代码来源:SerializationTest.java


示例15: testNonstaticValidation

import net.sf.oval.Validator; //导入依赖的package包/类
public void testNonstaticValidation() {
    final Validator validator = new Validator();

    TestEntity.staticA = null;
    TestEntity.staticB = null;

    // test that only non static fields are validated
    final TestEntity t = new TestEntity();
    List<ConstraintViolation> violations = validator.validate(t);
    assertTrue(violations.size() == 2);

    t.nonstaticA = "";
    t.nonstaticB = "";

    violations = validator.validate(t);
    assertTrue(violations.size() == 0);
}
 
开发者ID:sebthom,项目名称:oval,代码行数:18,代码来源:StaticFieldsAndGettersTest.java


示例16: testValidateFieldValue

import net.sf.oval.Validator; //导入依赖的package包/类
public void testValidateFieldValue() throws SecurityException, NoSuchFieldException {
    final Validator validator = new Validator();

    final Person p = new Person();
    final Field fieldHomeAddress = p.getClass().getDeclaredField("homeAddress");
    final Address a = new Address();

    final List<ConstraintViolation> violations = validator.validateFieldValue(p, fieldHomeAddress, a);
    assertEquals(1, violations.size());
    assertEquals("ASSERT_VALID", violations.get(0).getMessage());
    assertEquals(a, violations.get(0).getInvalidValue());
    assertEquals(3, violations.get(0).getCauses().length);
    for (final ConstraintViolation cv : violations.get(0).getCauses())
        if ("NOT_NULL_STREET".equals(cv.getMessage()))
            assertEquals("street", ((FieldContext) cv.getContext()).getField().getName());
    a.street = "The Street";
    a.city = "The City";
    a.zipCode = "12345";
    assertEquals(0, validator.validateFieldValue(p, fieldHomeAddress, a).size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:21,代码来源:AssertValidTest.java


示例17: testCollectionValues

import net.sf.oval.Validator; //导入依赖的package包/类
public void testCollectionValues() {
    final Validator validator = new Validator();

    final Person p = new Person();
    p.firstName = "John";
    p.lastName = "Doe";
    p.otherAddresses1 = new ArrayList<Address>();
    p.otherAddresses2 = new HashSet<Address>();
    p.otherAddresses3 = new HashSet<Address>();

    final Address a = new Address();
    a.street = "The Street";
    a.city = "The City";
    a.zipCode = null;
    assertEquals(1, validator.validate(a).size());

    p.otherAddresses1.add(a);
    assertEquals(1, validator.validate(p).size());

    p.otherAddresses1.remove(a);
    p.otherAddresses2.add(a);
    assertEquals(0, validator.validate(p).size());

    p.otherAddresses3.add(a);
    assertEquals(1, validator.validate(p).size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:27,代码来源:AssertValidTest.java


示例18: CustomUserDetailsService

import net.sf.oval.Validator; //导入依赖的package包/类
@Autowired
public CustomUserDetailsService(UserRepository userRepository, CustomSecurityService customSecurityService, RoleRepository roleRepository, CustomACLService customACLService, PasswordEncoder passwordEncoder, Validator ovalValidator) {
    this.userRepository = userRepository;
    this.customSecurityService = customSecurityService;
    this.roleRepository = roleRepository;
    this.customACLService = customACLService;
    this.passwordEncoder = passwordEncoder;
    this.ovalValidator = ovalValidator;
}
 
开发者ID:Pivopil,项目名称:spring-boot-oauth2-rest-service-password-encoding,代码行数:10,代码来源:CustomUserDetailsService.java


示例19: isSatisfied

import net.sf.oval.Validator; //导入依赖的package包/类
public boolean isSatisfied(final Object validatedObject, final Object valueToValidate, final OValContext context, final Validator validator) {
    if (valueToValidate == null)
        return true;

    for (final Class<?> type : types)
        if (type.isInstance(valueToValidate))
            return true;
    return false;
}
 
开发者ID:sebthom,项目名称:oval,代码行数:10,代码来源:InstanceOfAnyCheck.java


示例20: getMembersLowerCase

import net.sf.oval.Validator; //导入依赖的package包/类
private List<String> getMembersLowerCase() {
    if (membersLowerCase == null) {
        membersLowerCase = getCollectionFactory().createList(members.size());
        for (final String val : members) {
            membersLowerCase.add(val.toLowerCase(Validator.getLocaleProvider().getLocale()));
        }
    }
    return membersLowerCase;
}
 
开发者ID:sebthom,项目名称:oval,代码行数:10,代码来源:NotMemberOfCheck.java



注:本文中的net.sf.oval.Validator类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PsiElementRenameHandler类代码示例发布时间:2022-05-22
下一篇:
Java XSLTErrorResources类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap