10. @cucumberbdd#Devoxx @citrus_test
Feature: Create voting
As a user I want to create new votings. Each voting is given default vote
options.
Scenario: Default voting options
Given voting title "Do you like Devoxx?"
When I create new voting
Then voting should have 2 options
And voting should have option "yes"
And voting should have option "no"
And voting title should be "Do you like Devoxx?“
Feature specification
11. @cucumberbdd#Devoxx @citrus_test
Feature: Create voting
As a user I want to create new votings. Each voting is given default vote
options. The user should be able to set custom vote options.
Scenario: Default voting options
Given voting title "Do you like Devoxx?"
When I create new voting
Then voting should have 2 options
And voting should have option "yes"
And voting should have option "no"
And voting title should be "Do you like Devoxx?"
Scenario: Custom voting options
When I create new voting "What type of Devoxx ticket do you have?"
And voting options are "University:Conference:Combi"
Then voting title should be "What type of Devoxx ticket do you have?"
And voting should have options
| University |
| Conference |
| Combi |
Feature specification
13. @cucumberbdd#Devoxx @citrus_test
@RunWith(Cucumber.class)
public class VotingFeatureTest {
}
JUnit Cucumber test
voting-close.feature
voting-create.feature
voting-results.feature
public class VotingSteps {
@Given("^New default voting$")
public void defaultVoting() { ... }
@When("^I create new voting "(.+)"$")
public void createVotingWithTitle(String title) { ... }
@Then("^voting should have (d+) options$")
public void votingShouldHaveOptions(int optionCount) { ... }
}
14. @cucumberbdd#Devoxx @citrus_test
@When("^I create new voting "(.+)"$")
public void createVotingWithTitle(String title) {
votingId = UUID.randomUUID();
Voting voting = new Voting(votingId, title);
votingService.add(voting);
}
Step definitions
@Then("^voting should have (d+) options$")
public void votingShouldHaveOptions(int optionCount) {
Assert.assertEquals(optionCount,
votingService.get(votingId).getOptions().size());
}
When I create new voting "What type of Devoxx ticket do you have?“
Then voting should have 3 options
15. @cucumberbdd#Devoxx @citrus_test
@Then("^(?:the )?voting should have options$")
public void votingShouldHaveOptions(DataTable dataTable) {
List<String> options = dataTable.asList(String.class);
votingShouldHaveOptions(options.size());
for(String option : options) {
votingShouldHaveOption(option);
}
}
Data tables
Then voting should have options
| University |
| Conference |
| Combi |
17. @cucumberbdd#Devoxx @citrus_test
Feature: Show voting results
As a user I want to vote for an option. All voting results are stored
and the user should be able to get top vote option for each voting.
Background:
Given I create new voting "Do you like Devoxx?"
And voting options are "yes:no"
Scenario: Initial vote results
Then votes of option "yes" should be 0
And votes of option "no" should be 0
Scenario: Get vote results
When I vote for "yes"
Then votes of option "yes" should be 1
And votes of option "no" should be 0
And top vote should be "yes"
Background
18. @cucumberbdd#Devoxx @citrus_test
Feature: Show voting results
As a user I want to vote for an option. All voting results are stored
and the user should be able to get top vote option for each voting.
Scenario Outline: Get vote results
Given I create new voting "<title>"
And voting options are "yes:no"
When I vote for "yes" <yes_votes> times
And I vote for "no" <no_votes> times
Then votes of option "yes" should be <yes_votes>
And votes of option "no" should be <no_votes>
And top vote should be "<top_vote>"
Examples:
| title | yes_votes | no_votes | top_vote |
| Did you enjoy the salad? | 12 | 5 | yes |
| Did you enjoy the crab sandwich? | 1 | 25 | no |
Scenario Outline
24. @cucumberbdd#Devoxx @citrus_test
Feature: Voting Http REST API
Background:
Given Voting list is empty
And New voting "Do you like Belgian beer?"
And voting options are "yes:no"
Scenario: Top vote
When client creates the voting
And client votes for "no"
Then votes should be
| yes | 0 |
| no | 1 |
And top vote should be "no"
Scenario: Close voting
Given reporting is enabled
When client creates the voting
And client votes for "yes" 3 times
And client votes for "no" 2 times
And client closes the voting
Then participants should receive reporting mail
"""
Dear participants,
the voting '${title}' came to an end.
The top answer is 'yes'!
Have a nice day!
Your Voting-App Team
"""
Messaging feature
25. @cucumberbdd#Devoxx @citrus_test
public class VotingRestSteps {
@CitrusEndpoint
private HttpClient votingClient;
@CitrusEndpoint
private MailServer mailServer;
@CitrusResource
private TestRunner runner;
@Given("^Voting list is empty$")
public void clear() {
runner.http(action -> action.client(votingClient)
.send()
.delete("/voting"));
runner.http(action -> action.client(votingClient)
.receive()
.response(HttpStatus.OK));
}
}
Endpoint Injection
26. @cucumberbdd#Devoxx @citrus_test
@Configuration
public class CitrusEndpointConfig {
@Bean
public HttpClient votingClient() {
return CitrusEndpoints.http()
.client()
.requestUrl("http://localhost:8080/rest/services")
.build();
}
@Bean
public MailServer mailServer() {
return CitrusEndpoints.mail()
.server()
.port(2222)
.autoStart(true)
.autoAccept(true)
.build();
}
}
Endpoint Configuration
27. @cucumberbdd#Devoxx @citrus_test
Citrus endpoints
Component Description
citrus-http Http REST client and server
citrus-jms JMS queue or topic destination
citrus-ws SOAP client and server
citrus-mail SMTP mail client and server
citrus-docker Docker container management
citrus-camel Apache Camel endpoint
citrus-selenium Selenium browser endpoint
citrus-vertx Vert.x endpoint
citrus-kubernetes Kubernetes client
…