Skip to content

Commit

Permalink
refactor variable assignment naming
Browse files Browse the repository at this point in the history
  • Loading branch information
eduwercamacaro committed Dec 2, 2024
1 parent 979c869 commit c20416e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,11 @@ public interface WfRunVariable extends LHExpression {
WorkflowCondition isNotIn(Serializable rhs);

/**
* Mutates the value of this WfRunVariable and sets it to the the value provided on the RHS.
* Mutates the value of this WfRunVariable and sets it to the value provided on the RHS.
*
* If the LHS of this WfRunVariable is set, then the sub-element of this WfRunVariable
* provided by the Json Path is mutated.
* @param rhs is the value to set this WfRunVariable to.
*/
void assignTo(Serializable rhs);
void assign(Serializable rhs);
}
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public WorkflowConditionImpl isNotIn(Serializable rhs) {
}

@Override
public void assignTo(Serializable rhs) {
public void assign(Serializable rhs) {
parent.mutate(this, VariableMutationType.ASSIGN, rhs);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ void mutationsShouldUseVariableAssignment() {
// Deprecated the literal_value and node_output approach
Workflow workflow = new WorkflowImpl("obiwan", wf -> {
WfRunVariable myVar = wf.addVariable("my-var", VariableType.STR);
myVar.assignTo("some-value");
myVar.assign("some-value");
});

PutWfSpecRequest wfSpec = workflow.compileWorkflow();
Expand All @@ -570,7 +570,7 @@ void nodeOutputMutationsShouldAlsoUseVariableAssignments() {
// Deprecated the literal_value and node_output approach
Workflow workflow = new WorkflowImpl("obiwan", wf -> {
WfRunVariable myVar = wf.addVariable("my-var", VariableType.STR);
myVar.assignTo(wf.execute("use-the-force"));
myVar.assign(wf.execute("use-the-force"));
});

PutWfSpecRequest wfSpec = workflow.compileWorkflow();
Expand All @@ -590,7 +590,7 @@ void nodeOutputMutationsShouldCarryJsonPath() {
// Deprecated the literal_value and node_output approach
Workflow workflow = new WorkflowImpl("obiwan", wf -> {
WfRunVariable myVar = wf.addVariable("my-var", VariableType.STR);
myVar.assignTo(wf.execute("use-the-force").jsonPath("$.hello.there"));
myVar.assign(wf.execute("use-the-force").jsonPath("$.hello.there"));
});

PutWfSpecRequest wfSpec = workflow.compileWorkflow();
Expand All @@ -614,7 +614,7 @@ void assigningVariablesToOtherVariablesShouldUseVariableAssignment() {
Workflow workflow = new WorkflowImpl("obiwan", wf -> {
WfRunVariable myVar = wf.addVariable("my-var", VariableType.STR);
WfRunVariable otherVar = wf.addVariable("other-var", VariableType.STR);
myVar.assignTo(otherVar);
myVar.assign(otherVar);
});

PutWfSpecRequest wfSpec = workflow.compileWorkflow();
Expand All @@ -632,7 +632,7 @@ void assigningVariablesToOtherVariablesShouldCarryJsonPath() {
Workflow workflow = new WorkflowImpl("obiwan", wf -> {
WfRunVariable myVar = wf.addVariable("my-var", VariableType.STR);
WfRunVariable otherVar = wf.addVariable("other-var", VariableType.JSON_OBJ);
myVar.assignTo(otherVar.jsonPath("$.hello.there"));
myVar.assign(otherVar.jsonPath("$.hello.there"));
});

PutWfSpecRequest wfSpec = workflow.compileWorkflow();
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/java/e2e/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void shouldDoBasic() {
public Workflow getBasic() {
return new WorkflowImpl("test-basic", thread -> {
WfRunVariable asdf = thread.declareBool("asdf");
asdf.assignTo(thread.execute("ag-one"));
asdf.assign(thread.execute("ag-one"));
});
}

Expand Down
18 changes: 9 additions & 9 deletions server/src/test/java/e2e/ExpressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,22 @@ public Workflow getExpression() {
// EXTEND a String test
var myStr = wf.declareStr("my-str");
wf.doIf(myStr.isNotEqualTo(null), then -> {
myStr.assignTo(myStr.extend("-suffix"));
myStr.assign(myStr.extend("-suffix"));
});

// Add an int and composite expressions
var intToAdd = wf.declareInt("int-to-add");
var intToAddResult = wf.declareInt("int-to-add-result");
wf.doIf(intToAdd.isNotEqualTo(null), then -> {
// Tests compound expressions
intToAddResult.assignTo(wf.execute("expr-add-one", intToAdd.add(1)));
intToAddResult.assign(wf.execute("expr-add-one", intToAdd.add(1)));
});

// Division By Zero test
var thingToDivideByZero = wf.declareInt("thing-to-divide-by-zero");
var divideByZeroResult = wf.declareInt("divide-by-zero-result");
wf.doIf(thingToDivideByZero.isNotEqualTo(null), then -> {
divideByZeroResult.assignTo(thingToDivideByZero.divide(0));
divideByZeroResult.assign(thingToDivideByZero.divide(0));
});

// Test precision of arithmetic. Make use of the fact that we don't have
Expand All @@ -273,8 +273,8 @@ public Workflow getExpression() {
var divisionResultInt = wf.declareInt("division-result-int");
wf.doIf(divisionTestJson.isNotEqualTo(null), then -> {
LHExpression foobar = divisionTestJson.jsonPath("$.lhs").divide(divisionTestJson.jsonPath("$.rhs"));
divisionResult.assignTo(foobar);
divisionResultInt.assignTo(foobar);
divisionResult.assign(foobar);
divisionResultInt.assign(foobar);
});

// This test uses a complex expression where the things we are computing over
Expand All @@ -289,20 +289,20 @@ public Workflow getExpression() {
// TotalPrice = Quantity * Price * (1 - DiscountPercentage / 100)
LHExpression pedro =
quantity.multiply(price).multiply(wf.subtract(1.0, discountPercentage.divide(100.0)));
totalPriceInt.assignTo(pedro);
totalPriceDouble.assignTo(pedro);
totalPriceInt.assign(pedro);
totalPriceDouble.assign(pedro);
});

// Test mutating sub-fields of a json object
var json = wf.declareJsonObj("json");
wf.doIf(json.isNotEqualTo(null), then -> {
json.jsonPath("$.foo").assignTo("bar");
json.jsonPath("$.foo").assign("bar");
});

// Test mutating doubly-nested fields of a Json Object
var nestedJson = wf.declareJsonObj("nested-json");
wf.doIf(nestedJson.isNotEqualTo(null), then -> {
nestedJson.jsonPath("$.foo.bar").assignTo("baz");
nestedJson.jsonPath("$.foo.bar").assign("baz");
});
});
}
Expand Down

0 comments on commit c20416e

Please sign in to comment.