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

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lshannon committed Mar 23, 2023
1 parent 1c9364a commit 129754f
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 600 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,9 @@ public class WorkFlowConstants {
// Id of a workflow that can 'undo' the actions of a previously executed WorkFlow
public static final String ROLL_BACK_WORKFLOW_NAME = "ROLL_BACK_WORKFLOW_NAME";

// The results of the Assessment will be stored in the WorkContext using this label
public static final String RESULTING_INFRASTRUCTURE_OPTIONS = "RESULTING_INFRASTRUCTURE_OPTIONS";

// This should be appended to the name of the Workflow so it can be filtered correctly
public static final String ASSESSMENT_WORKFLOW = "_ASSESSMENT_WORKFLOW";

// An entity generated with all WorkFlow executions
public static final String WORKFLOW_EXECUTION_ENTITY_REFERENCES = "WORKFLOW_EXECUTION_ENTITY_REFERENCES";

// The type of the WorkFlow
public static final String WORKFLOW_TYPE = "WORKFLOW_TYPE";

// This is used when you need to specify an assessment to determine if follow on
// workflow can be executed
public static final String WORKFLOW_CHECKER_ID = "WORKFLOW_CHECKER_ID";

// The arguments for the WorkFlow Checker to run. As these might be runtime values
// they will be persisted in the WorkFlowTransactionDTO
public static final String WORKFLOW_CHECKER_ARGUMENTS = "WORKFLOW_CHECKER_ARGUMENTS";

public static final String CURRENT_WORKFLOW_ID = "CURRENT_WORKFLOW_ID";

// This is for an WorkFlowChecker to store the value of the next WorkFlow to run in a
// WorkFlowTransactionDTO
public static final String NEXT_WORKFLOW_ID = "NEXT_WORKFLOW_ID";

// These arguments are for passing values from the WorkFlowChecker to the next
// WorkFlow to run
public static final String NEXT_WORKFLOW_ARGUMENTS = "NEXT_WORKFLOW_ARGUMENTS";

// Ensures this class is only used to obtain the constants
private WorkFlowConstants() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
*/
package com.redhat.parodos.workflow.task;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.springframework.beans.factory.BeanNameAware;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.redhat.parodos.workflow.context.WorkContextDelegate;
Expand All @@ -24,12 +31,6 @@

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanNameAware;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
* Base Class for a WorkFlowTask.
Expand All @@ -50,8 +51,9 @@ public abstract class BaseWorkFlowTask implements WorkFlowTask, BeanNameAware {
public void setBeanName(String name) {
this.name = name;
}

// WorkFlowChecker check a process that has been initiated by a WorkFlow to see if its been completed

// WorkFlowChecker check a process that has been initiated by a WorkFlow to see if its
// been completed
private List<WorkFlow> workFlowCheckers;

public List<WorkFlow> getWorkFlowCheckers() {
Expand All @@ -62,7 +64,15 @@ public void setWorkFlowCheckers(List<WorkFlow> workFlowCheckers) {
this.workFlowCheckers = workFlowCheckers;
}

public String getParameterValue(WorkContext workContext, String parameterName) throws MissingParameterException {
/**
* Get Parameters specific to this WorkFlowTask, this is a required parameter
* @param workContext
* @param parameterName
* @return String value for the Parameter name
* @throws MissingParameterException
*/
public String getRequiredParameterValue(WorkContext workContext, String parameterName)
throws MissingParameterException {
Map<String, String> parameters = Optional
.ofNullable(new ObjectMapper().convertValue(
WorkContextDelegate.read(workContext, WorkContextDelegate.ProcessType.WORKFLOW_TASK_EXECUTION,
Expand All @@ -74,10 +84,37 @@ public String getParameterValue(WorkContext workContext, String parameterName) t
return parameters.entrySet().stream().filter(entry -> parameterName.equals(entry.getKey()))
.map(Map.Entry::getValue).findFirst().orElseThrow(() -> {
log.error(String.format("parameter %s is not provided for task %s!", parameterName, name));
return new MissingParameterException("missing parameter(s)");
return new MissingParameterException("missing parameter(s) for ParameterName: " + parameterName);
});
}

/**
* Gets an optional parameter. Returns the defaultValue if not found
* @param workContext
* @param parameterName
* @param defaultValue
* @return
* @throws MissingParameterException
*/
public String getOptionalParameterValue(WorkContext workContext, String parameterName, String defaultValue) {
Map<String, String> parameters = Optional
.ofNullable(new ObjectMapper().convertValue(
WorkContextDelegate.read(workContext, WorkContextDelegate.ProcessType.WORKFLOW_TASK_EXECUTION,
name, WorkContextDelegate.Resource.ARGUMENTS),
new TypeReference<HashMap<String, String>>() {
}))
.orElse(new HashMap<>());
parameters.putAll(getParentParameters(workContext, getName()));
return parameters.entrySet().stream().filter(entry -> parameterName.equals(entry.getKey()))
.map(Map.Entry::getValue).findFirst().orElse(defaultValue);
}

/**
* Get Parameters that are set at the WorkFlow level
* @param workContext
* @param workName
* @return
*/
private Map<String, String> getParentParameters(WorkContext workContext, String workName) {
String parentWorkflowName = (String) WorkContextDelegate.read(workContext,
WorkContextDelegate.ProcessType.WORKFLOW_EXECUTION, workName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
*/
package com.redhat.parodos.workflow.task;

import com.redhat.parodos.workflow.task.enums.WorkFlowTaskOutput;
import java.util.Collections;
import java.util.List;

import com.redhat.parodos.workflow.task.enums.WorkFlowTaskOutput;
import com.redhat.parodos.workflow.task.parameter.WorkFlowTaskParameter;
import com.redhat.parodos.workflows.work.Work;

import lombok.NonNull;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public abstract class BaseInfrastructureWorkFlowTask extends BaseWorkFlowTask {

private WorkFlowTaskType type = WorkFlowTaskType.INFRASTRUCTURE;


public WorkFlowTaskType getType() {
return type;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.redhat.parodos.workflow.task.version;

import org.springframework.beans.factory.annotation.Value;

public class GithubVersionManager implements VersionManager {

@Value("${gitPropertiesFileLocation}")
String gitPropertiesFileLocation;

@Override
public String getVersion() {
// we using this gitPropertiesFileLocation to find the git props and find the
// version
return null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.redhat.parodos.workflow.task.version;

public interface VersionManager {

String getVersion();

}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void verifyParameter() throws MissingParameterException {

BaseWorkFlowTask flowTask = (BaseWorkFlowTask) task;
flowTask.setBeanName("Test");
assertEquals("test", flowTask.getParameterValue(context, "username"));
assertEquals("test", flowTask.getRequiredParameterValue(context, "username"));
}

@Test(expected = MissingParameterException.class)
Expand All @@ -106,7 +106,7 @@ public void noParameters() throws MissingParameterException {

BaseWorkFlowTask flowTask = (BaseWorkFlowTask) task;
flowTask.setBeanName("Test");
assertEquals("Test", flowTask.getParameterValue(context, "username"));
assertEquals("Test", flowTask.getRequiredParameterValue(context, "username"));
}

@Test
Expand Down
Loading

0 comments on commit 129754f

Please sign in to comment.