当前位置: 首页>>代码示例>>Java>>正文


Java Validator.validate方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: testScalarValues

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

    final Person p = new Person();
    p.firstName = "John";
    p.lastName = "Doe";
    assertEquals(0, validator.validate(p).size());

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

    // make the address invalid
    a.zipCode = null;
    assertEquals(1, validator.validate(a).size());

    // associate the invalid address with the person check the person for validity
    p.homeAddress = a;
    List<ConstraintViolation> violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("ASSERT_VALID", violations.get(0).getMessage());

    // test circular dependencies
    a.contact = p;
    violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("ASSERT_VALID", violations.get(0).getMessage());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:31,代码来源:CustomAssertValidTest.java

示例6: testJEXLExpression

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

    // test not null
    final Person p = new Person();
    List<ConstraintViolation> violations = validator.validate(p);
    assertEquals(4, violations.size());

    // test max length
    p.firstName = "Mike";
    p.lastName = "Mahoney";
    p.zipCode = "1234567"; // too long
    violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("C3", violations.get(0).getMessage());

    // test not empty
    p.zipCode = "";
    violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("C3", violations.get(0).getMessage());

    // test ok
    p.zipCode = "wqeew";
    violations = validator.validate(p);
    assertEquals(0, violations.size());

    // test object-level constraint
    p.firstName = "12345";
    p.lastName = "1234";
    violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("C0", violations.get(0).getMessage());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:35,代码来源:AssertJEXLTest.java

示例7: testOGNLExpression

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

    // test not null
    final Person p = new Person();
    List<ConstraintViolation> violations = validator.validate(p);
    assertTrue(violations.size() == 4);

    // test max length
    p.firstName = "Mike";
    p.lastName = "Mahoney";
    p.zipCode = "1234567";
    violations = validator.validate(p);
    assertTrue(violations.size() == 1);
    assertTrue(violations.get(0).getMessage().equals("C3"));

    // test not empty
    p.zipCode = "";
    violations = validator.validate(p);
    assertTrue(violations.size() == 1);
    assertTrue(violations.get(0).getMessage().equals("C3"));

    // test ok
    p.zipCode = "wqeew";
    violations = validator.validate(p);
    assertTrue(violations.size() == 0);

    // test object-level constraint
    p.firstName = "12345";
    p.lastName = "1234";
    violations = validator.validate(p);
    assertTrue(violations.size() == 1);
    assertTrue(violations.get(0).getMessage().equals("C0"));
}
 
开发者ID:sebthom,项目名称:oval,代码行数:35,代码来源:AssertOGNLTest.java

示例8: testRubyExpression

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

    // test not null
    final Person p = new Person();
    List<ConstraintViolation> violations = validator.validate(p);
    assertTrue(violations.size() == 4);

    // test max length
    p.firstName = "Mike";
    p.lastName = "Mahoney";
    p.zipCode = "1234567";
    violations = validator.validate(p);
    assertTrue(violations.size() == 1);
    assertTrue(violations.get(0).getMessage().equals("C3"));

    // test not empty
    p.zipCode = "";
    violations = validator.validate(p);
    assertTrue(violations.size() == 1);
    assertTrue(violations.get(0).getMessage().equals("C3"));

    // test ok
    p.zipCode = "wqeew";
    violations = validator.validate(p);
    assertTrue(violations.size() == 0);

    // test object-level constraint
    p.firstName = "12345";
    p.lastName = "1234";
    violations = validator.validate(p);
    assertTrue(violations.size() == 1);
    assertTrue(violations.get(0).getMessage().equals("C0"));
}
 
开发者ID:sebthom,项目名称:oval,代码行数:35,代码来源:AssertRubyTest.java

示例9: testTarget

import net.sf.oval.Validator; //导入方法依赖的package包/类
public void testTarget() {
    final Validator v = new Validator();
    List<ConstraintViolation> violations;

    final Level1 lv1 = new Level1();
    assertEquals(0, v.validate(lv1).size());

    lv1.level2a = new Level2();
    lv1.level2b = new Level2();
    assertEquals(0, v.validate(lv1).size());

    lv1.level2a.level3 = new Level3();
    violations = v.validate(lv1);
    assertEquals(1, violations.size());
    lv1.level2a.level3.name = "foo";

    lv1.level2a.level3.array = new String[] {};
    violations = v.validate(lv1);
    assertEquals(1, violations.size());
    ConstraintViolation violation = violations.get(0);
    assertTrue(violation.getContext() instanceof FieldContext);
    assertEquals("LEVEL3_ARRAY_TOO_SMALL", violation.getMessage());

    lv1.level2a.level3.array = new String[] { "123", "1234", "1234", "1234" };
    violations = v.validate(lv1);
    assertEquals(1, violations.size());
    violation = violations.get(0);
    assertTrue(violation.getContext() instanceof FieldContext);
    assertEquals("LEVEL3_ARRAY_ITEM_TOO_SMALL", violation.getMessage());

    try {
        lv1.level2b.level3 = new Level3();
        v.validate(lv1);
        fail();
    } catch (final ValidationFailedException ex) {
        assertTrue(ex.getCause() instanceof InvalidConfigurationException);
    }
}
 
开发者ID:sebthom,项目名称:oval,代码行数:39,代码来源:TargetDefaultTest.java

示例10: testClassWithoutConstraints

import net.sf.oval.Validator; //导入方法依赖的package包/类
public void testClassWithoutConstraints() {
    final TestEntity e = new TestEntity(null);

    final Validator v = new Validator();
    final List<ConstraintViolation> violations = v.validate(e);
    assertEquals(0, violations.size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:8,代码来源:ValidateClassWithoutConstraintsTest.java

示例11: testEmptyXmlConfigurer

import net.sf.oval.Validator; //导入方法依赖的package包/类
public void testEmptyXmlConfigurer() {
    final XMLConfigurer xmlConfigurer = new XMLConfigurer();
    final Validator v = new Validator(xmlConfigurer);

    final TestEntity e = new TestEntity(null);

    final List<ConstraintViolation> violations = v.validate(e);
    assertEquals(0, violations.size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:10,代码来源:ValidateClassWithoutConstraintsTest.java

示例12: testConstraintViolationOrder

import net.sf.oval.Validator; //导入方法依赖的package包/类
public void testConstraintViolationOrder() {
    final TestEntity e = new TestEntity();
    final Validator v = new Validator();
    List<ConstraintViolation> violations = v.validate(e);
    assertEquals(0, violations.size());
    e.lastname = "foo";
    violations = v.validate(e);
    assertEquals(1, violations.size());
    assertEquals("NOT_NULL", violations.get(0).getMessage());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:11,代码来源:ConditionalConstraintsTest.java

示例13: testPrimitiveArray

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

    // test min size
    List<ConstraintViolation> violations = validator.validate(account);
    assertEquals(1, violations.size());
    assertEquals("MIN_SIZE", violations.get(0).getMessage());

    // test valid
    account.items = new int[] { 1 };
    violations = validator.validate(account);
    assertEquals(0, violations.size());

    // test max size
    account.items = new int[] { 1, 2, 3, 4, 5 };
    violations = validator.validate(account);
    assertEquals(1, violations.size());
    assertEquals("MAX_SIZE", violations.get(0).getMessage());

    // test attribute not null
    account.items = null;
    violations = validator.validate(account);
    assertEquals(1, violations.size());
    assertEquals("NOT_NULL", violations.get(0).getMessage());

    // test elements max
    account.items = new int[] { 1, 100 };
    violations = validator.validate(account);
    assertEquals(1, violations.size());
    assertEquals("MAX", violations.get(0).getMessage());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:33,代码来源:PrimitiveArrayTest.java

示例14: testObjectGraph

import net.sf.oval.Validator; //导入方法依赖的package包/类
public void testObjectGraph() {
    final ClassA classA = new ClassA();
    classA.classB = new ClassB();
    classA.classC = new ClassC();
    classA.classC.classA = classA;
    classA.classB.classC = classA.classC;

    final Validator validator = new Validator();
    final List<ConstraintViolation> violations = validator.validate(classA);
    assertEquals(1, violations.size());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:12,代码来源:ObjectGraphTest.java

示例15: testMVELExpression

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

    // test not null
    final Person p = new Person();
    List<ConstraintViolation> violations = validator.validate(p);
    assertEquals(4, violations.size());

    // test max length
    p.firstName = "Mike";
    p.lastName = "Mahoney";
    p.zipCode = "1234567"; // too long
    violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("C3", violations.get(0).getMessage());

    // test not empty
    p.zipCode = "";
    violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("C3", violations.get(0).getMessage());

    // test ok
    p.zipCode = "wqeew";
    violations = validator.validate(p);
    assertEquals(0, violations.size());

    // test object-level constraint
    p.firstName = "12345";
    p.lastName = "1234";
    violations = validator.validate(p);
    assertEquals(1, violations.size());
    assertEquals("C0", violations.get(0).getMessage());
}
 
开发者ID:sebthom,项目名称:oval,代码行数:35,代码来源:AssertMVELTest.java


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