Java 类org.springframework.validation.beanvalidation.BeanValidationPostProcessor 实例源码

项目:spring4-understanding    文件:BeanValidationPostProcessorTests.java   
@Test
public void testNotNullConstraint() {
    GenericApplicationContext ac = new GenericApplicationContext();
    ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
    ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
    ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class));
    try {
        ac.refresh();
        fail("Should have thrown BeanCreationException");
    }
    catch (BeanCreationException ex) {
        assertTrue(ex.getRootCause().getMessage().contains("testBean"));
        assertTrue(ex.getRootCause().getMessage().contains("invalid"));
    }
    ac.close();
}
项目:spring4-understanding    文件:BeanValidationPostProcessorTests.java   
@Test
public void testSizeConstraint() {
    GenericApplicationContext ac = new GenericApplicationContext();
    ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
    RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
    bd.getPropertyValues().add("testBean", new TestBean());
    bd.getPropertyValues().add("stringValue", "s");
    ac.registerBeanDefinition("bean", bd);
    try {
        ac.refresh();
        fail("Should have thrown BeanCreationException");
    }
    catch (BeanCreationException ex) {
        assertTrue(ex.getRootCause().getMessage().contains("stringValue"));
        assertTrue(ex.getRootCause().getMessage().contains("invalid"));
    }
    ac.close();
}
项目:spring4-understanding    文件:BeanValidationPostProcessorTests.java   
@Test
public void testNotNullConstraintSatisfied() {
    GenericApplicationContext ac = new GenericApplicationContext();
    ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
    ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
    RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
    bd.getPropertyValues().add("testBean", new TestBean());
    ac.registerBeanDefinition("bean", bd);
    ac.refresh();
    ac.close();
}
项目:spring4-understanding    文件:BeanValidationPostProcessorTests.java   
@Test
public void testNotNullConstraintAfterInitialization() {
    GenericApplicationContext ac = new GenericApplicationContext();
    RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class);
    bvpp.getPropertyValues().add("afterInitialization", true);
    ac.registerBeanDefinition("bvpp", bvpp);
    ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
    ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class));
    ac.refresh();
    ac.close();
}
项目:spring4-understanding    文件:BeanValidationPostProcessorTests.java   
@Test
public void testSizeConstraintSatisfied() {
    GenericApplicationContext ac = new GenericApplicationContext();
    ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
    RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
    bd.getPropertyValues().add("testBean", new TestBean());
    bd.getPropertyValues().add("stringValue", "ss");
    ac.registerBeanDefinition("bean", bd);
    ac.refresh();
    ac.close();
}
项目:springboot-analysis    文件:BeanPostProcessorApplication.java   
@Bean
public BeanPostProcessor beanValidationPostProcessor() {
    BeanValidationPostProcessor processor = new BeanValidationPostProcessor();
    processor.setAfterInitialization(true);
    return processor;
}