Skip to content

Commit

Permalink
Fix submit analysis test
Browse files Browse the repository at this point in the history
  • Loading branch information
gciavarrini authored and openshift-merge-robot committed Aug 14, 2023
1 parent e3f4154 commit 77106fb
Showing 1 changed file with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,46 +1,61 @@
package com.redhat.parodos.tasks.migrationtoolkit;

import java.util.Map;
import java.util.UUID;

import com.redhat.parodos.workflow.context.WorkContextDelegate;
import com.redhat.parodos.workflow.exception.MissingParameterException;
import com.redhat.parodos.workflow.task.log.WorkFlowTaskLogger;
import com.redhat.parodos.workflows.work.WorkContext;
import com.redhat.parodos.workflows.work.WorkReport;
import com.redhat.parodos.workflows.work.WorkStatus;
import lombok.SneakyThrows;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.Mock;

import static com.redhat.parodos.tasks.migrationtoolkit.TestConsts.APP_ID;
import static com.redhat.parodos.workflows.workflow.WorkContextAssert.assertThat;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.mockito.MockitoAnnotations.openMocks;

@Disabled
public class SubmitAnalysisTaskTest {

SubmitAnalysisTask underTest;

@Mock
MTATaskGroupClient mockClient;

@Mock
WorkFlowTaskLogger taskLoggerMock;

WorkContext ctx;

@BeforeEach
public void setUp() {
underTest = new SubmitAnalysisTask();
openMocks(this);
underTest = spy(new SubmitAnalysisTask());
underTest.mtaClient = mockClient;
underTest.taskLogger = taskLoggerMock;
underTest.setBeanName("SubmitAnalysisTask");
ctx = new WorkContext();
}
Expand All @@ -63,6 +78,10 @@ public void missingMandatoryParams() {
@SneakyThrows
public void failsCreatingTaskGroup() {
when(mockClient.create(anyString())).thenReturn(new Result.Failure<>(new Exception("not found")));
doNothing().when(taskLoggerMock).logErrorWithSlf4j(any());

doReturn("123").when(this.underTest).getRequiredParameterValue(eq("applicationID"));

ctx.put("applicationID", "123");
WorkContextDelegate.write(ctx, WorkContextDelegate.ProcessType.WORKFLOW_EXECUTION,
WorkContextDelegate.Resource.ID, UUID.randomUUID());
Expand All @@ -80,6 +99,7 @@ public void failsCreatingTaskGroup() {
@SneakyThrows
public void createCompletes() {
String taskGroupID = "1";
doReturn(APP_ID).when(this.underTest).getRequiredParameterValue(eq("applicationID"));
ctx.put("applicationID", APP_ID);
when(mockClient.create(APP_ID)).thenReturn(new Result.Success<>(of(taskGroupID, APP_ID)));
WorkContextDelegate.write(ctx, WorkContextDelegate.ProcessType.WORKFLOW_EXECUTION,
Expand All @@ -89,8 +109,16 @@ public void createCompletes() {

assertThat(execute.getError(), is(nullValue()));
assertThat(execute.getStatus(), equalTo(WorkStatus.COMPLETED));
assertThat(execute.getWorkContext()).hasEntryKey("analysisTaskGroup");
assertThat(((TaskGroup) execute.getWorkContext().get("analysisTaskGroup")).id(), equalTo(taskGroupID));
assertThat(execute.getWorkContext().getEntrySet(),
hasItem(allOf(hasProperty("key", equalTo("WORKFLOW_EXECUTION_ARGUMENTS")),
hasProperty("value", instanceOf(Map.class)))));

Map<String, Object> workflowExecutionArguments = (Map<String, Object>) execute.getWorkContext().getEntrySet()
.stream().filter(entry -> entry.getKey().equals("WORKFLOW_EXECUTION_ARGUMENTS")).findFirst()
.map(Map.Entry::getValue).orElse(null);

assertThat(workflowExecutionArguments, hasKey("taskGroupID"));
assertThat(workflowExecutionArguments.get("taskGroupID"), equalTo(taskGroupID));
verify(mockClient, times(1)).create(APP_ID);
}

Expand Down

0 comments on commit 77106fb

Please sign in to comment.