This is an automated email from the ASF dual-hosted git repository.
jstastnycz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-apps.git
The following commit(s) were added to refs/heads/main by this push:
new 05c188101 [incubator-kie-issues#2256] Fix Quarkus Job Exception
Details Extractor injection (#2303)
05c188101 is described below
commit 05c188101553944c25ab1a77bbb7b6f172c88f87
Author: Jan Stastny <[email protected]>
AuthorDate: Fri Feb 20 09:59:46 2026 +0100
[incubator-kie-issues#2256] Fix Quarkus Job Exception Details Extractor
injection (#2303)
Co-authored-by: jstastny-cz <[email protected]>
---
...ingConditionalJobExceptionDetailsExtractor.java | 5 +-
...onalJobExceptionDetailsExtractorCustomTest.java | 84 +++++++++++++++++++++
...alJobExceptionDetailsExtractorDisabledTest.java | 85 ++++++++++++++++++++++
...onditionalJobExceptionDetailsExtractorTest.java | 50 +++++++++++++
...onalJobExceptionDetailsExtractorCustomTest.java | 74 +++++++++++++++++++
...alJobExceptionDetailsExtractorDisabledTest.java | 72 ++++++++++++++++++
...onditionalJobExceptionDetailsExtractorTest.java | 51 +++++++++++++
7 files changed, 418 insertions(+), 3 deletions(-)
diff --git
a/jobs/kogito-addons-quarkus-embedded-jobs/src/main/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractor.java
b/jobs/kogito-addons-quarkus-embedded-jobs/src/main/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractor.java
index 67153958d..de42d7291 100644
---
a/jobs/kogito-addons-quarkus-embedded-jobs/src/main/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractor.java
+++
b/jobs/kogito-addons-quarkus-embedded-jobs/src/main/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractor.java
@@ -23,10 +23,9 @@ import
org.kie.kogito.app.jobs.integrations.DefaultJobExceptionDetailsExtractor;
import org.kie.kogito.app.jobs.integrations.JobExceptionDetailsExtractor;
import org.kie.kogito.jobs.service.model.JobExecutionExceptionDetails;
-import io.quarkus.arc.All;
-
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Any;
import jakarta.enterprise.inject.Instance;
import jakarta.inject.Inject;
@@ -62,7 +61,7 @@ public class WrappingConditionalJobExceptionDetailsExtractor
implements JobExcep
Boolean exceptionDetailsEnabled;
@Inject
- @All // Injects all other implementations
+ @Any // Injects all other implementations
Instance<JobExceptionDetailsExtractor> allExtractors;
private JobExceptionDetailsExtractor delegate;
diff --git
a/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorCustomTest.java
b/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorCustomTest.java
new file mode 100644
index 000000000..4a5e609cf
--- /dev/null
+++
b/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorCustomTest.java
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.app.jobs.quarkus;
+
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.app.jobs.integrations.JobExceptionDetailsExtractor;
+import org.kie.kogito.jobs.service.model.JobExecutionExceptionDetails;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Alternative;
+import jakarta.inject.Inject;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test class for verifying WrappingConditionalJobExceptionDetailsExtractor
correctly delegates
+ * to CUSTOM implementations when provided.
+ */
+@QuarkusTest
+@TestProfile(WrappingConditionalJobExceptionDetailsExtractorCustomTest.CustomExtractorProfile.class)
+public class WrappingConditionalJobExceptionDetailsExtractorCustomTest {
+
+ @Inject
+ WrappingConditionalJobExceptionDetailsExtractor extractor;
+
+ /**
+ * Custom test extractor that returns marker values.
+ * Uses @Alternative so it's only active when enabled by the test profile.
+ */
+ @Alternative
+ @ApplicationScoped
+ public static class CustomTestExtractor implements
JobExceptionDetailsExtractor {
+ @Override
+ public JobExecutionExceptionDetails extractExceptionDetails(Exception
e) {
+ if (e == null) {
+ return null;
+ }
+ return new JobExecutionExceptionDetails("CUSTOM_EXTRACTOR",
"Custom implementation was used");
+ }
+ }
+
+ /**
+ * Test profile that enables the custom extractor alternative
+ */
+ public static class CustomExtractorProfile implements QuarkusTestProfile {
+ @Override
+ public Set<Class<?>> getEnabledAlternatives() {
+ return Set.of(CustomTestExtractor.class);
+ }
+ }
+
+ @Test
+ public void testCustomExtractorIsUsedWhenProvided() {
+ Exception testException = new RuntimeException("Test exception
message");
+
+ JobExecutionExceptionDetails result =
extractor.extractExceptionDetails(testException);
+
+ assertThat(result).isNotNull();
+ assertThat(result.exceptionMessage()).isEqualTo("CUSTOM_EXTRACTOR");
+ assertThat(result.exceptionDetails()).isEqualTo("Custom implementation
was used");
+ }
+}
diff --git
a/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorDisabledTest.java
b/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorDisabledTest.java
new file mode 100644
index 000000000..2589b689a
--- /dev/null
+++
b/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorDisabledTest.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.app.jobs.quarkus;
+
+import java.util.Map;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.app.jobs.integrations.JobExceptionDetailsExtractor;
+import org.kie.kogito.jobs.service.model.JobExecutionExceptionDetails;
+
+import io.quarkus.test.junit.QuarkusTest;
+import io.quarkus.test.junit.QuarkusTestProfile;
+import io.quarkus.test.junit.TestProfile;
+
+import jakarta.enterprise.context.ApplicationScoped;
+import jakarta.enterprise.inject.Alternative;
+import jakarta.inject.Inject;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test class for verifying WrappingConditionalJobExceptionDetailsExtractor
respects
+ * the kogito.jobs-service.exception-details-enabled property.
+ */
+@QuarkusTest
+@TestProfile(WrappingConditionalJobExceptionDetailsExtractorDisabledTest.DisabledProfile.class)
+public class WrappingConditionalJobExceptionDetailsExtractorDisabledTest {
+
+ @Inject
+ WrappingConditionalJobExceptionDetailsExtractor extractor;
+
+ /**
+ * Custom test extractor that would return details if called.
+ * This should NOT be used when the feature is disabled.
+ */
+ @Alternative
+ @ApplicationScoped
+ public static class CustomTestExtractor implements
JobExceptionDetailsExtractor {
+ @Override
+ public JobExecutionExceptionDetails extractExceptionDetails(Exception
e) {
+ return new JobExecutionExceptionDetails("SHOULD_NOT_BE_USED",
"This should not be returned");
+ }
+ }
+
+ /**
+ * Test profile that DISABLES exception details and provides a custom
extractor
+ */
+ public static class DisabledProfile implements QuarkusTestProfile {
+ @Override
+ public Map<String, String> getConfigOverrides() {
+ return Map.of("kogito.jobs-service.exception-details-enabled",
"false");
+ }
+
+ @Override
+ public Set<Class<?>> getEnabledAlternatives() {
+ return Set.of(CustomTestExtractor.class);
+ }
+ }
+
+ @Test
+ public void testCustomExtractorNotUsedWhenDisabled() {
+ Exception testException = new RuntimeException("Test exception");
+
+ JobExecutionExceptionDetails result =
extractor.extractExceptionDetails(testException);
+
+ assertThat(result).isNull();
+ }
+}
diff --git
a/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorTest.java
b/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorTest.java
new file mode 100644
index 000000000..99d4718b3
--- /dev/null
+++
b/jobs/kogito-addons-quarkus-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/quarkus/WrappingConditionalJobExceptionDetailsExtractorTest.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.app.jobs.quarkus;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.jobs.service.model.JobExecutionExceptionDetails;
+
+import io.quarkus.test.junit.QuarkusTest;
+
+import jakarta.inject.Inject;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test class for verifying WrappingConditionalJobExceptionDetailsExtractor
correctly delegates
+ * to the default implementation.
+ */
+@QuarkusTest
+public class WrappingConditionalJobExceptionDetailsExtractorTest {
+
+ @Inject
+ WrappingConditionalJobExceptionDetailsExtractor extractor;
+
+ @Test
+ public void testDefaultExtractorIsUsedWhenEnabled() {
+ Exception testException = new RuntimeException("Test exception
message");
+
+ JobExecutionExceptionDetails result =
extractor.extractExceptionDetails(testException);
+
+ assertThat(result).isNotNull();
+
assertThat(result.exceptionMessage()).isEqualTo("java.lang.RuntimeException");
+ assertThat(result.exceptionDetails()).isEqualTo("Test exception
message");
+ }
+}
diff --git
a/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorCustomTest.java
b/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorCustomTest.java
new file mode 100644
index 000000000..5c211c5fc
--- /dev/null
+++
b/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorCustomTest.java
@@ -0,0 +1,74 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.app.jobs.springboot;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.app.jobs.integrations.JobExceptionDetailsExtractor;
+import org.kie.kogito.jobs.service.model.JobExecutionExceptionDetails;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test class for verifying WrappingConditionalJobExceptionDetailsExtractor
correctly delegates
+ * to CUSTOM implementations when provided.
+ */
+@SpringBootTest(classes = {
WrappingConditionalJobExceptionDetailsExtractorCustomTest.TestConfiguration.class,
+ WrappingConditionalJobExceptionDetailsExtractor.class })
+@DirtiesContext
+public class WrappingConditionalJobExceptionDetailsExtractorCustomTest {
+
+ @Autowired
+ WrappingConditionalJobExceptionDetailsExtractor extractor;
+
+ /**
+ * Test configuration that provides a custom extractor bean.
+ * This bean is only active for this test class.
+ */
+ @Configuration
+ public static class TestConfiguration {
+ @Bean(name = "customTestExtractorForCustomTest")
+ public JobExceptionDetailsExtractor customTestExtractor() {
+ return new JobExceptionDetailsExtractor() {
+ @Override
+ public JobExecutionExceptionDetails
extractExceptionDetails(Exception e) {
+ if (e == null) {
+ return null;
+ }
+ return new
JobExecutionExceptionDetails("CUSTOM_EXTRACTOR", "Custom implementation was
used");
+ }
+ };
+ }
+ }
+
+ @Test
+ public void testCustomExtractorIsUsedWhenProvided() {
+ Exception testException = new RuntimeException("Test exception
message");
+
+ JobExecutionExceptionDetails result =
extractor.extractExceptionDetails(testException);
+
+ assertThat(result).isNotNull();
+ assertThat(result.exceptionMessage()).isEqualTo("CUSTOM_EXTRACTOR");
+ assertThat(result.exceptionDetails()).isEqualTo("Custom implementation
was used");
+ }
+}
diff --git
a/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorDisabledTest.java
b/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorDisabledTest.java
new file mode 100644
index 000000000..f45bc0575
--- /dev/null
+++
b/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorDisabledTest.java
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.app.jobs.springboot;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.app.jobs.integrations.JobExceptionDetailsExtractor;
+import org.kie.kogito.jobs.service.model.JobExecutionExceptionDetails;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.TestPropertySource;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test class for verifying WrappingConditionalJobExceptionDetailsExtractor
respects
+ * the kogito.jobs-service.exception-details-enabled property.
+ */
+@SpringBootTest(classes = {
+
WrappingConditionalJobExceptionDetailsExtractorDisabledTest.TestConfiguration.class,
+ WrappingConditionalJobExceptionDetailsExtractor.class })
+@TestPropertySource(properties =
"kogito.jobs-service.exception-details-enabled=false")
+@DirtiesContext
+public class WrappingConditionalJobExceptionDetailsExtractorDisabledTest {
+
+ @Autowired
+ private WrappingConditionalJobExceptionDetailsExtractor extractor;
+
+ /**
+ * Test configuration that provides a custom extractor.
+ * This extractor should NOT be used when the feature is disabled.
+ */
+ @Configuration
+ static class TestConfiguration {
+ @Bean(name = "customTestExtractorForDisabledTest")
+ public JobExceptionDetailsExtractor customTestExtractor() {
+ return new JobExceptionDetailsExtractor() {
+ @Override
+ public JobExecutionExceptionDetails
extractExceptionDetails(Exception e) {
+ return new
JobExecutionExceptionDetails("SHOULD_NOT_BE_USED", "This should not be
returned");
+ }
+ };
+ }
+ }
+
+ @Test
+ public void testCustomExtractorNotUsedWhenDisabled() {
+ Exception testException = new RuntimeException("Test exception");
+
+ JobExecutionExceptionDetails result =
extractor.extractExceptionDetails(testException);
+
+ assertThat(result).isNull();
+ }
+}
diff --git
a/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorTest.java
b/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorTest.java
new file mode 100644
index 000000000..c525018ab
--- /dev/null
+++
b/jobs/kogito-addons-springboot-embedded-jobs/src/test/java/org/kie/kogito/app/jobs/springboot/WrappingConditionalJobExceptionDetailsExtractorTest.java
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.kogito.app.jobs.springboot;
+
+import org.junit.jupiter.api.Test;
+import org.kie.kogito.jobs.service.model.JobExecutionExceptionDetails;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Test class for verifying WrappingConditionalJobExceptionDetailsExtractor
correctly delegates
+ * to the default implementation.
+ */
+@SpringBootTest(classes = {
+ WrappingConditionalJobExceptionDetailsExtractor.class })
+@DirtiesContext
+public class WrappingConditionalJobExceptionDetailsExtractorTest {
+
+ @Autowired
+ WrappingConditionalJobExceptionDetailsExtractor extractor;
+
+ @Test
+ public void testDefaultExtractorIsUsedWhenEnabled() {
+ Exception testException = new RuntimeException("Test exception
message");
+
+ JobExecutionExceptionDetails result =
extractor.extractExceptionDetails(testException);
+
+ assertThat(result).isNotNull();
+
assertThat(result.exceptionMessage()).isEqualTo("java.lang.RuntimeException");
+ assertThat(result.exceptionDetails()).isEqualTo("Test exception
message");
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]