From ea6b839403a6575f45cb86fb489a8f44f8bcaded Mon Sep 17 00:00:00 2001 From: vbhat6 Date: Thu, 15 Feb 2024 11:09:01 +0530 Subject: [PATCH] feat: Customizing Cloudevents validation --- .../core/test/CloudEventCustomValidator.java | 17 +++++++++++++++++ ...oudevents.core.validator.CloudEventValidator | 1 + 2 files changed, 18 insertions(+) create mode 100644 core/src/test/java/io/cloudevents/core/test/CloudEventCustomValidator.java create mode 100644 core/src/test/resources/META-INF/services/io.cloudevents.core.validator.CloudEventValidator diff --git a/core/src/test/java/io/cloudevents/core/test/CloudEventCustomValidator.java b/core/src/test/java/io/cloudevents/core/test/CloudEventCustomValidator.java new file mode 100644 index 000000000..55fe0a024 --- /dev/null +++ b/core/src/test/java/io/cloudevents/core/test/CloudEventCustomValidator.java @@ -0,0 +1,17 @@ +package io.cloudevents.core.test; + +import io.cloudevents.CloudEvent; +import io.cloudevents.core.validator.CloudEventValidator; + +public class CloudEventCustomValidator implements CloudEventValidator { + + @Override + public void validate(CloudEvent cloudEvent) { + String namespace = null; + if ((namespace = (String) cloudEvent.getExtension("namespace")) != null && + !namespace.equals("sales")){ + throw new IllegalStateException("Expecting sales in namespace extension"); + } + } + +} diff --git a/core/src/test/resources/META-INF/services/io.cloudevents.core.validator.CloudEventValidator b/core/src/test/resources/META-INF/services/io.cloudevents.core.validator.CloudEventValidator new file mode 100644 index 000000000..c265df28c --- /dev/null +++ b/core/src/test/resources/META-INF/services/io.cloudevents.core.validator.CloudEventValidator @@ -0,0 +1 @@ +io.cloudevents.core.test.CloudEventCustomValidator