Skip to content

Commit

Permalink
#29498 Fixing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgambarios committed Oct 23, 2024
1 parent 2f605a7 commit a757bb0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public JobQueueHelper(JobQueueManagerAPI jobQueueManagerAPI, JobProcessorScanner
*/
@VisibleForTesting
void registerProcessor(final String queueName, final Class<? extends JobProcessor> processor){
jobQueueManagerAPI.registerProcessor(queueName.toLowerCase(), processor);
jobQueueManagerAPI.registerProcessor(queueName, processor);
}

/**
Expand Down Expand Up @@ -210,7 +210,7 @@ JobPaginatedResult getJobs(int page, int pageSize) {
*/
JobPaginatedResult getActiveJobs(String queueName, int page, int pageSize) {
try {
return jobQueueManagerAPI.getActiveJobs(queueName.toLowerCase(), page, pageSize);
return jobQueueManagerAPI.getActiveJobs(queueName, page, pageSize);
} catch (JobQueueDataException e) {
Logger.error(this.getClass(), "Error fetching active jobs", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,13 @@ void testEmptyParams(){
void testWithValidParamsButInvalidQueueName(){
final JobParams jobParams = new JobParams();
jobParams.setJsonParams("{}");

final var user = mock(User.class);
when(user.getUserId()).thenReturn("dotcms.org.1");

assertThrows(DoesNotExistException.class, () -> {
jobQueueHelper.createJob(
"nonExisting", jobParams, mock(User.class), mock(HttpServletRequest.class)
"nonExisting", jobParams, user, mock(HttpServletRequest.class)
);
});
}
Expand Down Expand Up @@ -91,15 +95,18 @@ void testWithValidParamsAndQueueName() throws DotDataException, JsonProcessingEx
final JobParams jobParams = new JobParams();
jobParams.setJsonParams("{}");

final var user = mock(User.class);
when(user.getUserId()).thenReturn("dotcms.org.1");

final String jobId = jobQueueHelper.createJob(
"demoQueue", jobParams, mock(User.class), mock(HttpServletRequest.class)
"demoQueue", jobParams, user, mock(HttpServletRequest.class)
);

Assertions.assertNotNull(jobId);
final Job job = jobQueueHelper.getJob(jobId);
Assertions.assertNotNull(job);
Assertions.assertEquals(jobId, job.id());
Assertions.assertTrue(jobQueueHelper.getQueueNames().contains("demoQueue".toLowerCase()));
Assertions.assertTrue(jobQueueHelper.getQueueNames().contains("demoQueue"));
}

/**
Expand All @@ -113,8 +120,12 @@ void testIsWatchable() throws DotDataException, JsonProcessingException {
jobQueueHelper.registerProcessor("testQueue", DemoJobProcessor.class);
final JobParams jobParams = new JobParams();
jobParams.setJsonParams("{}");

final var user = mock(User.class);
when(user.getUserId()).thenReturn("dotcms.org.1");

final String jobId = jobQueueHelper.createJob(
"testQueue", jobParams, mock(User.class), mock(HttpServletRequest.class)
"testQueue", jobParams, user, mock(HttpServletRequest.class)
);
Assertions.assertNotNull(jobId);
final Job job = jobQueueHelper.getJob(jobId);
Expand All @@ -133,8 +144,12 @@ void testGetStatusInfo() throws DotDataException, JsonProcessingException {
jobQueueHelper.registerProcessor("testQueue", DemoJobProcessor.class);
final JobParams jobParams = new JobParams();
jobParams.setJsonParams("{}");

final var user = mock(User.class);
when(user.getUserId()).thenReturn("dotcms.org.1");

final String jobId = jobQueueHelper.createJob(
"testQueue", jobParams, mock(User.class), mock(HttpServletRequest.class)
"testQueue", jobParams, user, mock(HttpServletRequest.class)
);
Assertions.assertNotNull(jobId);
final Job job = jobQueueHelper.getJob(jobId);
Expand Down

0 comments on commit a757bb0

Please sign in to comment.