-
Notifications
You must be signed in to change notification settings - Fork 160
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Customizing Cloudevents validation
- Loading branch information
vbhat6
committed
Oct 5, 2023
1 parent
eaef3be
commit d2706e0
Showing
5 changed files
with
112 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
16 changes: 16 additions & 0 deletions
16
core/src/main/java/io/cloudevents/core/validator/CloudEventValidator.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,16 @@ | ||
package io.cloudevents.core.validator; | ||
|
||
import io.cloudevents.CloudEvent; | ||
|
||
/** | ||
* Interface which defines validation for CloudEvents attributes and extensions. | ||
*/ | ||
public interface CloudEventValidator { | ||
|
||
/** | ||
* Validate the attributes of a CloudEvent. | ||
* | ||
* @param cloudEvent the CloudEvent to validate | ||
*/ | ||
void validate(CloudEvent cloudEvent); | ||
} |
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
11 changes: 11 additions & 0 deletions
11
core/src/test/java/io/cloudevents/core/v1/CustomCloudEventValidator.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,11 @@ | ||
package io.cloudevents.core.v1; | ||
|
||
/** | ||
* Dummy validation class which does not implement CloudEventValidator class. | ||
*/ | ||
public class CustomCloudEventValidator { | ||
|
||
void validate(){ | ||
|
||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
core/src/test/java/io/cloudevents/core/v1/CustomCloudEventValidatorImpl.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,15 @@ | ||
package io.cloudevents.core.v1; | ||
|
||
import io.cloudevents.CloudEvent; | ||
import io.cloudevents.core.validator.CloudEventValidator; | ||
|
||
public class CustomCloudEventValidatorImpl implements CloudEventValidator { | ||
@Override | ||
public void validate(CloudEvent cloudEvent) { | ||
|
||
if (cloudEvent.getExtension("namespace") == null){ | ||
throw new IllegalStateException("Extension 'namespace' cannot be null"); | ||
} | ||
|
||
} | ||
} |