Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Minor: rename constant according to annotation name.
Browse files Browse the repository at this point in the history
  • Loading branch information
1u0 committed Feb 2, 2024
1 parent 4723a08 commit 02a9e44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class EventTypeAnnotationsValidator {
"(([1-9]|[1-9]\\d|[1][01]\\d|120)((\\smonths?)|(m)))|(([1-9]|(10))((\\syears?)|(y))))$");
static final String RETENTION_PERIOD_ANNOTATION = "datalake.zalando.org/retention-period";
static final String RETENTION_REASON_ANNOTATION = "datalake.zalando.org/retention-period-reason";
static final String MATERIALISE_EVENTS_ANNOTATION = "datalake.zalando.org/materialize-events";
static final String MATERIALIZE_EVENTS_ANNOTATION = "datalake.zalando.org/materialize-events";

private final FeatureToggleService featureToggleService;
private final AuthorizationService authorizationService;
Expand All @@ -46,21 +46,21 @@ public void validateAnnotations(final Map<String, String> annotations) throws In
}

private void validateDataLakeAnnotations(@NotNull final Map<String, String> annotations) {
final var materializeEvents = annotations.get(MATERIALISE_EVENTS_ANNOTATION);
final var materializeEvents = annotations.get(MATERIALIZE_EVENTS_ANNOTATION);
final var retentionPeriod = annotations.get(RETENTION_PERIOD_ANNOTATION);

if (materializeEvents != null) {
if (!materializeEvents.equals("off") && !materializeEvents.equals("on")) {
throw new InvalidEventTypeException(
"Annotation " + MATERIALISE_EVENTS_ANNOTATION
"Annotation " + MATERIALIZE_EVENTS_ANNOTATION
+ " is not valid. Provided value: \""
+ materializeEvents
+ "\". Possible values are: \"on\" or \"off\".");
}
if (materializeEvents.equals("on")) {
if (retentionPeriod == null) {
throw new InvalidEventTypeException("Annotation " + RETENTION_PERIOD_ANNOTATION
+ " is required, when " + MATERIALISE_EVENTS_ANNOTATION + " is \"on\".");
+ " is required, when " + MATERIALIZE_EVENTS_ANNOTATION + " is \"on\".");
}
}
}
Expand All @@ -84,7 +84,7 @@ private void validateDataLakeAnnotations(@NotNull final Map<String, String> anno

if (areDataLakeAnnotationsMandatory()) {
if (materializeEvents == null) {
throw new InvalidEventTypeException("Annotation " + MATERIALISE_EVENTS_ANNOTATION + " is required");
throw new InvalidEventTypeException("Annotation " + MATERIALIZE_EVENTS_ANNOTATION + " is required");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void setUp() {
@Test
public void whenMaterializationEventFormatIsWrongThenFail() {
final var annotations = Map.of(
EventTypeAnnotationsValidator.MATERIALISE_EVENTS_ANNOTATION, "1 day"
EventTypeAnnotationsValidator.MATERIALIZE_EVENTS_ANNOTATION, "1 day"
);
try {
validator.validateAnnotations(annotations);
Expand All @@ -43,7 +43,7 @@ public void whenMaterializationEventFormatIsWrongThenFail() {
Assert.assertTrue(
"When the format of the Materialize Event annotation is wrong, the name of the annotation " +
"should be present",
e.getMessage().contains(EventTypeAnnotationsValidator.MATERIALISE_EVENTS_ANNOTATION));
e.getMessage().contains(EventTypeAnnotationsValidator.MATERIALIZE_EVENTS_ANNOTATION));
}
}

Expand Down Expand Up @@ -114,11 +114,11 @@ public void whenRetentionPeriodAndReasonThenOk() {

@Test
public void whenMaterializationEventsThenOk() {
final String[] validMaterialisationEventsValues = {"off", "on"};
final String[] validMaterializationEventsValues = {"off", "on"};

for (final var materialisationEventValue : validMaterialisationEventsValues) {
for (final var materializationEventValue : validMaterializationEventsValues) {
final var annotations = Map.of(
EventTypeAnnotationsValidator.MATERIALISE_EVENTS_ANNOTATION, materialisationEventValue
EventTypeAnnotationsValidator.MATERIALIZE_EVENTS_ANNOTATION, materializationEventValue,
EventTypeAnnotationsValidator.RETENTION_PERIOD_ANNOTATION, "1m",
EventTypeAnnotationsValidator.RETENTION_REASON_ANNOTATION, "for testing"
);
Expand All @@ -137,15 +137,15 @@ public void whenDataLakeAnnotationsEnforcedThenMaterializationIsRequired() {
Assert.fail("not reachable");
} catch (InvalidEventTypeException e) {
Assert.assertTrue(
e.getMessage().contains(EventTypeAnnotationsValidator.MATERIALISE_EVENTS_ANNOTATION));
e.getMessage().contains(EventTypeAnnotationsValidator.MATERIALIZE_EVENTS_ANNOTATION));
}
}

@Test
public void whenMaterializationIsOnThenRetentionPeriodIsRequired() {
try {
validator.validateAnnotations(Collections.singletonMap(
EventTypeAnnotationsValidator.MATERIALISE_EVENTS_ANNOTATION, "on"));
EventTypeAnnotationsValidator.MATERIALIZE_EVENTS_ANNOTATION, "on"));
Assert.fail("not reachable");
} catch (InvalidEventTypeException e) {
Assert.assertTrue(
Expand Down

0 comments on commit 02a9e44

Please sign in to comment.