Skip to content
Advertisement

Tag: validation

How to properly validate PNG header in java?

I’m trying to write a function which will check if PNG file is not corrupted. Here I found a function, also provided below, which stores file bytes into its own byte array. I know that the first eight bytes of a PNG file always contain the same decimal values 137 80 78 71 13 10 26 10 (hex: 89 50

How to raise a ConstraintValidationException in a test case for bean properties with validation annotations?

I’m trying to test that my beans have correct validation annotations. I’m using spring-boot. Here is an example test case: I expect the call to checkIfvalidated() and to setSomeProperty(null) to raise a ConstraintViolationException, and the tests to pass, but they both fail with: My pom.xml: Why is there no ConstraintViolationException raised here? The bean property has a @NotNull annotation, the

Where should I check if username already exist in rest api?

I am creating a rest application using Spring Boot. I’ve got three logical layers: controller, service, and repository. Where should I check if the given username and similar values already exist in the database? In the controller layer, I check user input (length, size, etc.) Can I also check username existence here? For instance: Can I check it in the

hibernate validator throws exception ValidationException: HV000028 for @Past annotation

I am validating an entity with a hibernate validator in a spring boot project. I got an exception for the Date validator @Past . I faced javax.validation.ValidationException: HV000028: Unexpected exception during isValid call This is the dependency I have in my gradle.build file implementation ‘org.springframework.boot:spring-boot-starter-validation’ The following my a similar entity I have This is a log trace Answer This

Why is @Validated required for validating Spring controller request parameters?

With the following validation setup in an annotated MVC controller: @Validated on the controller is required for the method parameter since it’s not a “complex” object. In comparison, the @Valid annotation on the setOther method works without the @Validated annotation. Why is @Validated required? Why not enable it by default? Is there a cost to its use? edit Note that

Spring unit test issue with Validator

I am trying to write unit test for a validator class that I have. So within my UniqueEmailValidator class, I injected a @Service component to check if it exist. And I tried to write unit test for this constraint validator. How do I initialize the AccountService within the Validator class? It seem like it wasn’t injected, hence, the null exception.

Advertisement