From de0ed34b1a289cffddf8b97adcde1decb91e9313 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Thu, 10 Oct 2024 09:51:09 -0600 Subject: [PATCH] #29480 --- .../test/java/com/dotcms/Junit5Suite1.java | 4 +- .../dotcms/TestBaseJunit5WeldInitiator.java | 47 +++++++++++++++++++ .../api/JobQueueManagerAPICDITest.java | 25 +--------- .../v1/job/JobQueueHelperIntegrationTest.java | 17 ++----- .../util/IntegrationTestInitService.java | 6 ++- 5 files changed, 62 insertions(+), 37 deletions(-) create mode 100644 dotcms-integration/src/test/java/com/dotcms/TestBaseJunit5WeldInitiator.java diff --git a/dotcms-integration/src/test/java/com/dotcms/Junit5Suite1.java b/dotcms-integration/src/test/java/com/dotcms/Junit5Suite1.java index ff80711f56d4..a0003e96d56d 100644 --- a/dotcms-integration/src/test/java/com/dotcms/Junit5Suite1.java +++ b/dotcms-integration/src/test/java/com/dotcms/Junit5Suite1.java @@ -3,6 +3,7 @@ import com.dotcms.jobs.business.api.JobQueueManagerAPICDITest; import com.dotcms.jobs.business.api.JobQueueManagerAPIIntegrationTest; import com.dotcms.jobs.business.queue.PostgresJobQueueIntegrationTest; +import com.dotcms.rest.api.v1.job.JobQueueHelperIntegrationTest; import org.junit.platform.suite.api.SelectClasses; import org.junit.platform.suite.api.Suite; @@ -10,7 +11,8 @@ @SelectClasses({ JobQueueManagerAPICDITest.class, PostgresJobQueueIntegrationTest.class, - JobQueueManagerAPIIntegrationTest.class + JobQueueManagerAPIIntegrationTest.class, + JobQueueHelperIntegrationTest.class }) public class Junit5Suite1 { diff --git a/dotcms-integration/src/test/java/com/dotcms/TestBaseJunit5WeldInitiator.java b/dotcms-integration/src/test/java/com/dotcms/TestBaseJunit5WeldInitiator.java new file mode 100644 index 000000000000..b65843c090dc --- /dev/null +++ b/dotcms-integration/src/test/java/com/dotcms/TestBaseJunit5WeldInitiator.java @@ -0,0 +1,47 @@ +package com.dotcms; + +import com.dotcms.jobs.business.api.JobProcessorFactory; +import com.dotcms.jobs.business.api.JobProcessorScanner; +import com.dotcms.jobs.business.api.JobQueueConfig; +import com.dotcms.jobs.business.api.JobQueueConfigProducer; +import com.dotcms.jobs.business.api.JobQueueManagerAPIImpl; +import com.dotcms.jobs.business.api.events.EventProducer; +import com.dotcms.jobs.business.api.events.RealTimeJobMonitor; +import com.dotcms.jobs.business.error.CircuitBreaker; +import com.dotcms.jobs.business.error.RetryStrategy; +import com.dotcms.jobs.business.error.RetryStrategyProducer; +import com.dotcms.jobs.business.queue.JobQueue; +import com.dotcms.jobs.business.queue.JobQueueProducer; +import com.dotcms.rest.api.v1.job.JobQueueHelper; +import org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider; +import org.jboss.weld.junit5.WeldInitiator; +import org.jboss.weld.junit5.WeldJunit5Extension; +import org.jboss.weld.junit5.WeldSetup; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.extension.ExtendWith; + +@ExtendWith(WeldJunit5Extension.class) +public class TestBaseJunit5WeldInitiator { + + @WeldSetup + public static WeldInitiator weld = WeldInitiator.of( + WeldInitiator.createWeld() + .containerId(RegistrySingletonProvider.STATIC_INSTANCE) + .beanClasses(JobQueueManagerAPIImpl.class, JobQueueConfig.class, + JobQueue.class, RetryStrategy.class, CircuitBreaker.class, + JobQueueProducer.class, JobQueueConfigProducer.class, + RetryStrategyProducer.class, RealTimeJobMonitor.class, + EventProducer.class, JobProcessorFactory.class, JobQueueHelper.class, + JobProcessorScanner.class + ) + ); + + @AfterAll + public static void tearDown() { + if (weld != null && weld.isRunning()) { + weld.shutdown(); + weld = null; + } + } + +} diff --git a/dotcms-integration/src/test/java/com/dotcms/jobs/business/api/JobQueueManagerAPICDITest.java b/dotcms-integration/src/test/java/com/dotcms/jobs/business/api/JobQueueManagerAPICDITest.java index 1fc6fdd14a6d..d4e6d85c2865 100644 --- a/dotcms-integration/src/test/java/com/dotcms/jobs/business/api/JobQueueManagerAPICDITest.java +++ b/dotcms-integration/src/test/java/com/dotcms/jobs/business/api/JobQueueManagerAPICDITest.java @@ -5,39 +5,18 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; -import com.dotcms.jobs.business.api.events.EventProducer; -import com.dotcms.jobs.business.api.events.RealTimeJobMonitor; -import com.dotcms.jobs.business.error.CircuitBreaker; +import com.dotcms.TestBaseJunit5WeldInitiator; import com.dotcms.jobs.business.error.ExponentialBackoffRetryStrategy; -import com.dotcms.jobs.business.error.RetryStrategy; -import com.dotcms.jobs.business.error.RetryStrategyProducer; import com.dotcms.jobs.business.queue.JobQueue; -import com.dotcms.jobs.business.queue.JobQueueProducer; import javax.inject.Inject; -import org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider; -import org.jboss.weld.junit5.WeldInitiator; -import org.jboss.weld.junit5.WeldJunit5Extension; -import org.jboss.weld.junit5.WeldSetup; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; /** * Test class for verifying the CDI (Contexts and Dependency Injection) functionality of the * JobQueueManagerAPI implementation. */ -@ExtendWith(WeldJunit5Extension.class) -public class JobQueueManagerAPICDITest { - @WeldSetup - public WeldInitiator weld = WeldInitiator.of( - WeldInitiator.createWeld() - .containerId(RegistrySingletonProvider.STATIC_INSTANCE) - .beanClasses(JobQueueManagerAPIImpl.class, JobQueueConfig.class, - JobQueue.class, RetryStrategy.class, CircuitBreaker.class, - JobQueueProducer.class, JobQueueConfigProducer.class, - RetryStrategyProducer.class, RealTimeJobMonitor.class, - EventProducer.class, JobProcessorFactory.class) - ); +public class JobQueueManagerAPICDITest extends TestBaseJunit5WeldInitiator { @Inject private JobQueueManagerAPI jobQueueManagerAPI; diff --git a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/job/JobQueueHelperIntegrationTest.java b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/job/JobQueueHelperIntegrationTest.java index ea9ecdefc96f..566363fc2ab3 100644 --- a/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/job/JobQueueHelperIntegrationTest.java +++ b/dotcms-integration/src/test/java/com/dotcms/rest/api/v1/job/JobQueueHelperIntegrationTest.java @@ -5,10 +5,9 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.dotcms.cdi.CDIUtils; +import com.dotcms.TestBaseJunit5WeldInitiator; import com.dotcms.jobs.business.job.Job; import com.dotcms.jobs.business.processor.JobProcessor; -import com.dotcms.util.IntegrationTestInitService; import com.dotmarketing.exception.DoesNotExistException; import com.dotmarketing.exception.DotDataException; import com.fasterxml.jackson.core.JsonProcessingException; @@ -19,11 +18,11 @@ import java.io.IOException; import java.util.HashMap; import java.util.Map; +import javax.inject.Inject; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.glassfish.jersey.media.multipart.FormDataContentDisposition; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** @@ -31,16 +30,10 @@ * Helper add functionality to consume JobQueueManagerAPI * Here we test those functionalities, methods that simply call the JobQueueManagerAPI are not tested */ -public class JobQueueHelperIntegrationTest { +public class JobQueueHelperIntegrationTest extends TestBaseJunit5WeldInitiator { - static JobQueueHelper jobQueueHelper; - - @BeforeAll - static void setUp() throws Exception { - // Initialize the test environment - IntegrationTestInitService.getInstance().init(); - jobQueueHelper = CDIUtils.getBean(JobQueueHelper.class).orElseThrow(() -> new IllegalStateException("JobQueueHelper Bean not found")); - } + @Inject + JobQueueHelper jobQueueHelper; @Test void testEmptyParams(){ diff --git a/dotcms-integration/src/test/java/com/dotcms/util/IntegrationTestInitService.java b/dotcms-integration/src/test/java/com/dotcms/util/IntegrationTestInitService.java index 6b397ee4dade..9711a2000a10 100644 --- a/dotcms-integration/src/test/java/com/dotcms/util/IntegrationTestInitService.java +++ b/dotcms-integration/src/test/java/com/dotcms/util/IntegrationTestInitService.java @@ -3,6 +3,7 @@ import com.dotcms.business.bytebuddy.ByteBuddyFactory; import com.dotcms.config.DotInitializationService; import com.dotcms.jobs.business.api.JobProcessorFactory; +import com.dotcms.jobs.business.api.JobProcessorScanner; import com.dotcms.jobs.business.api.JobQueueConfig; import com.dotcms.jobs.business.api.JobQueueConfigProducer; import com.dotcms.jobs.business.api.JobQueueManagerAPIImpl; @@ -16,6 +17,7 @@ import com.dotcms.repackage.org.apache.struts.Globals; import com.dotcms.repackage.org.apache.struts.config.ModuleConfig; import com.dotcms.repackage.org.apache.struts.config.ModuleConfigFactory; +import com.dotcms.rest.api.v1.job.JobQueueHelper; import com.dotcms.test.TestUtil; import com.dotmarketing.business.APILocator; import com.dotmarketing.business.CacheLocator; @@ -72,7 +74,9 @@ public void init() throws Exception { RetryStrategyProducer.class, RealTimeJobMonitor.class, JobProcessorFactory.class, - EventProducer.class) + EventProducer.class, + JobProcessorScanner.class, + JobQueueHelper.class) .initialize(); System.setProperty(TestUtil.DOTCMS_INTEGRATION_TEST, TestUtil.DOTCMS_INTEGRATION_TEST);