Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizzio-dotCMS committed Oct 10, 2024
1 parent ddc4ac3 commit de0ed34
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
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;

@Suite
@SelectClasses({
JobQueueManagerAPICDITest.class,
PostgresJobQueueIntegrationTest.class,
JobQueueManagerAPIIntegrationTest.class
JobQueueManagerAPIIntegrationTest.class,
JobQueueHelperIntegrationTest.class
})
public class Junit5Suite1 {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,28 +18,22 @@
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;

/**
* Integration test for the JobQueueHelper class
* 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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit de0ed34

Please sign in to comment.