SlideShare a Scribd company logo
#DevoxxUS
Behavior driven
integration
with
Cucumber & Citrus
Christoph Deppisch
ConSol Software GmbH
@cucumberbdd @citrus_test
#DevoxxUS @citrus_test
http://cucumber.io
http://citrusframework.org
@cucumberbdd
#DevoxxUS
Behavior Driven
Development
@citrus_test@cucumberbdd
#DevoxxUS
Communication
@citrus_test@cucumberbdd
#DevoxxUS @citrus_test
=
@cucumberbdd
#DevoxxUS
Explaining the
behavior
@citrus_test@cucumberbdd
#DevoxxUS
Concrete
Examples
@citrus_test@cucumberbdd
#DevoxxUS
Given a certain context
When some event happens
Then an outcome should occur
@citrus_test
Gherkin
@cucumberbdd
#DevoxxUS
Voting application
@citrus_test@cucumberbdd
#DevoxxUS
Feature specification
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 Mondays?"

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 Mondays?"
@citrus_test@cucumberbdd
#DevoxxUS
Feature specification continued
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 Mondays?"

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 Mondays?"



Scenario: Custom voting options

When I create new voting "What is your favorite color?"

And voting options are "green:red:blue"

Then voting title should be "What is your favorite color?"

And voting should have options

| green |

| red |

| blue |
@citrus_test@cucumberbdd
#DevoxxUS @citrus_test@cucumberbdd
#DevoxxUS
JUnit Cucumber test
@RunWith(Cucumber.class)

public class VotingFeatureTest {

}
@citrus_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) { ... } 

}
@cucumberbdd
#DevoxxUS
Step definitions
@When("^I create new voting "(.+)"$")

public void createVotingWithTitle(String title) {

votingId = UUID.randomUUID();

Voting voting = new Voting(votingId, title);

votingService.add(voting);

}
@citrus_test
@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 is your favorite color?"
Then voting should have 3 options
@cucumberbdd
#DevoxxUS
Data tables
@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);

}

}
@citrus_test
Then voting should have options

| green |

| red |

| blue |
@cucumberbdd
#DevoxxUS @citrus_test
Demo
@cucumberbdd
#DevoxxUS
Hooks
@Before

public void before(Scenario scenario) {

// do something

}


@After

public void after(Scenario scenario) {

// do something

}
@citrus_test@cucumberbdd
#DevoxxUS
Background
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 cucumbers?"

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"
@citrus_test@cucumberbdd
#DevoxxUS
Scenario Outline
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 |

| Do you like hotdogs? | 12 | 5 | yes |

| Do you like crap sandwiches? | 1 | 25 | no |
@citrus_test@cucumberbdd
#DevoxxUS @citrus_test@cucumberbdd
#DevoxxUS
Messaging
Integration
@citrus_test@cucumberbdd
#DevoxxUS @citrus_test
Client VotingApp
Http REST
JMS
Reporting
MailServer
JMS
SMTP
@cucumberbdd
#DevoxxUS @citrus_test
VotingApp
Http REST
JMS
JMS
SMTP
@cucumberbdd
#DevoxxUS
Citrus Object Factory
cucumber.api.java.ObjectFactory=cucumber.runtime.java.CitrusObjectFactory
@citrus_test
cucumber.properties
@RunWith(Cucumber.class)

@CucumberOptions(plugin = { "com.consol.citrus.cucumber.CitrusReporter" } )

public class VotingRestFeatureIT {


}
@cucumberbdd
#DevoxxUS
Messaging Feature
Feature: Voting Http REST API



Background:

Given Voting list is empty

And New voting "Do you like donuts?"

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

"""
@citrus_test@cucumberbdd
#DevoxxUS
Endpoint injection
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));

}
}
@citrus_test@cucumberbdd
#DevoxxUS
Endpoint configuration
@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();

}

}
@citrus_test@cucumberbdd
#DevoxxUS
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
…
@cucumberbdd @citrus_test
#DevoxxUS
Http REST messaging
@Given("^New voting "([^"]+)"$")

public void newVoting(String title) {

runner.variable("id", "citrus:randomUUID()");

runner.variable("title", title);

runner.variable("options", buildOptionsAsJsonArray("yes:no"));

runner.variable("closed", false);

}



@When("^client creates the voting$")

public void createVoting() {

runner.http(action -> action.client(votingClient)

.send()

.post("/voting")

.contentType("application/json")

.payload("{ "id": "${id}", "title": "${title}", "options": ${options} }"));



runner.http(action -> action.client(votingClient)

.receive()

.response(HttpStatus.OK)

.messageType(MessageType.JSON));

}
@citrus_test@cucumberbdd
#DevoxxUS
Mail SMTP messaging
@Then("^participants should receive reporting mail$")

public void shouldReceiveReportingMail(String text) {

runner.createVariable("mailBody", text);



runner.receive(action -> action.endpoint(mailServer)

.payload(new ClassPathResource("templates/mail.xml"))

.header(CitrusMailMessageHeaders.MAIL_SUBJECT, "Voting results")

.header(CitrusMailMessageHeaders.MAIL_FROM, "voting@example.org")

.header(CitrusMailMessageHeaders.MAIL_TO, "participants@example.org"));

}
@citrus_test
<mail-message xmlns="http://www.citrusframework.org/schema/mail/message">

<from>voting@example.org</from>

<to>participants@example.org</to>

<cc></cc>

<bcc></bcc>

<subject>Voting results</subject>

<body>

<contentType>text/plain; charset=us-ascii</contentType>

<content>${mailBody}</content>

</body>

</mail-message>
@cucumberbdd
#DevoxxUS
JMS messaging
@CitrusEndpoint(name = "reportingEndpoint")

private JmsEndpoint reportingEndpoint;
@Then("^reporting should receive vote results$")

public void shouldReceiveReport(DataTable dataTable) {

runner.createVariable("results", buildOptionsAsJsonArray(dataTable));



runner.receive(action -> action.endpoint(reportingEndpoint)

.messageType(MessageType.JSON)

.payload("{ "id": "${id}", "title": "${title}", "options": ${results} }"));

}
@citrus_test
@Bean

public JmsEndpoint reportingEndpoint() {

return CitrusEndpoints.jms()

.asynchronous()

.connectionFactory(connectionFactory())

.destination("jms.voting.report")

.build();

}
@cucumberbdd
#DevoxxUS @citrus_test
Demo
@cucumberbdd
#DevoxxUS
Reading & information
https://cucumber.io
http://citrusframework.org
Demo Sources
https://github.com/christophd/citrus-demo-devoxx-us
Citrus Cucumber Extension
http://citrusframework.org/reference/html/cucumber.html
@citrus_test@cucumberbdd
#DevoxxUS @citrus_test
Thank You!
@cucumberbdd

More Related Content

Viewers also liked

The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your dataChristian Posta
 
【チュートリアル】コンピュータビジョンによる動画認識
【チュートリアル】コンピュータビジョンによる動画認識【チュートリアル】コンピュータビジョンによる動画認識
【チュートリアル】コンピュータビジョンによる動画認識Hirokatsu Kataoka
 
LBJ Lição 13 - O que posso fazer por minha igreja
LBJ Lição 13 - O que posso fazer por minha igrejaLBJ Lição 13 - O que posso fazer por minha igreja
LBJ Lição 13 - O que posso fazer por minha igrejaNatalino das Neves Neves
 
NSF Smart and Connected Health Visioning Meeting
NSF Smart and Connected Health Visioning MeetingNSF Smart and Connected Health Visioning Meeting
NSF Smart and Connected Health Visioning MeetingSherry Pagoto
 
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care	White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care Swords to Plowshares
 
LBA Lição 13 - Uma vida de frutificação
LBA Lição 13 - Uma vida de frutificaçãoLBA Lição 13 - Uma vida de frutificação
LBA Lição 13 - Uma vida de frutificaçãoNatalino das Neves Neves
 
じょいとも広告人講座17:天野祐吉
じょいとも広告人講座17:天野祐吉じょいとも広告人講座17:天野祐吉
じょいとも広告人講座17:天野祐吉じょいとも
 
UIも大事だよ。という話。@Opt Group Tech Day
UIも大事だよ。という話。@Opt Group Tech DayUIも大事だよ。という話。@Opt Group Tech Day
UIも大事だよ。という話。@Opt Group Tech DayTetsuya Takeda
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialChristos Zigkolis
 

Viewers also liked (11)

The hardest part of microservices: your data
The hardest part of microservices: your dataThe hardest part of microservices: your data
The hardest part of microservices: your data
 
Фишки из патентов Google
Фишки из патентов GoogleФишки из патентов Google
Фишки из патентов Google
 
【チュートリアル】コンピュータビジョンによる動画認識
【チュートリアル】コンピュータビジョンによる動画認識【チュートリアル】コンピュータビジョンによる動画認識
【チュートリアル】コンピュータビジョンによる動画認識
 
Tbi challenge2013
Tbi challenge2013Tbi challenge2013
Tbi challenge2013
 
LBJ Lição 13 - O que posso fazer por minha igreja
LBJ Lição 13 - O que posso fazer por minha igrejaLBJ Lição 13 - O que posso fazer por minha igreja
LBJ Lição 13 - O que posso fazer por minha igreja
 
NSF Smart and Connected Health Visioning Meeting
NSF Smart and Connected Health Visioning MeetingNSF Smart and Connected Health Visioning Meeting
NSF Smart and Connected Health Visioning Meeting
 
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care	White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
White Paper: Legislation to Ensure Veterans’ Access to Mental Health Care
 
LBA Lição 13 - Uma vida de frutificação
LBA Lição 13 - Uma vida de frutificaçãoLBA Lição 13 - Uma vida de frutificação
LBA Lição 13 - Uma vida de frutificação
 
じょいとも広告人講座17:天野祐吉
じょいとも広告人講座17:天野祐吉じょいとも広告人講座17:天野祐吉
じょいとも広告人講座17:天野祐吉
 
UIも大事だよ。という話。@Opt Group Tech Day
UIも大事だよ。という話。@Opt Group Tech DayUIも大事だよ。という話。@Opt Group Tech Day
UIも大事だよ。という話。@Opt Group Tech Day
 
Wordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short TutorialWordpress Plugin Development Short Tutorial
Wordpress Plugin Development Short Tutorial
 

Similar to Behavior driven integration with Cucumber & Citrus

Remaining Agile with Billions of Documents: Appboy and Creative MongoDB Schemas
Remaining Agile with Billions of Documents: Appboy and Creative MongoDB SchemasRemaining Agile with Billions of Documents: Appboy and Creative MongoDB Schemas
Remaining Agile with Billions of Documents: Appboy and Creative MongoDB SchemasMongoDB
 
Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twistchristophd
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptHendrik Ebbers
 
Devoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingDevoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingPierre Laporte
 
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016Phil Leggetter
 
User Expectations in Mobile App Security
User Expectations in Mobile App SecurityUser Expectations in Mobile App Security
User Expectations in Mobile App SecurityTao Xie
 
Identifying Users Across Platforms with a Universal ID Webinar Slides
Identifying Users Across Platforms with a Universal ID Webinar SlidesIdentifying Users Across Platforms with a Universal ID Webinar Slides
Identifying Users Across Platforms with a Universal ID Webinar SlidesLooker
 
Goodle Developer Days Munich 2008 - Open Social Update
Goodle Developer Days Munich 2008 - Open Social UpdateGoodle Developer Days Munich 2008 - Open Social Update
Goodle Developer Days Munich 2008 - Open Social UpdatePatrick Chanezon
 
Java 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJava 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJosé Paumard
 
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...Catalyst
 
Technovation challenge workplan for week 4
Technovation challenge workplan for week 4Technovation challenge workplan for week 4
Technovation challenge workplan for week 4wetech_global
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introductionsaivvit
 
Bootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4jBootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4jMax De Marzi
 
Deduplication Using Solr: Presented by Neeraj Jain, Stubhub
Deduplication Using Solr: Presented by Neeraj Jain, StubhubDeduplication Using Solr: Presented by Neeraj Jain, Stubhub
Deduplication Using Solr: Presented by Neeraj Jain, StubhubLucidworks
 

Similar to Behavior driven integration with Cucumber & Citrus (20)

Remaining Agile with Billions of Documents: Appboy and Creative MongoDB Schemas
Remaining Agile with Billions of Documents: Appboy and Creative MongoDB SchemasRemaining Agile with Billions of Documents: Appboy and Creative MongoDB Schemas
Remaining Agile with Billions of Documents: Appboy and Creative MongoDB Schemas
 
Testing Microservices with a Citrus twist
Testing Microservices with a Citrus twistTesting Microservices with a Citrus twist
Testing Microservices with a Citrus twist
 
Beauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScriptBeauty & the Beast - Java VS TypeScript
Beauty & the Beast - Java VS TypeScript
 
Devoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarkingDevoxx BE - How to fail at benchmarking
Devoxx BE - How to fail at benchmarking
 
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
Real-Time Web Apps & .NET. What Are Your Options? NDC Oslo 2016
 
User Expectations in Mobile App Security
User Expectations in Mobile App SecurityUser Expectations in Mobile App Security
User Expectations in Mobile App Security
 
Identifying Users Across Platforms with a Universal ID Webinar Slides
Identifying Users Across Platforms with a Universal ID Webinar SlidesIdentifying Users Across Platforms with a Universal ID Webinar Slides
Identifying Users Across Platforms with a Universal ID Webinar Slides
 
Goodle Developer Days Munich 2008 - Open Social Update
Goodle Developer Days Munich 2008 - Open Social UpdateGoodle Developer Days Munich 2008 - Open Social Update
Goodle Developer Days Munich 2008 - Open Social Update
 
Java 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java ComparisonJava 8 Streams and Rx Java Comparison
Java 8 Streams and Rx Java Comparison
 
SOLID Ruby, SOLID Rails
SOLID Ruby, SOLID RailsSOLID Ruby, SOLID Rails
SOLID Ruby, SOLID Rails
 
AWS re:Invent Hackathon
AWS re:Invent HackathonAWS re:Invent Hackathon
AWS re:Invent Hackathon
 
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...
TechSEO Boost 2021 - Rendering Strategies: Measuring the Devil’s Details in C...
 
Legacy is Good
Legacy is GoodLegacy is Good
Legacy is Good
 
Designing Testable Software
Designing Testable SoftwareDesigning Testable Software
Designing Testable Software
 
Double Loop
Double LoopDouble Loop
Double Loop
 
Technovation challenge workplan for week 4
Technovation challenge workplan for week 4Technovation challenge workplan for week 4
Technovation challenge workplan for week 4
 
DataHub
DataHubDataHub
DataHub
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Bootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4jBootstrapping Recommendations with Neo4j
Bootstrapping Recommendations with Neo4j
 
Deduplication Using Solr: Presented by Neeraj Jain, Stubhub
Deduplication Using Solr: Presented by Neeraj Jain, StubhubDeduplication Using Solr: Presented by Neeraj Jain, Stubhub
Deduplication Using Solr: Presented by Neeraj Jain, Stubhub
 

Recently uploaded

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Shahin Sheidaei
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptxGeorgi Kodinov
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of ProgrammingMatt Welsh
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandIES VE
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfkalichargn70th171
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesKrzysztofKkol1
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Globus
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareinfo611746
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfOrtus Solutions, Corp
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisGlobus
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownloadvrstrong314
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Globus
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEJelle | Nordend
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessWSO2
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...Juraj Vysvader
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Globus
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILNatan Silnitsky
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTier1 app
 

Recently uploaded (20)

Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Designing for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web ServicesDesigning for Privacy in Amazon Web Services
Designing for Privacy in Amazon Web Services
 
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
Innovating Inference - Remote Triggering of Large Language Models on HPC Clus...
 
Studiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting softwareStudiovity film pre-production and screenwriting software
Studiovity film pre-production and screenwriting software
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data AnalysisProviding Globus Services to Users of JASMIN for Environmental Data Analysis
Providing Globus Services to Users of JASMIN for Environmental Data Analysis
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
De mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FMEDe mooiste recreatieve routes ontdekken met RouteYou en FME
De mooiste recreatieve routes ontdekken met RouteYou en FME
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
Climate Science Flows: Enabling Petabyte-Scale Climate Analysis with the Eart...
 
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.ILBeyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
Beyond Event Sourcing - Embracing CRUD for Wix Platform - Java.IL
 
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 

Behavior driven integration with Cucumber & Citrus

  • 1. #DevoxxUS Behavior driven integration with Cucumber & Citrus Christoph Deppisch ConSol Software GmbH @cucumberbdd @citrus_test
  • 8. #DevoxxUS Given a certain context When some event happens Then an outcome should occur @citrus_test Gherkin @cucumberbdd
  • 10. #DevoxxUS Feature specification 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 Mondays?"
 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 Mondays?" @citrus_test@cucumberbdd
  • 11. #DevoxxUS Feature specification continued 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 Mondays?"
 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 Mondays?"
 
 Scenario: Custom voting options
 When I create new voting "What is your favorite color?"
 And voting options are "green:red:blue"
 Then voting title should be "What is your favorite color?"
 And voting should have options
 | green |
 | red |
 | blue | @citrus_test@cucumberbdd
  • 13. #DevoxxUS JUnit Cucumber test @RunWith(Cucumber.class)
 public class VotingFeatureTest {
 } @citrus_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) { ... } 
 } @cucumberbdd
  • 14. #DevoxxUS Step definitions @When("^I create new voting "(.+)"$")
 public void createVotingWithTitle(String title) {
 votingId = UUID.randomUUID();
 Voting voting = new Voting(votingId, title);
 votingService.add(voting);
 } @citrus_test @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 is your favorite color?" Then voting should have 3 options @cucumberbdd
  • 15. #DevoxxUS Data tables @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);
 }
 } @citrus_test Then voting should have options
 | green |
 | red |
 | blue | @cucumberbdd
  • 17. #DevoxxUS Hooks @Before
 public void before(Scenario scenario) {
 // do something
 } 
 @After
 public void after(Scenario scenario) {
 // do something
 } @citrus_test@cucumberbdd
  • 18. #DevoxxUS Background 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 cucumbers?"
 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" @citrus_test@cucumberbdd
  • 19. #DevoxxUS Scenario Outline 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 |
 | Do you like hotdogs? | 12 | 5 | yes |
 | Do you like crap sandwiches? | 1 | 25 | no | @citrus_test@cucumberbdd
  • 22. #DevoxxUS @citrus_test Client VotingApp Http REST JMS Reporting MailServer JMS SMTP @cucumberbdd
  • 25. #DevoxxUS Messaging Feature Feature: Voting Http REST API
 
 Background:
 Given Voting list is empty
 And New voting "Do you like donuts?"
 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
 """ @citrus_test@cucumberbdd
  • 26. #DevoxxUS Endpoint injection 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));
 } } @citrus_test@cucumberbdd
  • 27. #DevoxxUS Endpoint configuration @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();
 }
 } @citrus_test@cucumberbdd
  • 28. #DevoxxUS 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 … @cucumberbdd @citrus_test
  • 29. #DevoxxUS Http REST messaging @Given("^New voting "([^"]+)"$")
 public void newVoting(String title) {
 runner.variable("id", "citrus:randomUUID()");
 runner.variable("title", title);
 runner.variable("options", buildOptionsAsJsonArray("yes:no"));
 runner.variable("closed", false);
 }
 
 @When("^client creates the voting$")
 public void createVoting() {
 runner.http(action -> action.client(votingClient)
 .send()
 .post("/voting")
 .contentType("application/json")
 .payload("{ "id": "${id}", "title": "${title}", "options": ${options} }"));
 
 runner.http(action -> action.client(votingClient)
 .receive()
 .response(HttpStatus.OK)
 .messageType(MessageType.JSON));
 } @citrus_test@cucumberbdd
  • 30. #DevoxxUS Mail SMTP messaging @Then("^participants should receive reporting mail$")
 public void shouldReceiveReportingMail(String text) {
 runner.createVariable("mailBody", text);
 
 runner.receive(action -> action.endpoint(mailServer)
 .payload(new ClassPathResource("templates/mail.xml"))
 .header(CitrusMailMessageHeaders.MAIL_SUBJECT, "Voting results")
 .header(CitrusMailMessageHeaders.MAIL_FROM, "voting@example.org")
 .header(CitrusMailMessageHeaders.MAIL_TO, "participants@example.org"));
 } @citrus_test <mail-message xmlns="http://www.citrusframework.org/schema/mail/message">
 <from>voting@example.org</from>
 <to>participants@example.org</to>
 <cc></cc>
 <bcc></bcc>
 <subject>Voting results</subject>
 <body>
 <contentType>text/plain; charset=us-ascii</contentType>
 <content>${mailBody}</content>
 </body>
 </mail-message> @cucumberbdd
  • 31. #DevoxxUS JMS messaging @CitrusEndpoint(name = "reportingEndpoint")
 private JmsEndpoint reportingEndpoint; @Then("^reporting should receive vote results$")
 public void shouldReceiveReport(DataTable dataTable) {
 runner.createVariable("results", buildOptionsAsJsonArray(dataTable));
 
 runner.receive(action -> action.endpoint(reportingEndpoint)
 .messageType(MessageType.JSON)
 .payload("{ "id": "${id}", "title": "${title}", "options": ${results} }"));
 } @citrus_test @Bean
 public JmsEndpoint reportingEndpoint() {
 return CitrusEndpoints.jms()
 .asynchronous()
 .connectionFactory(connectionFactory())
 .destination("jms.voting.report")
 .build();
 } @cucumberbdd
  • 33. #DevoxxUS Reading & information https://cucumber.io http://citrusframework.org Demo Sources https://github.com/christophd/citrus-demo-devoxx-us Citrus Cucumber Extension http://citrusframework.org/reference/html/cucumber.html @citrus_test@cucumberbdd