Skip to content

Commit de09f8c

Browse files
committed
Support for Bean Validation 2.0 container elements (with BV 2.0 test setup)
Includes latest dependency updates (Hibernate Validator 6.0.1, Caffeine 2.5.4, Netty 4.1.14, Tomcat 8.5.19, Johnzon 1.1.2, JsonPath 2.4, Jython 2.7.1) Issue: SPR-15839 Issue: SPR-15808
1 parent 48f95e9 commit de09f8c

File tree

10 files changed

+1193
-36
lines changed

10 files changed

+1193
-36
lines changed

build.gradle

+28-25
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ configure(allprojects) { project ->
3939
ext.activationApiVersion = "1.1.1"
4040
ext.annotationApiVersion = "1.3"
4141
ext.aspectjVersion = "1.9.0.BETA-6"
42-
ext.beanvalVersion = "1.1.0.Final"
42+
ext.beanvalVersion = "2.0.0.Final"
4343
ext.cacheApiVersion = "1.0.0"
44-
ext.caffeineVersion = "2.5.3"
44+
ext.caffeineVersion = "2.5.4"
4545
ext.eclipselinkVersion = "2.6.5-RC2"
4646
ext.ehcacheVersion = "2.10.4"
4747
ext.ehcachejcacheVersion = "1.0.1"
@@ -54,7 +54,7 @@ configure(allprojects) { project ->
5454
ext.gsonVersion = "2.8.1"
5555
ext.hamcrestVersion = "1.3"
5656
ext.hibernate5Version = "5.2.10.Final"
57-
ext.hibvalVersion = "5.4.1.Final"
57+
ext.hibvalVersion = "6.0.1.Final"
5858
ext.hsqldbVersion = "2.4.0"
5959
ext.httpasyncVersion = "4.1.3"
6060
ext.httpclientVersion = "4.5.3"
@@ -77,7 +77,7 @@ configure(allprojects) { project ->
7777
ext.junitJupiterVersion = '5.0.0-RC2'
7878
ext.junitPlatformVersion = '1.0.0-RC2'
7979
ext.log4jVersion = '2.8.2'
80-
ext.nettyVersion = "4.1.13.Final"
80+
ext.nettyVersion = "4.1.14.Final"
8181
ext.niomultipartVersion = "1.1.0"
8282
ext.okhttp3Version = "3.8.1"
8383
ext.poiVersion = "3.16"
@@ -94,7 +94,7 @@ configure(allprojects) { project ->
9494
ext.snakeyamlVersion = "1.18"
9595
ext.testngVersion = "6.11"
9696
ext.tiles3Version = "3.0.7"
97-
ext.tomcatVersion = "8.5.16"
97+
ext.tomcatVersion = "8.5.19"
9898
ext.tyrusVersion = "1.13.1"
9999
ext.undertowVersion = "1.4.18.Final"
100100
ext.websocketVersion = "1.1"
@@ -512,9 +512,8 @@ project("spring-context") {
512512
optional("javax.interceptor:javax.interceptor-api:${interceptorApiVersion}")
513513
optional("javax.enterprise.concurrent:javax.enterprise.concurrent-api:1.0")
514514
optional("javax.money:money-api:1.0.1")
515-
optional("org.eclipse.persistence:javax.persistence:${jpaVersion}")
516-
optional("javax.validation:validation-api:${beanvalVersion}")
517-
optional("org.hibernate:hibernate-validator:${hibvalVersion}")
515+
optional("javax.validation:validation-api:1.1.0.Final")
516+
optional("org.hibernate:hibernate-validator:5.4.1.Final")
518517
optional("joda-time:joda-time:${jodaVersion}")
519518
optional("org.aspectj:aspectjweaver:${aspectjVersion}")
520519
optional("org.codehaus.groovy:groovy-all:${groovyVersion}")
@@ -660,6 +659,17 @@ project("spring-jdbc") {
660659
}
661660
}
662661

662+
project("spring-context-indexer") {
663+
description = "Spring Context Indexer"
664+
665+
dependencies {
666+
testCompile(project(":spring-context"))
667+
testCompile("javax.inject:javax.inject:1")
668+
testCompile("javax.annotation:javax.annotation-api:${annotationApiVersion}")
669+
testCompile("org.eclipse.persistence:javax.persistence:${jpaVersion}")
670+
}
671+
}
672+
663673
project("spring-context-support") {
664674
description = "Spring Context Support"
665675

@@ -682,22 +692,16 @@ project("spring-context-support") {
682692
testCompile("org.apache.poi:poi:${poiVersion}")
683693
testCompile("org.hsqldb:hsqldb:${hsqldbVersion}")
684694
testCompile("org.slf4j:slf4j-api:${slf4jVersion}")
695+
testCompile("javax.validation:validation-api:${beanvalVersion}")
696+
testCompile("org.hibernate:hibernate-validator:${hibvalVersion}")
697+
testRuntime("javax.el:javax.el-api:${elApiVersion}")
698+
testRuntime("org.glassfish:javax.el:3.0.1-b08")
699+
testRuntime("javax.annotation:javax.annotation-api:${annotationApiVersion}")
685700
testRuntime("com.sun.mail:javax.mail:${javamailVersion}")
686701
testRuntime("org.ehcache:jcache:${ehcachejcacheVersion}")
687702
}
688703
}
689704

690-
project("spring-context-indexer") {
691-
description = "Spring Context Indexer"
692-
693-
dependencies {
694-
testCompile(project(":spring-context"))
695-
testCompile("javax.inject:javax.inject:1")
696-
testCompile("javax.annotation:javax.annotation-api:${annotationApiVersion}")
697-
testCompile("org.eclipse.persistence:javax.persistence:${jpaVersion}")
698-
}
699-
}
700-
701705
project("spring-web") {
702706
description = "Spring Web"
703707

@@ -782,7 +786,7 @@ project("spring-web") {
782786
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
783787
testRuntime("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
784788
testRuntime("javax.json:javax.json-api:1.1")
785-
testRuntime("org.apache.johnzon:johnzon-jsonb:1.1.1")
789+
testRuntime("org.apache.johnzon:johnzon-jsonb:1.1.2")
786790
}
787791
}
788792

@@ -891,7 +895,7 @@ project("spring-webmvc") {
891895
testRuntime("org.jetbrains.kotlin:kotlin-script-util:${kotlinVersion}")
892896
testRuntime("org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}")
893897
testRuntime("org.jruby:jruby:9.1.12.0")
894-
testRuntime("org.python:jython-standalone:2.5.3")
898+
testRuntime("org.python:jython-standalone:2.7.1")
895899
testRuntime("org.webjars:underscorejs:1.8.3")
896900
testRuntime("org.glassfish:javax.el:3.0.1-b08")
897901
testRuntime("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
@@ -999,7 +1003,7 @@ project("spring-webflux") {
9991003
testRuntime("org.jetbrains.kotlin:kotlin-script-util:${kotlinVersion}")
10001004
testRuntime("org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}")
10011005
testRuntime("org.jruby:jruby:9.1.12.0")
1002-
testRuntime("org.python:jython-standalone:2.5.3")
1006+
testRuntime("org.python:jython-standalone:2.7.1")
10031007
testRuntime("org.synchronoss.cloud:nio-multipart-parser:${niomultipartVersion}")
10041008
testRuntime("org.webjars:underscorejs:1.8.3")
10051009
testRuntime("org.glassfish:javax.el:3.0.1-b08")
@@ -1050,7 +1054,7 @@ project("spring-test") {
10501054
exclude group: "io.netty", module: "netty"
10511055
}
10521056
optional("org.skyscreamer:jsonassert:${jsonassertVersion}")
1053-
optional("com.jayway.jsonpath:json-path:2.3.0")
1057+
optional("com.jayway.jsonpath:json-path:2.4.0")
10541058
optional("org.reactivestreams:reactive-streams")
10551059
optional("io.projectreactor:reactor-core")
10561060
optional("io.projectreactor:reactor-test")
@@ -1139,7 +1143,6 @@ project("spring-aspects") {
11391143
ajc("org.aspectj:aspectjtools:${aspectjVersion}")
11401144
rt("org.aspectj:aspectjrt:${aspectjVersion}")
11411145
compile("org.aspectj:aspectjweaver:${aspectjVersion}")
1142-
provided("org.eclipse.persistence:javax.persistence:${jpaVersion}")
11431146
optional(project(":spring-aop")) // for @Async support
11441147
optional(project(":spring-beans")) // for @Configurable support
11451148
optional(project(":spring-context")) // for @Enable* support
@@ -1269,7 +1272,7 @@ configure(rootProject) {
12691272

12701273
task wrapper(type: Wrapper) {
12711274
description = "Generates gradlew[.bat] scripts"
1272-
gradleVersion = '3.5.1'
1275+
gradleVersion = '4.1'
12731276

12741277
doLast() {
12751278
def gradleOpts = "-XX:MaxMetaspaceSize=1024m -Xmx1024m"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/*
2+
* Copyright 2002-2017 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.validation.beanvalidation2;
18+
19+
import javax.annotation.PostConstruct;
20+
import javax.validation.constraints.NotNull;
21+
import javax.validation.constraints.Size;
22+
23+
import org.junit.Test;
24+
25+
import org.springframework.beans.factory.BeanCreationException;
26+
import org.springframework.beans.factory.support.RootBeanDefinition;
27+
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
28+
import org.springframework.context.support.GenericApplicationContext;
29+
import org.springframework.tests.sample.beans.TestBean;
30+
import org.springframework.validation.beanvalidation.BeanValidationPostProcessor;
31+
32+
import static org.junit.Assert.*;
33+
34+
/**
35+
* @author Juergen Hoeller
36+
*/
37+
public class BeanValidationPostProcessorTests {
38+
39+
@Test
40+
public void testNotNullConstraint() {
41+
GenericApplicationContext ac = new GenericApplicationContext();
42+
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
43+
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
44+
ac.registerBeanDefinition("bean", new RootBeanDefinition(NotNullConstrainedBean.class));
45+
try {
46+
ac.refresh();
47+
fail("Should have thrown BeanCreationException");
48+
}
49+
catch (BeanCreationException ex) {
50+
assertTrue(ex.getRootCause().getMessage().contains("testBean"));
51+
assertTrue(ex.getRootCause().getMessage().contains("invalid"));
52+
}
53+
ac.close();
54+
}
55+
56+
@Test
57+
public void testNotNullConstraintSatisfied() {
58+
GenericApplicationContext ac = new GenericApplicationContext();
59+
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
60+
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
61+
RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
62+
bd.getPropertyValues().add("testBean", new TestBean());
63+
ac.registerBeanDefinition("bean", bd);
64+
ac.refresh();
65+
ac.close();
66+
}
67+
68+
@Test
69+
public void testNotNullConstraintAfterInitialization() {
70+
GenericApplicationContext ac = new GenericApplicationContext();
71+
RootBeanDefinition bvpp = new RootBeanDefinition(BeanValidationPostProcessor.class);
72+
bvpp.getPropertyValues().add("afterInitialization", true);
73+
ac.registerBeanDefinition("bvpp", bvpp);
74+
ac.registerBeanDefinition("capp", new RootBeanDefinition(CommonAnnotationBeanPostProcessor.class));
75+
ac.registerBeanDefinition("bean", new RootBeanDefinition(AfterInitConstraintBean.class));
76+
ac.refresh();
77+
ac.close();
78+
}
79+
80+
@Test
81+
public void testSizeConstraint() {
82+
GenericApplicationContext ac = new GenericApplicationContext();
83+
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
84+
RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
85+
bd.getPropertyValues().add("testBean", new TestBean());
86+
bd.getPropertyValues().add("stringValue", "s");
87+
ac.registerBeanDefinition("bean", bd);
88+
try {
89+
ac.refresh();
90+
fail("Should have thrown BeanCreationException");
91+
}
92+
catch (BeanCreationException ex) {
93+
assertTrue(ex.getRootCause().getMessage().contains("stringValue"));
94+
assertTrue(ex.getRootCause().getMessage().contains("invalid"));
95+
}
96+
ac.close();
97+
}
98+
99+
@Test
100+
public void testSizeConstraintSatisfied() {
101+
GenericApplicationContext ac = new GenericApplicationContext();
102+
ac.registerBeanDefinition("bvpp", new RootBeanDefinition(BeanValidationPostProcessor.class));
103+
RootBeanDefinition bd = new RootBeanDefinition(NotNullConstrainedBean.class);
104+
bd.getPropertyValues().add("testBean", new TestBean());
105+
bd.getPropertyValues().add("stringValue", "ss");
106+
ac.registerBeanDefinition("bean", bd);
107+
ac.refresh();
108+
ac.close();
109+
}
110+
111+
112+
public static class NotNullConstrainedBean {
113+
114+
@NotNull
115+
private TestBean testBean;
116+
117+
@Size(min = 2)
118+
private String stringValue;
119+
120+
public TestBean getTestBean() {
121+
return testBean;
122+
}
123+
124+
public void setTestBean(TestBean testBean) {
125+
this.testBean = testBean;
126+
}
127+
128+
public String getStringValue() {
129+
return stringValue;
130+
}
131+
132+
public void setStringValue(String stringValue) {
133+
this.stringValue = stringValue;
134+
}
135+
136+
@PostConstruct
137+
public void init() {
138+
assertNotNull("Shouldn't be here after constraint checking", this.testBean);
139+
}
140+
}
141+
142+
143+
public static class AfterInitConstraintBean {
144+
145+
@NotNull
146+
private TestBean testBean;
147+
148+
public TestBean getTestBean() {
149+
return testBean;
150+
}
151+
152+
public void setTestBean(TestBean testBean) {
153+
this.testBean = testBean;
154+
}
155+
156+
@PostConstruct
157+
public void init() {
158+
this.testBean = new TestBean();
159+
}
160+
}
161+
162+
}

0 commit comments

Comments
 (0)