-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* 1905 | Added reason field to subscription and topic constratints on backend. * 1905 | Added reason field to subscription and topic constratints on frontend. * 1905 | Added missing unit test for topic constraints validations. --------- Co-authored-by: Mateusz <76775507+szczygiel-m@users.noreply.github.com>
- Loading branch information
1 parent
0952046
commit 762d389
Showing
17 changed files
with
348 additions
and
116 deletions.
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
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
...i/src/test/groovy/pl/allegro/tech/hermes/api/SubscriptionConstraintsValidationTest.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 SubscriptionConstraintsValidationTest extends Specification { | ||
private final Validator validator = Validation.buildDefaultValidatorFactory().getValidator() | ||
|
||
def "consumers number has to be greater than zero"() { | ||
given: | ||
def subscriptionConstraints = new SubscriptionConstraints( | ||
"group.topic\$subscription", | ||
new Constraints(consumersNumber, "Some reason") | ||
) | ||
|
||
when: | ||
Set<ConstraintViolationImpl<SubscriptionConstraints>> violations = validator.validate(subscriptionConstraints) | ||
|
||
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 subscriptionConstraints = new SubscriptionConstraints( | ||
"group.topic\$subscription", | ||
new Constraints(1, reason) | ||
) | ||
|
||
when: | ||
Set<ConstraintViolationImpl<SubscriptionConstraints>> violations = validator.validate(subscriptionConstraints) | ||
|
||
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 subscriptionConstraints = new SubscriptionConstraints( | ||
"group.topic\$subscription", | ||
new Constraints(consumersNumber, reason) | ||
) | ||
|
||
when: | ||
Set<ConstraintViolationImpl<SubscriptionConstraints>> violations = validator.validate(subscriptionConstraints) | ||
|
||
then: | ||
violations.isEmpty() | ||
|
||
where: | ||
consumersNumber | reason | ||
1 | "r".repeat(1023) | ||
10 | "" | ||
100 | null | ||
100 | "r" | ||
} | ||
} |
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", | ||
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" | ||
} | ||
} |
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
Oops, something went wrong.