-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix bug form replied and if condition #155
Merged
yinan-symphony
merged 3 commits into
finos:master
from
symphony-soufiane:fix-bug-form-replied-and-if-conditio
Oct 6, 2022
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.ArgumentMatchers.eq; | ||
import static org.mockito.Mockito.atLeast; | ||
import static org.mockito.Mockito.clearInvocations; | ||
import static org.mockito.Mockito.timeout; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
@@ -22,6 +23,9 @@ | |
import org.apache.commons.lang3.StringEscapeUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import java.util.Collections; | ||
import java.util.concurrent.TimeUnit; | ||
|
@@ -306,8 +310,7 @@ void sendFormOutputsArePreserved() throws Exception { | |
return true; | ||
}); | ||
|
||
assertThat(workflow) | ||
.executed("init", "check"); | ||
assertThat(workflow).executed("init", "check"); | ||
} | ||
|
||
@Test | ||
|
@@ -353,4 +356,80 @@ void sendMessageUpdateMessage() throws Exception { | |
assertThat(workflow).executed("init", "message-received_/hey", "update"); | ||
}); | ||
} | ||
|
||
@Test | ||
void formRepliedSendMessageOnConditionIf() throws Exception { | ||
Workflow workflow = | ||
SwadlParser.fromYaml(getClass().getResourceAsStream("/form/send-form-reply-conditional.swadl.yaml")); | ||
|
||
when(messageService.send(anyString(), any(Message.class))).thenReturn(message("msgId")); | ||
|
||
engine.deploy(workflow); | ||
|
||
// trigger workflow execution | ||
engine.onEvent(messageReceived("/test")); | ||
verify(messageService, timeout(5000)).send(anyString(), contains("form")); | ||
clearInvocations(messageService); | ||
|
||
await().atMost(5, TimeUnit.SECONDS).ignoreExceptions().until(() -> { | ||
engine.onEvent(form("msgId", "testForm", Collections.singletonMap("action", "create"))); | ||
return true; | ||
}); | ||
verify(messageService, timeout(5000)).send(anyString(), contains("Create")); | ||
|
||
Thread.sleep(1000); | ||
assertThat(workflow).executed(workflow, "testForm", "resCreate"); | ||
} | ||
|
||
@Test | ||
void formRepliedSendMessageOnConditionElse() throws Exception { | ||
Workflow workflow = | ||
SwadlParser.fromYaml(getClass().getResourceAsStream("/form/send-form-reply-conditional.swadl.yaml")); | ||
|
||
when(messageService.send(anyString(), any(Message.class))).thenReturn(message("msgId")); | ||
|
||
engine.deploy(workflow); | ||
|
||
// trigger workflow execution | ||
engine.onEvent(messageReceived("/test")); | ||
verify(messageService, timeout(5000)).send(anyString(), contains("form")); | ||
clearInvocations(messageService); | ||
|
||
await().atMost(5, TimeUnit.SECONDS).ignoreExceptions().until(() -> { | ||
engine.onEvent(form("msgId", "testForm", Collections.singletonMap("action", "menu"))); | ||
return true; | ||
}); | ||
verify(messageService, timeout(5000)).send(anyString(), contains("Menu")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here |
||
clearInvocations(messageService); | ||
|
||
sleepToTimeout(1000); | ||
engine.onEvent(messageReceived("/continue")); | ||
verify(messageService, timeout(5000)).send(anyString(), contains("DONE")); | ||
|
||
assertThat(workflow).executed(workflow, "testForm", "resMenu", "finish"); | ||
} | ||
|
||
@ParameterizedTest | ||
@CsvSource(value = {"GOOG,response0", "GOOGLE,response1"}) | ||
void formReplied_fork_condition_join_activity(String tickerValue, String expectedActivity) throws Exception { | ||
Workflow workflow = | ||
SwadlParser.fromYaml(getClass().getResourceAsStream("/form/send-form-reply-join-activity.swadl.yaml")); | ||
|
||
when(messageService.send(anyString(), any(Message.class))).thenReturn(message("msgId")); | ||
|
||
engine.deploy(workflow); | ||
|
||
// trigger workflow execution | ||
engine.onEvent(messageReceived("/go")); | ||
verify(messageService, timeout(2000)).send(anyString(), contains("form")); | ||
clearInvocations(messageService); | ||
|
||
await().atMost(5, TimeUnit.SECONDS).ignoreExceptions().until(() -> { | ||
engine.onEvent(form("msgId", "sendForm", Collections.singletonMap("ticker", tickerValue))); | ||
return true; | ||
}); | ||
verify(messageService, timeout(2000)).send(anyString(), contains("END")); | ||
|
||
assertThat(workflow).executed(workflow, "sendForm", expectedActivity, "response2"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this verifies what you think.
In line 337, we verify that we sent the form (content contains the word form).
In line 343, we want to verify that we sent a the message "Create". I don't know why Mockito.verify does not get updated, and it gets applied on the first one. So both Mockito.verify applies on the first messageService.send(..), which contains both "form" and "Create" words.
If you change the activity "resCreate" in swadl to send something else than "Create", let's say "CreateABC", and you change the test with (contains("CreateABC")), the test will fail.. One way to force Mockito.verify to apply to the new sendMessage call, is to change the to.streamId="" to a different one and replace anyString() in verify(..).
verify(messageService, timeout(5000)).send("ANOTHER_STREAM_ID", contains("SOMETHING_DIFF_FROM_CREATE"));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, i see your point, i add then the Mockito.clearInvocations(T mock) to clear the invocations on messageService mock after each verify, so that we are sure we have the right verification.