[JAVA-16218] Split javaxval module

This commit is contained in:
panagiotiskakos 2022-11-21 16:39:21 +02:00
parent 06498b9d70
commit 5caddfef33
30 changed files with 141 additions and 43 deletions

6
javaxval-2/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
.classpath
.project
.settings/
target/
bin/

10
javaxval-2/README.md Normal file
View File

@ -0,0 +1,10 @@
## Java Bean Validation Examples
This module contains articles about Bean Validation.
### Relevant Articles:
- [Method Constraints with Bean Validation 2.0](https://www.baeldung.com/javax-validation-method-constraints)
- [Difference Between @NotNull, @NotEmpty, and @NotBlank Constraints in Bean Validation](https://www.baeldung.com/java-bean-validation-not-null-empty-blank)
- [Guide to ParameterMessageInterpolator](https://www.baeldung.com/hibernate-parametermessageinterpolator)
- [Hibernate Validator Annotation Processor in Depth](https://www.baeldung.com/hibernate-validator-annotation-processor)
- More articles: [[<-- prev]](../javaxval)

71
javaxval-2/pom.xml Normal file
View File

@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>javaxval-2</artifactId>
<version>0.1-SNAPSHOT</version>
<name>javaxval-2</name>
<parent>
<groupId>com.baeldung</groupId>
<artifactId>parent-modules</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>${hibernate-validator.version}</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>${javax.el.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${org.springframework.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${spring.boot.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring.boot.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- uncomment in order to enable Hibernate Validator Anotation Processor -->
<!-- <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> -->
<!--<version>${maven.compiler.version}</version> <configuration> <source>${maven.compiler.source}</source> -->
<!--<target>${maven.compiler.target}</target> <fork>true</fork> <compilerArgs> <arg>-Averbose=true</arg> -->
<!--<arg>-AmethodConstraintsSupported=true</arg> <arg>-AdiagnosticKind=ERROR</arg> </compilerArgs> -->
<!--<annotationProcessorPaths> -->
<!--<path> <groupId>org.hibernate.validator</groupId> <artifactId>hibernate-validator-annotation-processor</artifactId> -->
<!--<version>${hibernate-validator.ap.version}</version> </path> </annotationProcessorPaths> </configuration> -->
<!--</plugin> </plugins> </build> -->
<properties>
<hibernate-validator.version>6.2.3.Final</hibernate-validator.version>
<hibernate-validator.ap.version>6.2.0.Final</hibernate-validator.ap.version>
<maven.compiler.version>3.6.1</maven.compiler.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<javax.el.version>3.0.0</javax.el.version>
<org.springframework.version>5.3.21</org.springframework.version>
<spring.boot.version>2.7.1</spring.boot.version>
</properties>
</project>

View File

@ -1,10 +1,11 @@
package com.baeldung.javaxval.hibernate.validator.ap;
import java.util.List;
import java.util.Optional;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Past;
import java.util.List;
import java.util.Optional;
public class Message {

View File

@ -2,8 +2,6 @@ package com.baeldung.javaxval.methodvalidation;
import java.time.LocalDate;
import com.baeldung.javaxval.methodvalidation.model.Customer;
import com.baeldung.javaxval.methodvalidation.model.Reservation;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
@ -11,6 +9,9 @@ import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.validation.beanvalidation.MethodValidationPostProcessor;
import com.baeldung.javaxval.methodvalidation.model.Customer;
import com.baeldung.javaxval.methodvalidation.model.Reservation;
@Configuration
@ComponentScan({ "com.baeldung.javaxval.methodvalidation.model" })
public class MethodValidationConfig {

View File

@ -5,10 +5,11 @@ import java.time.LocalDate;
import javax.validation.Valid;
import javax.validation.constraints.Positive;
import com.baeldung.javaxval.methodvalidation.constraints.ValidReservation;
import com.baeldung.javaxval.methodvalidation.constraints.ConsistentDateParameters;
import org.springframework.validation.annotation.Validated;
import com.baeldung.javaxval.methodvalidation.constraints.ConsistentDateParameters;
import com.baeldung.javaxval.methodvalidation.constraints.ValidReservation;
@Validated
public class Reservation {

View File

@ -9,12 +9,13 @@ import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import com.baeldung.javaxval.methodvalidation.constraints.ConsistentDateParameters;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import com.baeldung.javaxval.methodvalidation.constraints.ConsistentDateParameters;
@Controller
@Validated
public class ReservationManagement {

View File

@ -1,10 +1,10 @@
package com.baeldung.javaxval.notnull;
import javax.validation.constraints.NotNull;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;
import javax.validation.constraints.NotNull;
@Component
@Validated
public class ValidatingComponent {

View File

@ -5,9 +5,6 @@ import java.util.List;
import javax.validation.ConstraintViolationException;
import com.baeldung.javaxval.methodvalidation.model.Customer;
import com.baeldung.javaxval.methodvalidation.model.Reservation;
import com.baeldung.javaxval.methodvalidation.model.ReservationManagement;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
@ -17,6 +14,10 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.support.AnnotationConfigContextLoader;
import com.baeldung.javaxval.methodvalidation.model.Customer;
import com.baeldung.javaxval.methodvalidation.model.Reservation;
import com.baeldung.javaxval.methodvalidation.model.ReservationManagement;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = { MethodValidationConfig.class }, loader = AnnotationConfigContextLoader.class)
public class ContainerValidationIntegrationTest {

View File

@ -13,11 +13,12 @@ import javax.validation.Validation;
import javax.validation.ValidatorFactory;
import javax.validation.executable.ExecutableValidator;
import org.junit.Before;
import org.junit.Test;
import com.baeldung.javaxval.methodvalidation.model.Customer;
import com.baeldung.javaxval.methodvalidation.model.Reservation;
import com.baeldung.javaxval.methodvalidation.model.ReservationManagement;
import org.junit.Before;
import org.junit.Test;
public class ValidationIntegrationTest {

View File

@ -1,9 +1,9 @@
package com.baeldung.javaxval.notnull;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertThrows;
import org.junit.jupiter.api.Test;
class NotNullMethodParameterUnitTest {
private NotNullMethodParameter demo = new NotNullMethodParameter();

View File

@ -1,19 +1,20 @@
package com.baeldung.javaxval.notnull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.Set;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.constraints.NotNull;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.constraints.NotNull;
import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows;
@SpringBootTest
class ValidatingComponentIntegrationTest {

View File

@ -5,12 +5,9 @@ This module contains articles about Bean Validation.
### Relevant Articles:
- [Java Bean Validation Basics](https://www.baeldung.com/javax-validation)
- [Validating Container Elements with Bean Validation 2.0](https://www.baeldung.com/bean-validation-container-elements)
- [Method Constraints with Bean Validation 2.0](https://www.baeldung.com/javax-validation-method-constraints)
- [Difference Between @NotNull, @NotEmpty, and @NotBlank Constraints in Bean Validation](https://www.baeldung.com/java-bean-validation-not-null-empty-blank)
- [Validations for Enum Types](https://www.baeldung.com/javax-validations-enums)
- [Javax BigDecimal Validation](https://www.baeldung.com/javax-bigdecimal-validation)
- [Grouping Javax Validation Constraints](https://www.baeldung.com/javax-validation-groups)
- [Validations for Enum Types](https://www.baeldung.com/javax-validations-enums)
- [Guide to ParameterMessageInterpolator](https://www.baeldung.com/hibernate-parametermessageinterpolator)
- [Hibernate Validator Annotation Processor in Depth](https://www.baeldung.com/hibernate-validator-annotation-processor)
- [Constraint Composition with Bean Validation](https://www.baeldung.com/java-bean-validation-constraint-composition)
- [Using @NotNull on a Method Parameter](https://www.baeldung.com/java-notnull-method-parameter)
- More articles: [[next -->]](../javaxval-2)

View File

@ -8,12 +8,13 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import com.baeldung.javaxval.enums.demo.CustomerUnitTest;
import com.baeldung.javaxval.enums.demo.Customer;
import com.baeldung.javaxval.enums.demo.CustomerType;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.javaxval.enums.demo.Customer;
import com.baeldung.javaxval.enums.demo.CustomerType;
import com.baeldung.javaxval.enums.demo.CustomerUnitTest;
public class CustomerTypeSubSetValidatorUnitTest {
private static Validator validator;

View File

@ -1,8 +1,8 @@
package com.baeldung.javaxval.enums;
import static org.assertj.core.api.Assertions.assertThat;
import static com.baeldung.javaxval.enums.demo.CustomerType.DEFAULT;
import static com.baeldung.javaxval.enums.demo.CustomerType.OLD;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Set;
@ -10,11 +10,12 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import com.baeldung.javaxval.enums.demo.CustomerUnitTest;
import com.baeldung.javaxval.enums.demo.Customer;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.javaxval.enums.demo.Customer;
import com.baeldung.javaxval.enums.demo.CustomerUnitTest;
public class EnumNamePatternValidatorUnitTest {
private static Validator validator;

View File

@ -8,11 +8,12 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import com.baeldung.javaxval.enums.demo.CustomerUnitTest;
import com.baeldung.javaxval.enums.demo.Customer;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.javaxval.enums.demo.Customer;
import com.baeldung.javaxval.enums.demo.CustomerUnitTest;
public class ValueOfEnumValidatorUnitTest {
private static Validator validator;

View File

@ -9,10 +9,11 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import com.baeldung.javaxval.LocaleAwareUnitTest;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.javaxval.LocaleAwareUnitTest;
public class CustomerUnitTest extends LocaleAwareUnitTest {
private static Validator validator;

View File

@ -1,4 +1,4 @@
package com.baeldung.javaxval.javabeanconstraints.test;
package com.baeldung.javaxval.javabeanconstraints;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -1,4 +1,4 @@
package com.baeldung.javaxval.javabeanconstraints.test;
package com.baeldung.javaxval.javabeanconstraints;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -1,4 +1,4 @@
package com.baeldung.javaxval.javabeanconstraints.test;
package com.baeldung.javaxval.javabeanconstraints;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -8,10 +8,11 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import com.baeldung.javaxval.LocaleAwareUnitTest;
import org.junit.BeforeClass;
import org.junit.Test;
import com.baeldung.javaxval.LocaleAwareUnitTest;
public class RegistrationFormUnitTest extends LocaleAwareUnitTest {
private static Validator validator;

View File

@ -414,6 +414,7 @@
<module>java-websocket</module>
<module>javax-sound</module>
<module>javaxval</module>
<module>javaxval-2</module>
<module>jaxb</module>
<module>jersey</module>
<module>jgit</module>
@ -818,6 +819,7 @@
<module>java-websocket</module>
<module>javax-sound</module>
<module>javaxval</module>
<module>javaxval-2</module>
<module>jaxb</module>
<module>jersey</module>
<module>jgit</module>