-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DMP-4216: Allow inactive tasks to be run manually #2238
Changes from all commits
c1746df
5c1022f
f829e60
d2bfbb0
9d82640
b71235e
4f6bdda
0df7f3a
fe66f6e
5435b5d
cb19b6b
35e2cdc
8f67174
873599f
6974ec7
97c6e1b
6f9645f
bca06dd
743d827
8784591
e2358c9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
import uk.gov.hmcts.darts.common.exception.DartsApiException; | ||
import uk.gov.hmcts.darts.common.repository.AutomatedTaskRepository; | ||
import uk.gov.hmcts.darts.task.exception.AutomatedTaskApiError; | ||
import uk.gov.hmcts.darts.task.runner.AutomatedTask; | ||
import uk.gov.hmcts.darts.task.runner.impl.AbstractLockableAutomatedTask; | ||
import uk.gov.hmcts.darts.task.service.LockService; | ||
import uk.gov.hmcts.darts.tasks.model.AutomatedTaskPatch; | ||
|
@@ -27,8 +28,10 @@ | |
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.lenient; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.verifyNoInteractions; | ||
|
@@ -43,8 +46,6 @@ class AdminAutomatedTasksServiceImplTest { | |
@Mock | ||
private AutomatedTasksMapper mapper; | ||
@Mock | ||
private ManualTaskService manualTaskService; | ||
@Mock | ||
private AutomatedTaskRunner automatedTaskRunner; | ||
@Mock | ||
private LockService lockService; | ||
|
@@ -62,17 +63,19 @@ class AdminAutomatedTasksServiceImplTest { | |
|
||
@Test | ||
void invokesTaskWhenTaskIsNotLocked() { | ||
adminAutomatedTaskService = spy(adminAutomatedTaskService); | ||
var automatedTask = anAutomatedTaskEntityWithName("some-task-name", null); | ||
when(someAutomatedTask.getTaskName()).thenReturn("some-task-name"); | ||
when(lockService.isLocked(automatedTask)).thenReturn(false); | ||
|
||
when(automatedTaskRepository.findById(1)).thenReturn(Optional.of(automatedTask)); | ||
when(manualTaskService.getAutomatedTasks()).thenReturn(List.of(someAutomatedTask)); | ||
doReturn(List.of((AutomatedTask) someAutomatedTask)).when(adminAutomatedTaskService).getAllAutomatedTasks(); | ||
|
||
adminAutomatedTaskService.runAutomatedTask(1); | ||
|
||
verify(automatedTaskRunner, times(1)).run(someAutomatedTask); | ||
verify(auditApi, times(1)).record(AuditActivity.RUN_JOB_MANUALLY,"some-task-name"); | ||
verify(automatedTaskRunner, times(1)).run(someAutomatedTask, true); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You have set isManual to true but is there a test where its set to false There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the is manual run false should be covered by the existing tests for automated tasks. As when it is not manually run we default this value to be false |
||
verify(auditApi, times(1)).record(AuditActivity.RUN_JOB_MANUALLY, "some-task-name"); | ||
verify(adminAutomatedTaskService, times(1)).getAllAutomatedTasks(); | ||
} | ||
|
||
@Test | ||
|
@@ -95,7 +98,7 @@ void updateAutomatedTask() { | |
assertFalse(automatedTaskEntity.getTaskEnabled()); | ||
assertEquals(100, automatedTaskEntity.getBatchSize()); | ||
assertEquals(expectedReturnTask, task); | ||
verify(auditApi).record(AuditActivity.ENABLE_DISABLE_JOB,"some-task-name disabled"); | ||
verify(auditApi).record(AuditActivity.ENABLE_DISABLE_JOB, "some-task-name disabled"); | ||
verifyNoMoreInteractions(auditApi); | ||
} | ||
|
||
|
@@ -116,7 +119,7 @@ void updateAutomatedTaskDoesNotUpdateFieldsWithNullValueInPatchRequest() { | |
|
||
|
||
@Test | ||
void positiveGetAllAutomatedTasks() { | ||
void positiveGetAllAutomatedTasksSummaries() { | ||
AutomatedTaskEntity automatedTaskEntity1 = | ||
createAutomatedTaskEntity("task1", true); | ||
AutomatedTaskEntity automatedTaskEntity2 = | ||
|
@@ -126,7 +129,7 @@ void positiveGetAllAutomatedTasks() { | |
|
||
when(automatedTaskRepository.findAll()).thenReturn(List.of(automatedTaskEntity1, automatedTaskEntity2, automatedTaskEntity3)); | ||
|
||
adminAutomatedTaskService.getAllAutomatedTasks(); | ||
adminAutomatedTaskService.getAllAutomatedTasksSummaries(); | ||
|
||
verify(automatedTaskRepository, times(1)) | ||
.findAll(); | ||
|
@@ -136,7 +139,7 @@ void positiveGetAllAutomatedTasks() { | |
|
||
|
||
@Test | ||
void positiveGetAllAutomatedTasksDisabledExcludeFlag() { | ||
void positiveGetAllAutomatedTasksSummariesDisabledExcludeFlag() { | ||
AutomatedTaskEntity automatedTaskEntity1 = | ||
createAutomatedTaskEntity("task1", true); | ||
AutomatedTaskEntity automatedTaskEntity2 = | ||
|
@@ -146,7 +149,7 @@ void positiveGetAllAutomatedTasksDisabledExcludeFlag() { | |
|
||
when(automatedTaskRepository.findAll()).thenReturn(List.of(automatedTaskEntity1, automatedTaskEntity2, automatedTaskEntity3)); | ||
|
||
adminAutomatedTaskService.getAllAutomatedTasks(); | ||
adminAutomatedTaskService.getAllAutomatedTasksSummaries(); | ||
|
||
verify(automatedTaskRepository, times(1)) | ||
.findAll(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code is making my head hurt. Why are we passing this
isManualRun
in as a parameter? Can't we just use theisManualTask
variable that is already used in this class? Or just get rid of theisManualTask
class variable and use your new parameter.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the ManualTaskService as this no longer provided any value and updated the code to reflect this change