Skip to content

Commit

Permalink
#30874 add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogiardino committed Dec 9, 2024
1 parent e96f2ad commit 986fd48
Show file tree
Hide file tree
Showing 3 changed files with 409 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,224 @@ public void test_getJobs() throws DotDataException, JobQueueDataException {
verify(mockJobQueue).getJobs(1, 10);
}


/**
* Method to test: getJobs for a particular queue in JobQueueManagerAPI
* Given Scenario: Valid page and pageSize parameters are provided
* ExpectedResult: Correct list of jobs is retrieved from the job queue
*/
@Test
public void test_getJobsFromQueue() throws DotDataException, JobQueueDataException {

// Prepare test data
Job job1 = mock(Job.class);
Job job2 = mock(Job.class);
List<Job> expectedJobs = Arrays.asList(job1, job2);
final var paginatedResult = JobPaginatedResult.builder()
.jobs(expectedJobs)
.total(2)
.page(1)
.pageSize(10)
.build();

// Mock the behavior of jobQueue.getJobs
when(mockJobQueue.getJobs("testQueue",1, 10)).thenReturn(paginatedResult);

// Call the method under test
final var actualResult = jobQueueManagerAPI.getJobs("testQueue", 1, 10);

// Verify the results
assertEquals(expectedJobs, actualResult.jobs());
verify(mockJobQueue).getJobs("testQueue", 1, 10);
}


/**
* Method to test: getActiveJobs for a particular queue in JobQueueManagerAPI
* Given Scenario: Valid page and pageSize parameters are provided
* ExpectedResult: Correct list of jobs is retrieved from the job queue
*/
@Test
public void test_getActiveJobsFromQueue() throws DotDataException, JobQueueDataException {

// Prepare test data
Job job1 = mock(Job.class);
Job job2 = mock(Job.class);
List<Job> expectedJobs = Arrays.asList(job1, job2);
final var paginatedResult = JobPaginatedResult.builder()
.jobs(expectedJobs)
.total(2)
.page(1)
.pageSize(10)
.build();

// Mock the behavior of jobQueue.getJobs
when(mockJobQueue.getActiveJobs("testQueue",1, 10)).thenReturn(paginatedResult);

// Call the method under test
final var actualResult = jobQueueManagerAPI.getActiveJobs("testQueue", 1, 10);

// Verify the results
assertEquals(expectedJobs, actualResult.jobs());
verify(mockJobQueue).getActiveJobs("testQueue", 1, 10);
}


/**
* Method to test: getCompletedJobs for a particular queue in JobQueueManagerAPI
* Given Scenario: Valid page and pageSize parameters are provided
* ExpectedResult: Correct list of jobs is retrieved from the job queue
*/
@Test
public void test_getCompletedJobsFromQueue() throws DotDataException, JobQueueDataException {

// Prepare test data
Job job1 = mock(Job.class);
Job job2 = mock(Job.class);
List<Job> expectedJobs = Arrays.asList(job1, job2);
final var paginatedResult = JobPaginatedResult.builder()
.jobs(expectedJobs)
.total(2)
.page(1)
.pageSize(10)
.build();

// Mock the behavior of jobQueue.getJobs
when(mockJobQueue.getCompletedJobs("testQueue",1, 10)).thenReturn(paginatedResult);

// Call the method under test
final var actualResult = jobQueueManagerAPI.getCompletedJobs("testQueue", 1, 10);

// Verify the results
assertEquals(expectedJobs, actualResult.jobs());
verify(mockJobQueue).getCompletedJobs("testQueue", 1, 10);
}


/**
* Method to test: getCanceledJobs for a particular queue in JobQueueManagerAPI
* Given Scenario: Valid page and pageSize parameters are provided
* ExpectedResult: Correct list of jobs is retrieved from the job queue
*/
@Test
public void test_getCanceledJobsFromQueue() throws DotDataException, JobQueueDataException {

// Prepare test data
Job job1 = mock(Job.class);
Job job2 = mock(Job.class);
List<Job> expectedJobs = Arrays.asList(job1, job2);
final var paginatedResult = JobPaginatedResult.builder()
.jobs(expectedJobs)
.total(2)
.page(1)
.pageSize(10)
.build();

// Mock the behavior of jobQueue.getJobs
when(mockJobQueue.getCanceledJobs("testQueue",1, 10)).thenReturn(paginatedResult);

// Call the method under test
final var actualResult = jobQueueManagerAPI.getCanceledJobs("testQueue", 1, 10);

// Verify the results
assertEquals(expectedJobs, actualResult.jobs());
verify(mockJobQueue).getCanceledJobs("testQueue", 1, 10);
}


/**
* Method to test: getFailedJobs for a particular queue in JobQueueManagerAPI
* Given Scenario: Valid page and pageSize parameters are provided
* ExpectedResult: Correct list of jobs is retrieved from the job queue
*/
@Test
public void test_getFailedJobsFromQueue() throws DotDataException, JobQueueDataException {

// Prepare test data
Job job1 = mock(Job.class);
Job job2 = mock(Job.class);
List<Job> expectedJobs = Arrays.asList(job1, job2);
final var paginatedResult = JobPaginatedResult.builder()
.jobs(expectedJobs)
.total(2)
.page(1)
.pageSize(10)
.build();

// Mock the behavior of jobQueue.getJobs
when(mockJobQueue.getFailedJobs("testQueue",1, 10)).thenReturn(paginatedResult);

// Call the method under test
final var actualResult = jobQueueManagerAPI.getFailedJobs("testQueue", 1, 10);

// Verify the results
assertEquals(expectedJobs, actualResult.jobs());
verify(mockJobQueue).getFailedJobs("testQueue", 1, 10);
}


/**
* Method to test: getAbandonedJobs for a particular queue in JobQueueManagerAPI
* Given Scenario: Valid page and pageSize parameters are provided
* ExpectedResult: Correct list of jobs is retrieved from the job queue
*/
@Test
public void test_getAbandonedJobsFromQueue() throws DotDataException, JobQueueDataException {

// Prepare test data
Job job1 = mock(Job.class);
Job job2 = mock(Job.class);
List<Job> expectedJobs = Arrays.asList(job1, job2);
final var paginatedResult = JobPaginatedResult.builder()
.jobs(expectedJobs)
.total(2)
.page(1)
.pageSize(10)
.build();

// Mock the behavior of jobQueue.getJobs
when(mockJobQueue.getAbandonedJobs("testQueue",1, 10)).thenReturn(paginatedResult);

// Call the method under test
final var actualResult = jobQueueManagerAPI.getAbandonedJobs("testQueue", 1, 10);

// Verify the results
assertEquals(expectedJobs, actualResult.jobs());
verify(mockJobQueue).getAbandonedJobs("testQueue", 1, 10);
}


/**
* Method to test: getSuccessfulJobs for a particular queue in JobQueueManagerAPI
* Given Scenario: Valid page and pageSize parameters are provided
* ExpectedResult: Correct list of jobs is retrieved from the job queue
*/
@Test
public void test_getSuccessfulJobsFromQueue() throws DotDataException, JobQueueDataException {

// Prepare test data
Job job1 = mock(Job.class);
Job job2 = mock(Job.class);
List<Job> expectedJobs = Arrays.asList(job1, job2);
final var paginatedResult = JobPaginatedResult.builder()
.jobs(expectedJobs)
.total(2)
.page(1)
.pageSize(10)
.build();

// Mock the behavior of jobQueue.getJobs
when(mockJobQueue.getSuccessfulJobs("testQueue",1, 10)).thenReturn(paginatedResult);

// Call the method under test
final var actualResult = jobQueueManagerAPI.getSuccessfulJobs("testQueue", 1, 10);

// Verify the results
assertEquals(expectedJobs, actualResult.jobs());
verify(mockJobQueue).getSuccessfulJobs("testQueue", 1, 10);
}


/**
* Method to test: start in JobQueueManagerAPI
* Given Scenario: JobQueueManagerAPI is not started
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,96 @@ void test_getActiveJobsForQueue() throws JobQueueException {
assertEquals(5, result.total());
}


/**
* Method to test: getSuccessfulJobs in PostgresJobQueue for queue
* Given Scenario: Multiple successful jobs are created
* ExpectedResult: All successful jobs are retrieved correctly
*/
@Test
void test_getSuccessfulJobsForQueue() throws JobQueueException {

String queueName = "testQueue";
for (int i = 0; i < 5; i++) {
String jobId = jobQueue.createJob(queueName, new HashMap<>());
Job job = jobQueue.getJob(jobId);
Job completedJob = job.markAsSuccessful(null);
jobQueue.updateJobStatus(completedJob);
}

JobPaginatedResult result = jobQueue.getSuccessfulJobs(queueName, 1, 10);
assertEquals(5, result.jobs().size());
assertEquals(5, result.total());
}


/**
* Method to test: getFailedJobs in PostgresJobQueue for queue
* Given Scenario: Multiple failed jobs are created
* ExpectedResult: All failed jobs are retrieved correctly
*/
@Test
void test_getFailedJobsForQueue() throws JobQueueException {

String queueName = "testQueue";
for (int i = 0; i < 5; i++) {
String jobId = jobQueue.createJob(queueName, new HashMap<>());
Job job = jobQueue.getJob(jobId);
Job failedJob = Job.builder().from(job)
.state(JobState.FAILED)
.build();
jobQueue.updateJobStatus(failedJob);
}

JobPaginatedResult result = jobQueue.getFailedJobs(queueName, 1, 10);
assertEquals(5, result.jobs().size());
assertEquals(5, result.total());
}

/**
* Method to test: getCanceledJobs in PostgresJobQueue for queue
* Given Scenario: Multiple canceled jobs are created
* ExpectedResult: All canceled jobs are retrieved correctly
*/
@Test
void test_getCanceledJobsForQueue() throws JobQueueException {

String queueName = "testQueue";
for (int i = 0; i < 5; i++) {
String jobId = jobQueue.createJob(queueName, new HashMap<>());
Job job = jobQueue.getJob(jobId);
Job completedJob = job.markAsCanceled(null);
jobQueue.updateJobStatus(completedJob);
}

JobPaginatedResult result = jobQueue.getCanceledJobs(queueName, 1, 10);
assertEquals(5, result.jobs().size());
assertEquals(5, result.total());
}

/**
* Method to test: getAbandonedJobs in PostgresJobQueue for queue
* Given Scenario: Multiple abandoned jobs are created
* ExpectedResult: All abandoned jobs are retrieved correctly
*/
@Test
void test_getAbandonedJobsForQueue() throws JobQueueException {

String queueName = "testQueue";
for (int i = 0; i < 5; i++) {
String jobId = jobQueue.createJob(queueName, new HashMap<>());
Job job = jobQueue.getJob(jobId);
Job failedJob = Job.builder().from(job)
.state(JobState.ABANDONED)
.build();
jobQueue.updateJobStatus(failedJob);
}

JobPaginatedResult result = jobQueue.getAbandonedJobs(queueName, 1, 10);
assertEquals(5, result.jobs().size());
assertEquals(5, result.total());
}

/**
* Method to test: getActiveJobs in PostgresJobQueue Given Scenario: Multiple active jobs are
* created ExpectedResult: All active jobs are retrieved correctly
Expand Down
Loading

0 comments on commit 986fd48

Please sign in to comment.