Commit eab6ac2f authored by Vineeth Guna [Microsoft]'s avatar Vineeth Guna [Microsoft]
Browse files

Fixed unit tests as they are failing

parent 623deb85
Pipeline #17069 passed with stages
in 28 minutes and 46 seconds
......@@ -173,8 +173,8 @@ public class CustomOperatorMvcTest {
RESPONSE_CUSTOM_OPERATORS_PAGE, CustomOperatorsPage.class);
when(customOperatorService.getAllOperators(50, null))
.thenReturn(mockedCustomOperatorsPage);
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.VIEWER)))
.thenReturn(authorizationResponse);
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.ADMIN), eq(WorkflowRole.CREATOR),
eq(WorkflowRole.VIEWER))).thenReturn(authorizationResponse);
final MvcResult mvcResult = mockMvc.perform(
get(CUSTOM_OPERATOR_ENDPOINT)
......@@ -183,7 +183,8 @@ public class CustomOperatorMvcTest {
.andExpect(status().isOk())
.andReturn();
verify(customOperatorService, times(1)).getAllOperators(50, null);
verify(authorizationService, times(1)).authorizeAny(any(), eq(WorkflowRole.VIEWER));
verify(authorizationService, times(1)).authorizeAny(any(), eq(WorkflowRole.ADMIN),
eq(WorkflowRole.CREATOR), eq(WorkflowRole.VIEWER));
final CustomOperatorsPage response = mapper.readValue(mvcResult.getResponse()
.getContentAsByteArray(), CustomOperatorsPage.class);
assertThat(mockedCustomOperatorsPage, equalTo(response));
......@@ -197,8 +198,8 @@ public class CustomOperatorMvcTest {
RESPONSE_CUSTOM_OPERATORS_PAGE, CustomOperatorsPage.class);
when(customOperatorService.getAllOperators(limit, cursor))
.thenReturn(mockedCustomOperatorsPage);
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.VIEWER)))
.thenReturn(authorizationResponse);
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.ADMIN), eq(WorkflowRole.CREATOR),
eq(WorkflowRole.VIEWER))).thenReturn(authorizationResponse);
final MvcResult mvcResult = mockMvc.perform(
get(CUSTOM_OPERATOR_ENDPOINT)
......@@ -210,7 +211,7 @@ public class CustomOperatorMvcTest {
.andReturn();
verify(customOperatorService, times(1)).getAllOperators(limit, cursor);
verify(authorizationService, times(1)).authorizeAny(any(),
eq(WorkflowRole.VIEWER));
eq(WorkflowRole.ADMIN), eq(WorkflowRole.CREATOR), eq(WorkflowRole.VIEWER));
final CustomOperatorsPage response = mapper.readValue(mvcResult.getResponse()
.getContentAsByteArray(), CustomOperatorsPage.class);
assertThat(mockedCustomOperatorsPage, equalTo(response));
......@@ -222,8 +223,8 @@ public class CustomOperatorMvcTest {
final CustomOperator customOperator = mapper.readValue(RESPONSE_CUSTOM_OPERATOR,
CustomOperator.class);
when(customOperatorService.getOperatorById(id)).thenReturn(customOperator);
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.VIEWER)))
.thenReturn(authorizationResponse);
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.ADMIN), eq(WorkflowRole.CREATOR),
eq(WorkflowRole.VIEWER))).thenReturn(authorizationResponse);
final MvcResult mvcResult = mockMvc.perform(
get(CUSTOM_OPERATOR_BY_ID_ENDPOINT, id)
......@@ -232,8 +233,8 @@ public class CustomOperatorMvcTest {
.andExpect(status().isOk())
.andReturn();
verify(customOperatorService, times(1)).getOperatorById(id);
verify(authorizationService, times(1)).authorizeAny(any(),
eq(WorkflowRole.VIEWER));
verify(authorizationService, times(1)).authorizeAny(any(), eq(WorkflowRole.ADMIN),
eq(WorkflowRole.CREATOR), eq(WorkflowRole.VIEWER));
final CustomOperator response = mapper.readValue(mvcResult.getResponse()
.getContentAsByteArray(), CustomOperator.class);
assertThat(customOperator, equalTo(response));
......@@ -244,8 +245,8 @@ public class CustomOperatorMvcTest {
final String invalidId = "wdqqfqfqweew";
when(customOperatorService.getOperatorById(invalidId))
.thenThrow(new CustomOperatorNotFoundException("Not found"));
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.VIEWER)))
.thenReturn(authorizationResponse);
when(authorizationService.authorizeAny(any(), eq(WorkflowRole.ADMIN), eq(WorkflowRole.CREATOR),
eq(WorkflowRole.VIEWER))).thenReturn(authorizationResponse);
final MvcResult mvcResult = mockMvc.perform(
get(CUSTOM_OPERATOR_BY_ID_ENDPOINT, invalidId)
......@@ -254,8 +255,8 @@ public class CustomOperatorMvcTest {
.andExpect(status().isNotFound())
.andReturn();
verify(customOperatorService, times(1)).getOperatorById(invalidId);
verify(authorizationService, times(1)).authorizeAny(any(),
eq(WorkflowRole.VIEWER));
verify(authorizationService, times(1)).authorizeAny(any(), eq(WorkflowRole.ADMIN),
eq(WorkflowRole.CREATOR), eq(WorkflowRole.VIEWER));
}
private HttpHeaders getHttpHeaders() {
......
......@@ -47,6 +47,8 @@ import org.opengroup.osdu.workflow.model.IngestionStrategy;
import org.opengroup.osdu.workflow.model.WorkflowRole;
import org.opengroup.osdu.workflow.model.WorkflowStatus;
import org.opengroup.osdu.workflow.model.WorkflowStatusType;
import org.opengroup.osdu.workflow.provider.interfaces.ICustomOperatorMetadataRepository;
import org.opengroup.osdu.workflow.provider.interfaces.ICustomOperatorStore;
import org.opengroup.osdu.workflow.provider.interfaces.IIngestionStrategyRepository;
import org.opengroup.osdu.workflow.provider.interfaces.ISubmitIngestService;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowDefinitionRepository;
......@@ -106,6 +108,10 @@ public class WorkflowMvcTest {
private IWorkflowEngineService workflowEngineService;
@MockBean
private IWorkflowTasksSharingRepository workflowTasksSharingRepository;
@MockBean
private ICustomOperatorMetadataRepository customOperatorMetadataRepository;
@MockBean
private ICustomOperatorStore customOperatorStore;
@Captor
private ArgumentCaptor<WorkflowStatus> workflowStatusCaptor;
......
......@@ -43,6 +43,8 @@ import org.opengroup.osdu.workflow.model.UpdateStatusResponse;
import org.opengroup.osdu.workflow.model.WorkflowRole;
import org.opengroup.osdu.workflow.model.WorkflowStatus;
import org.opengroup.osdu.workflow.model.WorkflowStatusType;
import org.opengroup.osdu.workflow.provider.interfaces.ICustomOperatorMetadataRepository;
import org.opengroup.osdu.workflow.provider.interfaces.ICustomOperatorStore;
import org.opengroup.osdu.workflow.provider.interfaces.IIngestionStrategyRepository;
import org.opengroup.osdu.workflow.provider.interfaces.ISubmitIngestService;
import org.opengroup.osdu.workflow.provider.interfaces.IWorkflowDefinitionRepository;
......@@ -101,6 +103,10 @@ public class WorkflowStatusMvcTest {
private IWorkflowEngineService workflowEngineService;
@MockBean
private IWorkflowTasksSharingRepository workflowTasksSharingRepository;
@MockBean
private ICustomOperatorMetadataRepository customOperatorMetadataRepository;
@MockBean
private ICustomOperatorStore customOperatorStore;
@Test
public void shouldPassGetWorkflowStatusFlow() throws Exception {
......
Markdown is supported
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