-
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.
Merge branch 'master' into minor_ui_improvements_august_2024
- Loading branch information
Showing
10 changed files
with
164 additions
and
31 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
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
22 changes: 22 additions & 0 deletions
22
hermes-api/src/main/java/pl/allegro/tech/hermes/api/constraints/OneSourceRetransmission.java
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,22 @@ | ||
package pl.allegro.tech.hermes.api.constraints; | ||
|
||
import jakarta.validation.Constraint; | ||
|
||
import java.lang.annotation.Documented; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
import static java.lang.annotation.ElementType.TYPE; | ||
|
||
@Documented | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({TYPE}) | ||
@Constraint(validatedBy = OneSourceRetransmissionValidator.class) | ||
public @interface OneSourceRetransmission { | ||
String message() default "must contain one defined source of retransmission data - source topic or source view"; | ||
|
||
Class[] groups() default {}; | ||
|
||
Class[] payload() default {}; | ||
} |
24 changes: 24 additions & 0 deletions
24
...rc/main/java/pl/allegro/tech/hermes/api/constraints/OneSourceRetransmissionValidator.java
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,24 @@ | ||
package pl.allegro.tech.hermes.api.constraints; | ||
|
||
import jakarta.validation.ConstraintValidator; | ||
import jakarta.validation.ConstraintValidatorContext; | ||
import pl.allegro.tech.hermes.api.OfflineRetransmissionRequest; | ||
|
||
public class OneSourceRetransmissionValidator implements ConstraintValidator<OneSourceRetransmission, OfflineRetransmissionRequest> { | ||
|
||
public static final String EMPTY_STRING = ""; | ||
|
||
@Override | ||
public boolean isValid(OfflineRetransmissionRequest offlineRetransmissionRequest, ConstraintValidatorContext context) { | ||
var sourceViewPath = offlineRetransmissionRequest.getSourceViewPath(); | ||
var sourceTopic = offlineRetransmissionRequest.getSourceTopic(); | ||
|
||
return (nonBlank(sourceViewPath.orElse(EMPTY_STRING)) && sourceTopic.isEmpty()) | ||
|| (nonBlank(sourceTopic.orElse(EMPTY_STRING)) && sourceViewPath.isEmpty()); | ||
} | ||
|
||
private static boolean nonBlank(String value) { | ||
return value != null && !value.isBlank(); | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
...groovy/pl/allegro/tech/hermes/api/constraints/OneSourceRetransmissionValidatorTest.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,37 @@ | ||
package pl.allegro.tech.hermes.api.constraints | ||
|
||
|
||
import jakarta.validation.ConstraintValidatorContext | ||
import pl.allegro.tech.hermes.api.OfflineRetransmissionRequest | ||
import spock.lang.Specification | ||
|
||
class OneSourceRetransmissionValidatorTest extends Specification { | ||
|
||
OneSourceRetransmissionValidator validator = new OneSourceRetransmissionValidator() | ||
ConstraintValidatorContext mockContext = Mock() | ||
|
||
def "Validator should validate retransmission request when sourceViewPath is '#sourceViewPath' and sourceTopic is '#sourceTopic'"() { | ||
given: | ||
def request = new OfflineRetransmissionRequest( | ||
sourceViewPath, | ||
sourceTopic, | ||
"someTargetTopic", | ||
"2024-07-08T12:00:00", | ||
"2024-07-08T13:00:00" | ||
) | ||
expect: | ||
validator.isValid(request, mockContext) == isValid | ||
|
||
where: | ||
sourceViewPath | sourceTopic | isValid | ||
null | "testTopic" | true | ||
"testView" | null | true | ||
null | null | false | ||
"testView" | "testTopic" | false | ||
"" | "" | false | ||
" " | " " | false | ||
"" | "testTopic" | false | ||
"testView" | " " | false | ||
} | ||
|
||
} |
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
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.