Skip to content

Commit

Permalink
#29898 Adding CDI to the job queue system
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Sep 10, 2024
1 parent 8961b9d commit a4c9846
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 8 deletions.
6 changes: 5 additions & 1 deletion dotcms-integration/src/test/java/com/dotcms/MainSuite2b.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.dotcms.cache.lettuce.DotObjectCodecTest;
import com.dotcms.cache.lettuce.LettuceCacheTest;
import com.dotcms.cache.lettuce.RedisClientTest;
import com.dotcms.cdi.SimpleInjectionIT;
import com.dotcms.content.business.ObjectMapperTest;
import com.dotcms.content.business.json.ContentletJsonAPITest;
import com.dotcms.content.elasticsearch.business.ESIndexAPITest;
Expand Down Expand Up @@ -50,6 +51,7 @@
import com.dotcms.integritycheckers.ContentPageIntegrityCheckerTest;
import com.dotcms.integritycheckers.HostIntegrityCheckerTest;
import com.dotcms.integritycheckers.IntegrityUtilTest;
import com.dotcms.jobs.business.api.JobQueueManagerAPICDITest;
import com.dotcms.jobs.business.api.JobQueueManagerAPITest;
import com.dotcms.junit.MainBaseSuite;
import com.dotcms.mail.MailAPIImplTest;
Expand Down Expand Up @@ -321,7 +323,9 @@
Task240606AddVariableColumnToWorkflowTest.class,
OpenAIContentPromptActionletTest.class,
JobQueueManagerAPITest.class,
ConfigUtilsTest.class
ConfigUtilsTest.class,
JobQueueManagerAPICDITest.class,
SimpleInjectionIT.class
})

public class MainSuite2b {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.dotcms.jobs.business.api;

import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertSame;

import com.dotcms.jobs.business.error.CircuitBreaker;
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.Assertions;
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)
);

@Inject
private JobQueueManagerAPI jobQueueManagerAPI;

@Inject
private JobQueueManagerAPI jobQueueManagerAPI2;

/**
* Method to test: Multiple injections of JobQueueManagerAPI
* Given Scenario: Two separate injections of JobQueueManagerAPI are requested
* ExpectedResult: Both injections refer to the same instance, confirming singleton behavior
*/
@Test
public void test_SingletonBehavior() {
assertNotNull(jobQueueManagerAPI,
"First JobQueueManagerAPI instance should not be null");
assertNotNull(jobQueueManagerAPI2,
"Second JobQueueManagerAPI instance should not be null");
assertSame(jobQueueManagerAPI, jobQueueManagerAPI2,
"Both JobQueueManagerAPI injections should refer to the same instance");
}

/**
* Method to test: CDI injection of JobQueueManagerAPI
* Given Scenario: A CDI environment is set up with necessary dependencies
* ExpectedResult: JobQueueManagerAPI is correctly injected and is an instance of
* JobQueueManagerAPIImpl
*/
@Test
public void test_CDIInjection() {
assertNotNull(jobQueueManagerAPI, "JobQueueManagerAPI should be injected");
Assertions.assertInstanceOf(JobQueueManagerAPIImpl.class, jobQueueManagerAPI,
"JobQueueManagerAPI should be an instance of JobQueueManagerAPIImpl");
}

/**
* Method to test: Dependency injection of JobQueueManagerAPIImpl fields
* Given Scenario: JobQueueManagerAPIImpl is instantiated by the CDI container
* ExpectedResult: All required dependencies are correctly injected into JobQueueManagerAPIImpl
*/
@Test
public void test_JobQueueManagerAPIFields() {

// There are not JobQueue implementations yet
//Assertions.assertNotNull(impl.getJobQueue(), "JobQueue should be injected");

assertNotNull(jobQueueManagerAPI.getCircuitBreaker(),
"CircuitBreaker should be injected");
assertNotNull(jobQueueManagerAPI.getDefaultRetryStrategy(),
"Retry strategy should be injected");

Assertions.assertEquals(10, jobQueueManagerAPI.getThreadPoolSize(),
"ThreadPoolSize should be greater than 0");
Assertions.assertInstanceOf(ExponentialBackoffRetryStrategy.class,
jobQueueManagerAPI.getDefaultRetryStrategy(),
"Retry strategy should be an instance of ExponentialBackoffRetryStrategy");
}

}
7 changes: 0 additions & 7 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -866,13 +866,6 @@
<systemPropertyVariables/>
<trimStackTrace>true</trimStackTrace>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>${version.surefire.plugin}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
Expand Down

0 comments on commit a4c9846

Please sign in to comment.