Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Testing Microservices with a Citrus twist

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

Testing Microservices with a Citrus twist

Devoxx BE 2015

Avatar for Christoph Deppisch

Christoph Deppisch

November 10, 2015

More Decks by Christoph Deppisch

Other Decks in Technology

Transcript

  1. @citrus_test #Devoxx #CitrusTwist Christoph Deppisch • Senior software developer •

    @ConSol* Munich, Germany • 10 years of experience in Java • Passionate about automated software testing • Founder of the Open Source framework Citrus • Happy to be here today!
 
 
 Twitter: @freaky_styley
  2. @citrus_test #Devoxx #CitrusTwist What is Citrus? • Open Source integration

    test framework • Focus on messaging in distributed software systems • Automated interface tests • Ready-to-use endpoint components for message exchange • Works & integrates with well-known libraries • TestNG, JUnit • Apache Camel, Spring, Docker, Arquillian …
  3. @citrus_test #Devoxx #CitrusTwist import com.consol.citrus.annotations.CitrusTest; import com.consol.citrus.dsl.testng.TestNGCitrusTestDesigner; import org.testng.annotations.Test; @Test


    public class SampleCitrusIT extends TestNGCitrusTestDesigner {
 
 @CitrusTest
 public void sayHello() {
 echo("Hello, Devoxx! This is my first Citrus test!");
 }
 }
  4. @citrus_test #Devoxx #CitrusTwist • Missing something? Adding custom actions is

    possible! Test actions Test action Description echo Log message to console send Sends a message receive Receives a message sleep Wait some time sql Execute SQL statements parallel Execute actions in parallel conditional Execute actions based on condition iterate Execute actions in iteration repeat-on-error Failsafe action execution …
  5. @citrus_test #Devoxx #CitrusTwist @Test
 public class MessageExchangeIT extends TestNGCitrusTestDesigner {


    @Autowired
 private Endpoint orderEndpoint; 
 @CitrusTest
 public void sendAndReceiveMessage() { send(orderEndpoint) .payload("..."); receive(orderEndpoint) .payload("...");
 }
 }
  6. @citrus_test #Devoxx #CitrusTwist @CitrusTest
 public void sendAndReceiveMessage() { variable("orderId", Functions.randomNumber(10L));

    send(orderEndpoint) .payload("<order>" + "<id>${orderId}</id>" + "</order>") .header("operation", "placeOrder") .header("id", "${orderId}");
 receive(orderEndpoint) .payload("<orderResponse>" + "<timestamp>@ignore@</timestamp>" + "<id>${orderId}</id>" + "<success>true</success>" + "</orderResponse>") .header("id", "${orderId}");
 }
  7. @citrus_test #Devoxx #CitrusTwist • Missing something? Adding custom components is

    easy! Endpoint components 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-ftp FTP client and server citrus-vertx Vert.x endpoint citrus-ssh SSH client and server …
  8. @citrus_test #Devoxx #CitrusTwist <!-- JMS endpoints --> <citrus-jms:endpoint id="orderEndpoint"
 destination-name="factory.order.inbound"/>

    
 <citrus-jms:sync-endpoint id="errorEndpoint"
 destination-name="base.error.service"
 timeout="${global.receive.timeout}"/> <!-- JMS connection factory and message broker -->
 <bean id="connectionFactory"
 class="org.apache.activemq.ActiveMQConnectionFactory">
 <property name="brokerURL" value="tcp://localhost:61616" />
 </bean> Endpoints: citrus-jms
  9. @citrus_test #Devoxx #CitrusTwist <!-- REST Http client --> <citrus-http:client id="reportingClient"

    request-method="GET" timeout="5000"
 request-url="http://localhost:8080/services/report"/> <!-- REST Http server -->
 <citrus-http:server id="reportingServer"
 port="8080"
 auto-start="true"/> Endpoints: citrus-http
  10. @citrus_test #Devoxx #CitrusTwist Demo tools • docker-maven-plugin • docker:build, docker:start,

    docker:stop • https://github.com/rhuss/docker-maven-plugin • Apache Camel • Content-based routing, REST endpoints, standalone worker • http://camel.apache.org/ • Demo Code • https://github.com/christophd/citrus-demo-devoxx
  11. @citrus_test #Devoxx #CitrusTwist What else!? • Docker integration • build,

    start, stop, inspect, … • Manage Docker containers at test runtime • Arquillian extension • Use Citrus in Arquillian test • @CitrusFramework, @CitrusEndpoint, @CitrusResource • Apache Camel integration • Create, start, stop routes at test runtime
  12. @citrus_test #Devoxx #CitrusTwist Information • Homepage • http://citrusframework.org • Blog

    • http://labs.consol.de/tags/citrus/ • User Guide • http://citrusframework.org/reference/html/index.html • Mailing List • [email protected]