Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Simplify integration tests
Browse files Browse the repository at this point in the history
The workflows integration tests share a similar structure:
1. Create a project
2. Verify workflow definition exists
3. Run workflow execution

The first two elements can be generalized and provided some defaults to
simplify adding more tests.

Signed-off-by: Moti Asayag <[email protected]>
  • Loading branch information
masayag authored and openshift-merge-robot committed May 23, 2023
1 parent dc3a601 commit 88e1b7a
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.Arrays;
import java.util.List;

import com.redhat.parodos.flows.base.BaseIntegrationTest;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder.TestComponents;
import com.redhat.parodos.sdk.api.WorkflowApi;
import com.redhat.parodos.sdk.api.WorkflowDefinitionApi;
import com.redhat.parodos.sdk.invoker.ApiException;
Expand All @@ -16,36 +17,38 @@
import com.redhat.parodos.sdk.model.WorkFlowStatusResponseDTO;
import com.redhat.parodos.sdk.model.WorkRequestDTO;
import com.redhat.parodos.sdkutils.SdkUtils;
import com.redhat.parodos.workflow.consts.WorkFlowConstants;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
* @author Gloria Ciavarrini (Github: gciavarrini)
*/
@Slf4j
public class ComplexWorkFlowTest extends BaseIntegrationTest {
public class ComplexWorkFlowTest {

private static final String WORKFLOW_NAME = "onboardingComplexAssessment" + WorkFlowConstants.ASSESSMENT_WORKFLOW;

@Test
public void runComplexWorkFlow() throws ApiException, InterruptedException {
log.info("Running complex flow");

WorkflowApi workflowApi = new WorkflowApi();
log.info("******** Running The Complex WorkFlow ********");

log.info("Running the Assessment to see what WorkFlows are eligible for this situation:");
log.info("******** Running The Complex workFlow ********");
TestComponents components = new WorkFlowTestBuilder().withDefaultProject().withWorkFlowDefinition(WORKFLOW_NAME)
.build();

// Define WorkFlowRequest
WorkFlowRequestDTO workFlowRequestDTO = new WorkFlowRequestDTO();
workFlowRequestDTO.setProjectId(testProject.getId());
workFlowRequestDTO.setWorkFlowName("onboardingComplexAssessment_ASSESSMENT_WORKFLOW");
workFlowRequestDTO.setProjectId(components.project().getId());
workFlowRequestDTO.setWorkFlowName(WORKFLOW_NAME);
workFlowRequestDTO.setWorks(List.of(new WorkRequestDTO()
.arguments(List.of(new ArgumentRequestDTO().key("GIT_REPO_URL").value("git_repo_url")))));

log.info("Running the Assessment to see what WorkFlows are eligible for this situation:");
WorkflowApi workflowApi = new WorkflowApi(components.apiClient());
WorkFlowResponseDTO workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);
assertEquals(WorkStatusEnum.IN_PROGRESS, workFlowResponseDTO.getWorkStatus());
log.info("workflow submitted successfully with response: {}", workFlowResponseDTO);
Expand All @@ -54,9 +57,9 @@ public void runComplexWorkFlow() throws ApiException, InterruptedException {
WorkFlowStatusResponseDTO workFlowStatusResponseDTO = SdkUtils.waitWorkflowStatusAsync(workflowApi,
workFlowResponseDTO.getWorkFlowExecutionId());
assertNotNull(workFlowStatusResponseDTO);
if (workFlowStatusResponseDTO.getStatus() != WorkFlowStatusResponseDTO.StatusEnum.COMPLETED) {
fail("There is no valid INFRASTRUCTURE_OPTION");
}
assertThat(workFlowStatusResponseDTO.getStatus()).as("Assessment workflow should be completed")
.isEqualTo(WorkFlowStatusResponseDTO.StatusEnum.COMPLETED);

WorkFlowContextResponseDTO workflowOptions = workflowApi
.getWorkflowParameters(workFlowResponseDTO.getWorkFlowExecutionId(), List.of("WORKFLOW_OPTIONS"));
assertNotNull(workflowOptions);
Expand Down Expand Up @@ -94,7 +97,7 @@ public void runComplexWorkFlow() throws ApiException, InterruptedException {
work3.setArguments(Arrays.asList(new ArgumentRequestDTO().key("user-id").value("test-user-id"),
new ArgumentRequestDTO().key("api-server").value("api.com")));

workFlowRequestDTO.setProjectId(testProject.getId());
workFlowRequestDTO.setProjectId(components.project().getId());
workFlowRequestDTO.setWorkFlowName(workFlowDefinitions.get(0).getName());
workFlowRequestDTO.setWorks(Arrays.asList(work1, work2, work3));
workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.redhat.parodos.flows;

import com.redhat.parodos.flows.base.BaseIntegrationTest;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder.TestComponents;
import com.redhat.parodos.sdk.api.WorkflowApi;
import com.redhat.parodos.sdk.invoker.ApiException;
import com.redhat.parodos.sdk.model.WorkFlowRequestDTO;
Expand All @@ -17,27 +18,29 @@
* @author Gloria Ciavarrini (Github: gciavarrini)
*/
@Slf4j
public class EscalationFlowTest extends BaseIntegrationTest {
public class EscalationFlowTest {

private static final String WORKFLOW_NAME = "workflowStartingCheckingAndEscalation";

@Test
public void runEscalationFlow() throws ApiException, InterruptedException {
log.info("Running escalation flow");
WorkflowApi workflowApi = new WorkflowApi();

log.info("******** Running The Escalation WorkFlow ********");
log.info("executes 1 task with a WorkFlowChecker");
log.info("******** Running The Escalation workFlow ********");
TestComponents components = new WorkFlowTestBuilder().withDefaultProject().withWorkFlowDefinition(WORKFLOW_NAME)
.build();

// Define WorkFlowRequest
WorkFlowRequestDTO workFlowRequestDTO = new WorkFlowRequestDTO();
workFlowRequestDTO.setProjectId(testProject.getId());
workFlowRequestDTO.setProjectId(components.project().getId());
workFlowRequestDTO.setWorkFlowName("workflowStartingCheckingAndEscalation");

log.info("executes 1 task with a WorkFlowChecker");
WorkflowApi workflowApi = new WorkflowApi(components.apiClient());
WorkFlowResponseDTO workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);

assertNotNull("There is no valid WorkFlowExecutionId", workFlowResponseDTO.getWorkFlowExecutionId());
assertEquals(workFlowResponseDTO.getWorkStatus(), WorkFlowResponseDTO.WorkStatusEnum.IN_PROGRESS);
log.info("Simple escalation workflow execution id: {}", workFlowResponseDTO.getWorkFlowExecutionId());
log.info("Simple Escalation Flow {}", workFlowResponseDTO.getWorkStatus());
log.info("Escalation workflow execution id: {}", workFlowResponseDTO.getWorkFlowExecutionId());
log.info("Escalation workFlow {}", workFlowResponseDTO.getWorkStatus());
log.info("Waiting for checkers to complete...");

WorkFlowStatusResponseDTO workFlowStatusResponseDTO = SdkUtils.waitWorkflowStatusAsync(workflowApi,
Expand All @@ -46,7 +49,7 @@ public void runEscalationFlow() throws ApiException, InterruptedException {
assertNotNull(workFlowStatusResponseDTO);
assertNotNull(workFlowStatusResponseDTO.getWorkFlowExecutionId());
assertEquals(WorkFlowStatusResponseDTO.StatusEnum.COMPLETED, workFlowStatusResponseDTO.getStatus());
log.info("******** Simple Escalation Flow {} ********", workFlowStatusResponseDTO.getStatus());
log.info("******** Escalation workFlow {} ********", workFlowStatusResponseDTO.getStatus());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

import java.util.Arrays;
import java.util.List;
import java.util.function.Consumer;

import com.redhat.parodos.flows.base.BaseIntegrationTest;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder.TestComponents;
import com.redhat.parodos.sdk.api.WorkflowApi;
import com.redhat.parodos.sdk.api.WorkflowDefinitionApi;
import com.redhat.parodos.sdk.invoker.ApiException;
import com.redhat.parodos.sdk.model.ArgumentRequestDTO;
import com.redhat.parodos.sdk.model.WorkDefinitionResponseDTO;
Expand All @@ -27,38 +28,15 @@
import static org.junit.Assert.assertTrue;

@Slf4j
public class PrebuiltWorkFlowTest extends BaseIntegrationTest {
public class PrebuiltWorkFlowTest {

private static final String WORKFLOW_NAME = "prebuiltWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW;

@Test
public void runPreBuiltWorkFlow() throws ApiException, InterruptedException {
String workFlowName = "prebuiltWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW;

log.info("Running pre-built flow (name: {})", workFlowName);

// GET preBuiltWorkFlow DEFINITIONS
WorkflowDefinitionApi workflowDefinitionApi = new WorkflowDefinitionApi(apiClient);
List<WorkFlowDefinitionResponseDTO> prebuiltWorkFlowDefinitions = workflowDefinitionApi
.getWorkFlowDefinitions(workFlowName);
assertEquals(1, prebuiltWorkFlowDefinitions.size());

// GET WORKFLOW DEFINITION BY Id
WorkFlowDefinitionResponseDTO prebuiltWorkFlowDefinition = workflowDefinitionApi
.getWorkFlowDefinitionById(prebuiltWorkFlowDefinitions.get(0).getId());

assertNotNull(prebuiltWorkFlowDefinition.getId());
assertEquals(workFlowName, prebuiltWorkFlowDefinition.getName());
assertEquals(WorkFlowDefinitionResponseDTO.ProcessingTypeEnum.SEQUENTIAL,
prebuiltWorkFlowDefinition.getProcessingType());
assertEquals(WorkFlowDefinitionResponseDTO.TypeEnum.INFRASTRUCTURE, prebuiltWorkFlowDefinition.getType());

assertNotNull(prebuiltWorkFlowDefinition.getWorks());
assertEquals(1, prebuiltWorkFlowDefinition.getWorks().size());
assertEquals("notificationTask", prebuiltWorkFlowDefinition.getWorks().get(0).getName());
assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK,
prebuiltWorkFlowDefinition.getWorks().get(0).getWorkType());
assertTrue(CollectionUtils.isEmpty(prebuiltWorkFlowDefinition.getWorks().get(0).getWorks()));
assertNull(prebuiltWorkFlowDefinition.getWorks().get(0).getProcessingType());
assertNotNull(prebuiltWorkFlowDefinition.getWorks().get(0).getParameters());
log.info("******** Running The pre-built WorkFlow (name: {}) ********", WORKFLOW_NAME);
TestComponents components = new WorkFlowTestBuilder().withDefaultProject()
.withWorkFlowDefinition(WORKFLOW_NAME, getWorkFlowDefinitionResponseConsumer()).build();

// Define WorkRequests
WorkRequestDTO work1 = new WorkRequestDTO();
Expand All @@ -70,11 +48,11 @@ public void runPreBuiltWorkFlow() throws ApiException, InterruptedException {

// Define WorkFlowRequest
WorkFlowRequestDTO workFlowRequestDTO = new WorkFlowRequestDTO();
workFlowRequestDTO.setProjectId(testProject.getId());
workFlowRequestDTO.setWorkFlowName(workFlowName);
workFlowRequestDTO.setProjectId(components.project().getId());
workFlowRequestDTO.setWorkFlowName(WORKFLOW_NAME);
workFlowRequestDTO.setWorks(List.of(work1));

WorkflowApi workflowApi = new WorkflowApi(apiClient);
WorkflowApi workflowApi = new WorkflowApi(components.apiClient());
log.info("******** Running The PreBuilt Flow ********");
WorkFlowResponseDTO workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);

Expand All @@ -90,4 +68,23 @@ public void runPreBuiltWorkFlow() throws ApiException, InterruptedException {
log.info("******** PreBuilt Sequence Flow Completed ********");
}

private Consumer<WorkFlowDefinitionResponseDTO> getWorkFlowDefinitionResponseConsumer() {
return workFlowDefinition -> {
assertNotNull(workFlowDefinition.getId());
assertEquals(WORKFLOW_NAME, workFlowDefinition.getName());
assertEquals(WorkFlowDefinitionResponseDTO.ProcessingTypeEnum.SEQUENTIAL,
workFlowDefinition.getProcessingType());
assertEquals(WorkFlowDefinitionResponseDTO.TypeEnum.INFRASTRUCTURE, workFlowDefinition.getType());

assertNotNull(workFlowDefinition.getWorks());
assertEquals(1, workFlowDefinition.getWorks().size());
assertEquals("notificationTask", workFlowDefinition.getWorks().get(0).getName());
assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK,
workFlowDefinition.getWorks().get(0).getWorkType());
assertTrue(CollectionUtils.isEmpty(workFlowDefinition.getWorks().get(0).getWorks()));
assertNull(workFlowDefinition.getWorks().get(0).getProcessingType());
assertNotNull(workFlowDefinition.getWorks().get(0).getParameters());
};
}

}
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.redhat.parodos.flows;

import java.util.List;
import java.util.function.Consumer;

import com.redhat.parodos.flows.base.BaseIntegrationTest;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder;
import com.redhat.parodos.flows.common.WorkFlowTestBuilder.TestComponents;
import com.redhat.parodos.sdk.api.WorkflowApi;
import com.redhat.parodos.sdk.api.WorkflowDefinitionApi;
import com.redhat.parodos.sdk.invoker.ApiException;
import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO;
import com.redhat.parodos.sdk.model.WorkFlowRequestDTO;
Expand All @@ -14,6 +15,7 @@
import com.redhat.parodos.sdkutils.SdkUtils;
import com.redhat.parodos.workflow.consts.WorkFlowConstants;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;

import static org.junit.Assert.assertEquals;
Expand All @@ -23,39 +25,23 @@
* @author Richard Wang (Github: richrdW98)
*/
@Slf4j
public class SimpleRollbackWorkFlowTest extends BaseIntegrationTest {
public class SimpleRollbackWorkFlowTest {

private static final String WORKFLOW_NAME = "simpleFailedWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW;

@Test
public void runRollbackWorkFlow() throws ApiException, InterruptedException {
log.info("Running simple flow");

// GET simpleSequentialWorkFlow DEFINITIONS
WorkflowDefinitionApi workflowDefinitionApi = new WorkflowDefinitionApi();
List<WorkFlowDefinitionResponseDTO> simpleFailedWorkFlowDefinitions = workflowDefinitionApi
.getWorkFlowDefinitions("simpleFailedWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW);
assertEquals(1, simpleFailedWorkFlowDefinitions.size());

// GET WORKFLOW DEFINITION BY Id
WorkFlowDefinitionResponseDTO simpleSequentialWorkFlowDefinition = workflowDefinitionApi
.getWorkFlowDefinitionById(simpleFailedWorkFlowDefinitions.get(0).getId());

assertNotNull(simpleSequentialWorkFlowDefinition.getId());
assertEquals("simpleFailedWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW,
simpleSequentialWorkFlowDefinition.getName());
assertEquals(WorkFlowDefinitionResponseDTO.ProcessingTypeEnum.SEQUENTIAL,
simpleSequentialWorkFlowDefinition.getProcessingType());
assertEquals(WorkFlowDefinitionResponseDTO.TypeEnum.INFRASTRUCTURE,
simpleSequentialWorkFlowDefinition.getType());

// Define WorkRequests
log.info("******** Running The Simple WorkFlow ********");
TestComponents components = new WorkFlowTestBuilder().withDefaultProject()
.withWorkFlowDefinition(WORKFLOW_NAME, getWorkFlowDefinitionResponseConsumer()).build();

// Define WorkFlowRequest
WorkFlowRequestDTO workFlowRequestDTO = new WorkFlowRequestDTO();
workFlowRequestDTO.setProjectId(testProject.getId());
workFlowRequestDTO.setWorkFlowName("simpleFailedWorkFlow_INFRASTRUCTURE_WORKFLOW");
workFlowRequestDTO.setProjectId(components.project().getId());
workFlowRequestDTO.setWorkFlowName(WORKFLOW_NAME);
workFlowRequestDTO.setWorks(List.of());

WorkflowApi workflowApi = new WorkflowApi();
WorkflowApi workflowApi = new WorkflowApi(components.apiClient());
log.info("******** Running The Simple Failed Flow ********");

WorkFlowResponseDTO workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO);
Expand All @@ -74,4 +60,15 @@ public void runRollbackWorkFlow() throws ApiException, InterruptedException {
log.info("******** Simple Failed Flow Completed ********");
}

@NotNull
private static Consumer<WorkFlowDefinitionResponseDTO> getWorkFlowDefinitionResponseConsumer() {
return workFlowDefinition -> {
assertNotNull(workFlowDefinition.getId());
assertEquals(WORKFLOW_NAME, workFlowDefinition.getName());
assertEquals(WorkFlowDefinitionResponseDTO.ProcessingTypeEnum.SEQUENTIAL,
workFlowDefinition.getProcessingType());
assertEquals(WorkFlowDefinitionResponseDTO.TypeEnum.INFRASTRUCTURE, workFlowDefinition.getType());
};
}

}
Loading

0 comments on commit 88e1b7a

Please sign in to comment.