From 1730f704173b55981b012654bfb2cd4c194d15f7 Mon Sep 17 00:00:00 2001 From: Matej Novotny Date: Fri, 25 Oct 2024 10:06:57 +0200 Subject: [PATCH] Quartz - add validation tests for custom JDBC delegate --- .../DelegateNotASubclassTest.java | 53 +++++++++++++++++++ .../DelegateNotIndexedTest.java | 53 +++++++++++++++++++ .../test/customDelegate/InvalidDelegate.java | 5 ++ 3 files changed, 111 insertions(+) create mode 100644 extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotASubclassTest.java create mode 100644 extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotIndexedTest.java create mode 100644 extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/InvalidDelegate.java diff --git a/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotASubclassTest.java b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotASubclassTest.java new file mode 100644 index 0000000000000..b6200573a038c --- /dev/null +++ b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotASubclassTest.java @@ -0,0 +1,53 @@ +package io.quarkus.quartz.test.customDelegate; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.function.Consumer; + +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.builder.BuildChainBuilder; +import io.quarkus.builder.BuildContext; +import io.quarkus.builder.BuildStep; +import io.quarkus.deployment.Capability; +import io.quarkus.deployment.builditem.CapabilityBuildItem; +import io.quarkus.quartz.test.SimpleJobs; +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class DelegateNotASubclassTest { + + @RegisterExtension + static final QuarkusUnitTest test = new QuarkusUnitTest() + // add a mock pretending to provide Agroal Capability to pass our validation + .addBuildChainCustomizer(new Consumer<>() { + @Override + public void accept(BuildChainBuilder buildChainBuilder) { + buildChainBuilder.addBuildStep(new BuildStep() { + @Override + public void execute(BuildContext context) { + context.produce( + new CapabilityBuildItem(Capability.AGROAL, "fakeProvider")); + } + }).produces(CapabilityBuildItem.class).build(); + } + }) + .assertException(t -> { + assertEquals(ConfigurationException.class, t.getClass()); + Assertions.assertTrue(t.getMessage().contains( + "Custom JDBC delegate implementation with name 'io.quarkus.quartz.test.customDelegate.InvalidDelegate' needs to be a subclass")); + }) + .withApplicationRoot((jar) -> jar + .addClasses(SimpleJobs.class, InvalidDelegate.class) + .addAsResource(new StringAsset( + "quarkus.quartz.driver-delegate=io.quarkus.quartz.test.customDelegate.InvalidDelegate\nquarkus.quartz.store-type=jdbc-cmt"), + "application.properties")); + + @Test + public void shouldFailIfNotASubclass() { + Assertions.fail(); + } +} diff --git a/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotIndexedTest.java b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotIndexedTest.java new file mode 100644 index 0000000000000..248f1584ade99 --- /dev/null +++ b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/DelegateNotIndexedTest.java @@ -0,0 +1,53 @@ +package io.quarkus.quartz.test.customDelegate; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.function.Consumer; + +import org.jboss.shrinkwrap.api.asset.StringAsset; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.quarkus.builder.BuildChainBuilder; +import io.quarkus.builder.BuildContext; +import io.quarkus.builder.BuildStep; +import io.quarkus.deployment.Capability; +import io.quarkus.deployment.builditem.CapabilityBuildItem; +import io.quarkus.quartz.test.SimpleJobs; +import io.quarkus.runtime.configuration.ConfigurationException; +import io.quarkus.test.QuarkusUnitTest; + +public class DelegateNotIndexedTest { + + @RegisterExtension + static final QuarkusUnitTest test = new QuarkusUnitTest() + // add a mock pretending to provide Agroal Capability to pass our validation + .addBuildChainCustomizer(new Consumer<>() { + @Override + public void accept(BuildChainBuilder buildChainBuilder) { + buildChainBuilder.addBuildStep(new BuildStep() { + @Override + public void execute(BuildContext context) { + context.produce( + new CapabilityBuildItem(Capability.AGROAL, "fakeProvider")); + } + }).produces(CapabilityBuildItem.class).build(); + } + }) + .assertException(t -> { + assertEquals(ConfigurationException.class, t.getClass()); + Assertions.assertTrue(t.getMessage().contains( + "Custom JDBC delegate implementation class 'org.acme.DoesNotExist' was not found in Jandex index")); + }) + .withApplicationRoot((jar) -> jar + .addClasses(SimpleJobs.class) + .addAsResource(new StringAsset( + "quarkus.quartz.driver-delegate=org.acme.DoesNotExist\nquarkus.quartz.store-type=jdbc-cmt"), + "application.properties")); + + @Test + public void shouldFailWhenNotIndexed() { + Assertions.fail(); + } +} diff --git a/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/InvalidDelegate.java b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/InvalidDelegate.java new file mode 100644 index 0000000000000..a337418403997 --- /dev/null +++ b/extensions/quartz/deployment/src/test/java/io/quarkus/quartz/test/customDelegate/InvalidDelegate.java @@ -0,0 +1,5 @@ +package io.quarkus.quartz.test.customDelegate; + +// dummy class representing an invalid JDBC delegate by not subclassing a known one +public class InvalidDelegate { +}