Commit 8acbb35a authored by Aalekh Jain's avatar Aalekh Jain
Browse files

Updated UTs for WorkflowManagerService for system workflow related APIs

parent 501e93db
......@@ -135,6 +135,44 @@ public class WorkflowManagerServiceTest {
assertThat(workflowMetadataCaptor.getValue().getVersion(), equalTo(SEED_VERSION));
}
@Test
void testCreateSystemWorkflowWithValidData() throws Exception {
//given
when(dpsHeaders.getUserEmail()).thenReturn(USER_EMAIL);
final CreateWorkflowRequest request =
OBJECT_MAPPER.readValue(CREATE_WORKFLOW_REQUEST, CreateWorkflowRequest.class);
final ArgumentCaptor<WorkflowMetadata> workflowMetadataCaptor = ArgumentCaptor
.forClass(WorkflowMetadata.class);
final WorkflowMetadata responseMetadata = mock(WorkflowMetadata.class);
when(workflowSystemMetadataRepository.createSystemWorkflow(workflowMetadataCaptor.capture()))
.thenReturn(responseMetadata);
final ArgumentCaptor<WorkflowEngineRequest> workflowEngineRequestArgumentCaptor =
ArgumentCaptor.forClass(WorkflowEngineRequest.class);
doNothing().when(workflowEngineService)
.createWorkflow(workflowEngineRequestArgumentCaptor.capture(),
eq(request.getRegistrationInstructions()));
//when
final WorkflowMetadata returnedMetadata = workflowManagerService.createSystemWorkflow(request);
//then
verify(workflowSystemMetadataRepository).createSystemWorkflow(any(WorkflowMetadata.class));
verify(workflowEngineService).createWorkflow(any(WorkflowEngineRequest.class),
eq(request.getRegistrationInstructions()));
verify(dpsHeaders).getUserEmail();
assertThat(returnedMetadata, equalTo(responseMetadata));
assertThat(workflowEngineRequestArgumentCaptor.getValue().getWorkflowName(),
equalTo(workflowMetadataCaptor.getValue().getWorkflowName()));
assertThat(workflowEngineRequestArgumentCaptor.getValue().isSystemWorkflow(),
equalTo(true));
assertThat(workflowMetadataCaptor.getValue().getWorkflowName(),
equalTo(request.getWorkflowName()));
assertThat(workflowMetadataCaptor.getValue().getDescription(),
equalTo(request.getDescription()));
assertThat(workflowMetadataCaptor.getValue().getCreatedBy(), equalTo(USER_EMAIL));
assertThat(workflowMetadataCaptor.getValue().getVersion(), equalTo(SEED_VERSION));
}
@Test
void testCreateWorkflowWithConflict() throws Exception {
//given
......@@ -164,6 +202,35 @@ public class WorkflowManagerServiceTest {
assertThat(workflowMetadataCaptor.getValue().getVersion(), equalTo(SEED_VERSION));
}
@Test
void testCreateSystemWorkflowWithConflict() throws Exception {
//given
final CreateWorkflowRequest request =
OBJECT_MAPPER.readValue(CREATE_WORKFLOW_REQUEST, CreateWorkflowRequest.class);
final ArgumentCaptor<WorkflowMetadata> workflowMetadataCaptor = ArgumentCaptor
.forClass(WorkflowMetadata.class);
final WorkflowMetadata responseMetadata = mock(WorkflowMetadata.class);
when(workflowSystemMetadataRepository.createSystemWorkflow(workflowMetadataCaptor.capture()))
.thenThrow(new ResourceConflictException("conflictId", "conflicted"));
when(dpsHeaders.getUserEmail()).thenReturn(USER_EMAIL);
//when and then
Assertions.assertThrows(CoreException.class, () -> {
workflowManagerService.createSystemWorkflow(request);
});
verify(workflowSystemMetadataRepository, times(1)).createSystemWorkflow(any(WorkflowMetadata.class));
verify(workflowEngineService, times(0))
.createWorkflow(any(WorkflowEngineRequest.class),
eq(request.getRegistrationInstructions()));
verify(dpsHeaders, times(1)).getUserEmail();
assertThat(workflowMetadataCaptor.getValue().getWorkflowName(),
equalTo(request.getWorkflowName()));
assertThat(workflowMetadataCaptor.getValue().getDescription(),
equalTo(request.getDescription()));
assertThat(workflowMetadataCaptor.getValue().getCreatedBy(), equalTo(USER_EMAIL));
assertThat(workflowMetadataCaptor.getValue().getVersion(), equalTo(SEED_VERSION));
}
@Test
public void testCreateWorkflowWithInvalidWorkflowName() throws Exception {
//given
......@@ -176,6 +243,18 @@ public class WorkflowManagerServiceTest {
});
}
@Test
public void testCreateSystemWorkflowWithInvalidWorkflowName() throws Exception {
//given
final CreateWorkflowRequest request =
OBJECT_MAPPER.readValue(CREATE_WORKFLOW_REQUEST_WITH_INVALID_WORKFLOW_NAME, CreateWorkflowRequest.class);
//when and then
Assertions.assertThrows(BadRequestException.class, () -> {
workflowManagerService.createSystemWorkflow(request);
});
}
@Test
void testGetWorkflowByIdWithExistingWorkflow() {
//given
......@@ -194,6 +273,27 @@ public class WorkflowManagerServiceTest {
assertThat(workflowIdCaptor.getValue(), equalTo(WORKFLOW_NAME));
}
@Test
void testGetWorkflowByIdWithNonExistingPrivateWorkflowExistingSystemWorkflow() {
//given
final WorkflowMetadata responseMetadata = mock(WorkflowMetadata.class);
final ArgumentCaptor<String> workflowIdCaptor = ArgumentCaptor.forClass(String.class);
when(workflowMetadataRepository.getWorkflow(workflowIdCaptor.capture()))
.thenThrow(WorkflowNotFoundException.class);
when(workflowSystemMetadataRepository.getSystemWorkflow(workflowIdCaptor.capture()))
.thenReturn(responseMetadata);
//when
final WorkflowMetadata returnedMetadata = workflowManagerService
.getWorkflowByName(WORKFLOW_NAME);
//then
verify(workflowMetadataRepository).getWorkflow(eq(WORKFLOW_NAME));
verify(workflowSystemMetadataRepository).getSystemWorkflow(eq(WORKFLOW_NAME));
assertThat(returnedMetadata, equalTo(responseMetadata));
assertThat(workflowIdCaptor.getValue(), equalTo(WORKFLOW_NAME));
}
@Test
void testGetWorkflowByIdWithNonExistingWorkflow() {
//given
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment