diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/ComplexWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/ComplexWorkFlowTest.java index 49ca6d1d3..336d576de 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/ComplexWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/ComplexWorkFlowTest.java @@ -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; @@ -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); @@ -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); @@ -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); diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/EscalationFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/EscalationFlowTest.java index d2f0e629c..80c331651 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/EscalationFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/EscalationFlowTest.java @@ -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; @@ -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, @@ -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()); } } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java index c5e054120..f695dfa0c 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/PrebuiltWorkFlowTest.java @@ -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; @@ -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 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(); @@ -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); @@ -90,4 +68,23 @@ public void runPreBuiltWorkFlow() throws ApiException, InterruptedException { log.info("******** PreBuilt Sequence Flow Completed ********"); } + private Consumer 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()); + }; + } + } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleRollbackWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleRollbackWorkFlowTest.java index b87be30bb..34eed1bdd 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleRollbackWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleRollbackWorkFlowTest.java @@ -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; @@ -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; @@ -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 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); @@ -74,4 +60,15 @@ public void runRollbackWorkFlow() throws ApiException, InterruptedException { log.info("******** Simple Failed Flow Completed ********"); } + @NotNull + private static Consumer getWorkFlowDefinitionResponseConsumer() { + return workFlowDefinition -> { + assertNotNull(workFlowDefinition.getId()); + assertEquals(WORKFLOW_NAME, workFlowDefinition.getName()); + assertEquals(WorkFlowDefinitionResponseDTO.ProcessingTypeEnum.SEQUENTIAL, + workFlowDefinition.getProcessingType()); + assertEquals(WorkFlowDefinitionResponseDTO.TypeEnum.INFRASTRUCTURE, workFlowDefinition.getType()); + }; + } + } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java index 944ffb0b5..ee1e559ab 100644 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/SimpleWorkFlowTest.java @@ -3,14 +3,17 @@ import java.util.Arrays; import java.util.Collections; 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; import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO; +import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO.ProcessingTypeEnum; +import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO.TypeEnum; import com.redhat.parodos.sdk.model.WorkFlowRequestDTO; import com.redhat.parodos.sdk.model.WorkFlowResponseDTO; import com.redhat.parodos.sdk.model.WorkFlowResponseDTO.WorkStatusEnum; @@ -32,45 +35,15 @@ * @author Gloria Ciavarrini (Github: gciavarrini) */ @Slf4j -public class SimpleWorkFlowTest extends BaseIntegrationTest { +public class SimpleWorkFlowTest { + + private static final String WORKFLOW_NAME = "simpleSequentialWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW; @Test public void runSimpleWorkFlow() throws ApiException, InterruptedException { - log.info("Running simple flow"); - - // GET simpleSequentialWorkFlow DEFINITIONS - WorkflowDefinitionApi workflowDefinitionApi = new WorkflowDefinitionApi(); - List simpleSequentialWorkFlowDefinitions = workflowDefinitionApi - .getWorkFlowDefinitions("simpleSequentialWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW); - assertEquals(1, simpleSequentialWorkFlowDefinitions.size()); - - // GET WORKFLOW DEFINITION BY Id - WorkFlowDefinitionResponseDTO simpleSequentialWorkFlowDefinition = workflowDefinitionApi - .getWorkFlowDefinitionById(simpleSequentialWorkFlowDefinitions.get(0).getId()); - - assertNotNull(simpleSequentialWorkFlowDefinition.getId()); - assertEquals("simpleSequentialWorkFlow" + WorkFlowConstants.INFRASTRUCTURE_WORKFLOW, - simpleSequentialWorkFlowDefinition.getName()); - assertEquals(WorkFlowDefinitionResponseDTO.ProcessingTypeEnum.SEQUENTIAL, - simpleSequentialWorkFlowDefinition.getProcessingType()); - assertEquals(WorkFlowDefinitionResponseDTO.TypeEnum.INFRASTRUCTURE, - simpleSequentialWorkFlowDefinition.getType()); - - assertNotNull(simpleSequentialWorkFlowDefinition.getWorks()); - assertEquals(2, simpleSequentialWorkFlowDefinition.getWorks().size()); - assertEquals("restCallTask", simpleSequentialWorkFlowDefinition.getWorks().get(0).getName()); - assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, - simpleSequentialWorkFlowDefinition.getWorks().get(0).getWorkType()); - assertTrue(CollectionUtils.isEmpty(simpleSequentialWorkFlowDefinition.getWorks().get(0).getWorks())); - assertNull(simpleSequentialWorkFlowDefinition.getWorks().get(0).getProcessingType()); - assertNotNull(simpleSequentialWorkFlowDefinition.getWorks().get(0).getParameters()); - - assertEquals("loggingTask", simpleSequentialWorkFlowDefinition.getWorks().get(1).getName()); - assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, - simpleSequentialWorkFlowDefinition.getWorks().get(1).getWorkType()); - assertTrue(CollectionUtils.isEmpty(simpleSequentialWorkFlowDefinition.getWorks().get(1).getWorks())); - assertNull(simpleSequentialWorkFlowDefinition.getWorks().get(1).getProcessingType()); - assertNotNull(simpleSequentialWorkFlowDefinition.getWorks().get(1).getParameters()); + log.info("******** Running The Simple WorkFlow ********"); + TestComponents components = new WorkFlowTestBuilder().withDefaultProject() + .withWorkFlowDefinition(WORKFLOW_NAME, getWorkFlowDefinitionResponseConsumer()).build(); // Define WorkRequests WorkRequestDTO work1 = new WorkRequestDTO(); @@ -80,18 +53,17 @@ public void runSimpleWorkFlow() throws ApiException, InterruptedException { WorkRequestDTO work2 = new WorkRequestDTO(); work2.setWorkName("loggingTask"); - work2.setArguments(Arrays.asList(new ArgumentRequestDTO().key("user-id").value("test-user-id"), + work2.setArguments(List.of(new ArgumentRequestDTO().key("user-id").value("test-user-id"), new ArgumentRequestDTO().key("api-server").value("test-api-server"))); // Define WorkFlowRequest WorkFlowRequestDTO workFlowRequestDTO = new WorkFlowRequestDTO(); - workFlowRequestDTO.setProjectId(testProject.getId()); - workFlowRequestDTO.setWorkFlowName("simpleSequentialWorkFlow_INFRASTRUCTURE_WORKFLOW"); + workFlowRequestDTO.setProjectId(components.project().getId()); + workFlowRequestDTO.setWorkFlowName(WORKFLOW_NAME); workFlowRequestDTO.setWorks(Arrays.asList(work1, work2)); - WorkflowApi workflowApi = new WorkflowApi(); log.info("******** Running The Simple Sequence Flow ********"); - + WorkflowApi workflowApi = new WorkflowApi(components.apiClient()); WorkFlowResponseDTO workFlowResponseDTO = workflowApi.execute(workFlowRequestDTO); assertNotNull(workFlowResponseDTO.getWorkFlowExecutionId()); @@ -109,4 +81,29 @@ public void runSimpleWorkFlow() throws ApiException, InterruptedException { log.info("******** Simple Sequence Flow Completed ********"); } + private static Consumer getWorkFlowDefinitionResponseConsumer() { + return workFlowDefinition -> { + assertNotNull(workFlowDefinition.getId()); + assertEquals(WORKFLOW_NAME, workFlowDefinition.getName()); + assertEquals(ProcessingTypeEnum.SEQUENTIAL, workFlowDefinition.getProcessingType()); + assertEquals(TypeEnum.INFRASTRUCTURE, workFlowDefinition.getType()); + + assertNotNull(workFlowDefinition.getWorks()); + assertEquals(2, workFlowDefinition.getWorks().size()); + assertEquals("restCallTask", 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()); + + assertEquals("loggingTask", workFlowDefinition.getWorks().get(1).getName()); + assertEquals(WorkDefinitionResponseDTO.WorkTypeEnum.TASK, + workFlowDefinition.getWorks().get(1).getWorkType()); + assertTrue(CollectionUtils.isEmpty(workFlowDefinition.getWorks().get(1).getWorks())); + assertNull(workFlowDefinition.getWorks().get(1).getProcessingType()); + assertNotNull(workFlowDefinition.getWorks().get(1).getParameters()); + }; + } + } diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/base/BaseIntegrationTest.java b/integration-tests/src/test/java/com/redhat/parodos/flows/base/BaseIntegrationTest.java deleted file mode 100644 index 4c207b289..000000000 --- a/integration-tests/src/test/java/com/redhat/parodos/flows/base/BaseIntegrationTest.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.redhat.parodos.flows.base; - -import com.redhat.parodos.sdk.invoker.ApiClient; -import com.redhat.parodos.sdk.invoker.ApiException; -import com.redhat.parodos.sdk.model.ProjectResponseDTO; -import com.redhat.parodos.sdkutils.SdkUtils; -import org.junit.Before; - -import static com.redhat.parodos.sdkutils.SdkUtils.getParodosAPiClient; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -/** - * @author Gloria Ciavarrini (Github: gciavarrini) - */ -public class BaseIntegrationTest { - - private static final String projectName = "project-1"; - - private static final String projectDescription = "an example project"; - - protected ApiClient apiClient; - - protected ProjectResponseDTO testProject; - - @Before - public void setUp() throws ApiException, InterruptedException { - apiClient = getParodosAPiClient(); - initProject(); - } - - private void initProject() throws ApiException { - this.testProject = SdkUtils.getProjectAsync(apiClient, projectName, projectDescription); - assertNotNull(testProject); - } - -} diff --git a/integration-tests/src/test/java/com/redhat/parodos/flows/common/WorkFlowTestBuilder.java b/integration-tests/src/test/java/com/redhat/parodos/flows/common/WorkFlowTestBuilder.java new file mode 100644 index 000000000..38f63bd59 --- /dev/null +++ b/integration-tests/src/test/java/com/redhat/parodos/flows/common/WorkFlowTestBuilder.java @@ -0,0 +1,112 @@ +package com.redhat.parodos.flows.common; + +import java.util.List; +import java.util.function.Consumer; + +import com.redhat.parodos.sdk.api.WorkflowDefinitionApi; +import com.redhat.parodos.sdk.invoker.ApiClient; +import com.redhat.parodos.sdk.invoker.ApiException; +import com.redhat.parodos.sdk.model.ProjectResponseDTO; +import com.redhat.parodos.sdk.model.WorkFlowDefinitionResponseDTO; +import com.redhat.parodos.sdkutils.SdkUtils; + +import static com.redhat.parodos.sdkutils.SdkUtils.getParodosAPiClient; +import static org.assertj.core.api.Assertions.assertThat; + +public class WorkFlowTestBuilder { + + private static final String DEFAULT_PROJECT_NAME = "project-1"; + + private static final String DEFAULT_PROJECT_DESCRIPTION = "an example project"; + + private ProjectResponseDTO testProject; + + private String projectName; + + private String projectDescription; + + private String workFlowName; + + private ApiClient apiClient; + + private Consumer workFlowDefinitionConsumer; + + public WorkFlowTestBuilder withDefaultProject() { + this.projectName = DEFAULT_PROJECT_NAME; + this.projectDescription = DEFAULT_PROJECT_DESCRIPTION; + return this; + } + + public WorkFlowTestBuilder withProject(String projectName, String projectDescription) { + assertThat(projectName).isNotBlank(); + assertThat(projectDescription).isNotBlank(); + this.projectName = projectName; + this.projectDescription = projectDescription; + return this; + } + + private void setupProject() throws ApiException { + this.testProject = SdkUtils.getProjectAsync(apiClient, projectName, projectDescription); + assertThat(testProject).isNotNull(); + } + + public TestComponents build() { + try { + setupClient(); + setupProject(); + setupWorkFlowDefinition(); + } + catch (InterruptedException | ApiException e) { + throw new RuntimeException(e); + } + + return new TestComponents(apiClient, testProject); + } + + // Test two methods to retrieve the workflow definition: one by name and one by id + // The consumer is used to test the workflow definition. + private void setupWorkFlowDefinition() throws ApiException { + WorkflowDefinitionApi workflowDefinitionApi = new WorkflowDefinitionApi(apiClient); + + // Get workflow definition by name + List workFlowDefinitions = workflowDefinitionApi + .getWorkFlowDefinitions(workFlowName); + assertThat(workFlowDefinitions.size()).isEqualTo(1); + assertThat(workFlowDefinitions.get(0)).isNotNull(); + assertThat(workFlowDefinitions.get(0).getName()).isEqualTo(workFlowName); + assertThat(workFlowDefinitions.get(0).getId()).isNotNull(); + + // Get workflow definition by ID + WorkFlowDefinitionResponseDTO workFlowDefinition = workflowDefinitionApi + .getWorkFlowDefinitionById(workFlowDefinitions.get(0).getId()); + + workFlowDefinitionConsumer.accept(workFlowDefinition); + } + + private void setupClient() throws InterruptedException, ApiException { + apiClient = getParodosAPiClient(); + assertThat(apiClient).isNotNull(); + } + + public WorkFlowTestBuilder withWorkFlowDefinition(String workflowName, + Consumer consumer) { + assertThat(workflowName).isNotBlank(); + this.workFlowName = workflowName; + this.workFlowDefinitionConsumer = consumer; + return this; + } + + public WorkFlowTestBuilder withWorkFlowDefinition(String workflowName) { + assertThat(workflowName).isNotBlank(); + this.workFlowName = workflowName; + this.workFlowDefinitionConsumer = (workFlowDefinition) -> { + assertThat(workFlowDefinition.getId()).isNotNull(); + assertThat(workFlowDefinition.getName()).isEqualTo(workflowName); + }; + return this; + } + + public record TestComponents(ApiClient apiClient, ProjectResponseDTO project) { + } + +}