-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1905 | Added missing unit test for topic constraints validations.
- Loading branch information
1 parent
6b80eb5
commit 3f503fb
Showing
2 changed files
with
72 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
hermes-api/src/test/groovy/pl/allegro/tech/hermes/api/TopicConstraintsValidationTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package pl.allegro.tech.hermes.api | ||
|
||
import jakarta.validation.Validation | ||
import jakarta.validation.Validator | ||
import org.hibernate.validator.internal.engine.ConstraintViolationImpl | ||
import spock.lang.Specification | ||
|
||
class TopicConstraintsValidationTest extends Specification { | ||
private final Validator validator = Validation.buildDefaultValidatorFactory().getValidator() | ||
|
||
def "consumers number has to be greater than zero"() { | ||
given: | ||
def topicConstraints = new TopicConstraints( | ||
"group.topic", | ||
new Constraints(consumersNumber, "Some reason") | ||
) | ||
|
||
when: | ||
Set<ConstraintViolationImpl<TopicConstraints>> violations = validator.validate(topicConstraints) | ||
|
||
then: | ||
violations.propertyPath*.toString() == ["constraints.consumersNumber"] | ||
violations*.interpolatedMessage == ["must be greater than or equal to 1"] | ||
|
||
where: | ||
consumersNumber << [-100, -1, 0] | ||
} | ||
|
||
def "reason message length has to be max 1024"() { | ||
given: | ||
def topicConstraints = new TopicConstraints( | ||
"group.topic", | ||
new Constraints(1, reason) | ||
) | ||
|
||
when: | ||
Set<ConstraintViolationImpl<TopicConstraints>> violations = validator.validate(topicConstraints) | ||
|
||
then: | ||
violations.propertyPath*.toString() == ["constraints.reason"] | ||
violations*.interpolatedMessage == ["size must be between 0 and 1024"] | ||
|
||
where: | ||
reason << [ | ||
"r".repeat(1025), | ||
"r".repeat(2048), | ||
"r".repeat(10000) | ||
] | ||
} | ||
|
||
def "there shouldn't be any violations for valid inputs"() { | ||
given: | ||
def TopicConstraints = new TopicConstraints( | ||
"group.topic\$subscription", | ||
new Constraints(consumersNumber, reason) | ||
) | ||
|
||
when: | ||
Set<ConstraintViolationImpl<TopicConstraints>> violations = validator.validate(TopicConstraints) | ||
|
||
then: | ||
violations.isEmpty() | ||
|
||
where: | ||
consumersNumber | reason | ||
1 | "r".repeat(1023) | ||
10 | "" | ||
100 | null | ||
100 | "r" | ||
} | ||
} |