Skip to content

Commit

Permalink
Quartz - add validation tests for custom JDBC delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
manovotn committed Oct 25, 2024
1 parent 29c5bfb commit 1730f70
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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 {
}

0 comments on commit 1730f70

Please sign in to comment.