34
ChoreUnit: Testing framework for Web Services Felipe Besson, Guilherme Nogueira, Leonardo Leite {besson, gmaio, leofl}@ime.usp.br Porto Alegre, July 2nd, 2011

CHOReOS Web Services FISL Conference Brazil 2012

  • Upload
    choreos

  • View
    1.123

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: CHOReOS Web Services FISL Conference Brazil 2012

ChoreUnit: Testing framework for Web Services

Felipe Besson, Guilherme Nogueira, Leonardo Leite{besson, gmaio, leofl}@ime.usp.br

Porto Alegre, July 2nd, 2011

Page 2: CHOReOS Web Services FISL Conference Brazil 2012

Services

?

Page 3: CHOReOS Web Services FISL Conference Brazil 2012

Product Vs Service

Page 4: CHOReOS Web Services FISL Conference Brazil 2012

Product Vs Service

Page 5: CHOReOS Web Services FISL Conference Brazil 2012

Web Services

Message exchange standards (xml) among systems through Internet (http)

Page 6: CHOReOS Web Services FISL Conference Brazil 2012

Web Services - Applications● Machine-machine communication

0011110010111010

1011110111110000

Page 7: CHOReOS Web Services FISL Conference Brazil 2012

Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems

Page 8: CHOReOS Web Services FISL Conference Brazil 2012

Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation

Comprar

Zz

z

zz

zz

Z

Z

Page 9: CHOReOS Web Services FISL Conference Brazil 2012

Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation

Buy

Zz

z

zz

zz

Z

Z

Service provider

Client

Page 10: CHOReOS Web Services FISL Conference Brazil 2012

Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation● Data access

WS

Page 11: CHOReOS Web Services FISL Conference Brazil 2012

Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation● Data access and creation (colaborative)

WS

Page 12: CHOReOS Web Services FISL Conference Brazil 2012

Now: billions of web pages

Future: billions of web services

Page 13: CHOReOS Web Services FISL Conference Brazil 2012

SOAP

Page 14: CHOReOS Web Services FISL Conference Brazil 2012

WSDL<?xml version="1.0" encoding="UTF-8"?><definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"xmlns:tns="http://hello/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://hello/"name="HelloWorldService"><types> <xsd:schema> <xsd:import namespace="http://hello/" schemaLocation="http://localhost:8080/hello?xsd=1"></xsd:import> </xsd:schema></types><message name="sayHelloTo"> <part name="parameter" element="tns:sayHelloTo"></part></message><message name="sayHelloToResponse"> <part name="parameter" element="tns:sayHelloToResponse"></part></message><portType name="HelloWorld"> <operation name="sayHelloTo"> <input message="tns:sayHelloTo"></input> <output message="tns:sayHelloToResponse"></output> </operation></portType>

Page 15: CHOReOS Web Services FISL Conference Brazil 2012

Web Services Clients in Java

● Apache Axis2● Jax-WS (Java EE API)

Page 16: CHOReOS Web Services FISL Conference Brazil 2012

WS Client with Jax-WS...<portType name="StoreWS">

<operation name="searchByArtist"><input message="tns:searchByArtist"/><output message="tns:searchByArtistResponse"/>

</operation><operation name="searchByGenre"><input message="tns:searchByGenre"/>

<output message="tns:searchByGenreResponse"/></operation>

<operation name="searchByTitle"><input message="tns:searchByTitle"/><output message="tns:searchByTitleResponse"/>

</operation><operation name="purchase">

<input message="tns:purchase"/><output message="tns:purchaseResponse"/>

</operation></portType>...

Page 17: CHOReOS Web Services FISL Conference Brazil 2012

WS Client with Jax-WS

public interface Store {

List<CD> searchByArtist(String artist);

List<CD> searchByGenre(String genre);

List<CD> searchByTitle(String title);

Boolean purchase(CD cd, Customer customer);

}

Page 18: CHOReOS Web Services FISL Conference Brazil 2012

WS Client with Jax-WS

$wsimport -s src http://choreos.ime.usp.br/store?wsdl

Page 19: CHOReOS Web Services FISL Conference Brazil 2012

WS Client with Jax-WS

$wsimport -s src http://choreos.ime.usp.br/store?wsdl

ObjectFactory package-info StoreWSStoreWSServiceCDCustomerSearchByGenre SearchByGenreResponse SearchByTitle SearchByTitleResponseSearchByArtist SearchByArtistResponse Purchase PurchaseResponse

Page 20: CHOReOS Web Services FISL Conference Brazil 2012

WS Client with Jax-WS

StoreWSService service = new StoreWSService();StoreWS store = service.getStoreWSPort();

List<CD> cds = store.searchByGenre("Rock");

Page 21: CHOReOS Web Services FISL Conference Brazil 2012

TDD

Test-driven development

Page 22: CHOReOS Web Services FISL Conference Brazil 2012

TDD

Write test

Make test pass

Refactoring

Page 23: CHOReOS Web Services FISL Conference Brazil 2012

Our Framework

Page 24: CHOReOS Web Services FISL Conference Brazil 2012

Stub creation can be a problem

Process:

1. create stubs

2. add classes to project

3. understand classes

Service interfacechanged!

%$#@

Developer

Page 25: CHOReOS Web Services FISL Conference Brazil 2012

Problems when testing

● Tests must be almost completely rewritten

● Problem to integrate different services● How to do TDD without stubs?

%$#@

Page 26: CHOReOS Web Services FISL Conference Brazil 2012

Our GoalsMake testing web services easy

● Interact with web services without stubs● Easily validate the operation's responses● Writing tests before the actual implementation● Integrate tests and framework to the development

environment

Page 27: CHOReOS Web Services FISL Conference Brazil 2012

Overview

Page 28: CHOReOS Web Services FISL Conference Brazil 2012

Usage (1)

WSClient – dinamic client

// criationWSClient service = new WSClient (String wsdl);

// Invoking an operationItem resposta = service.request (String operation,

Item parameters);

Page 29: CHOReOS Web Services FISL Conference Brazil 2012

Usage (2)

Item – recursive structure representing complex types

<ns: getProductB yN am eR esponse> <ns:return xsi:type=”ax26:I tem ”> <barcode>153</barcode> <brand>adidas</brand> <descr iption>A cleat</descr iption> <nam e>S occer cleat</nam e> <pr ice>90.0</pr ice> <spor t>soccer</spor t> </ns:return></ns:getProductB yN am eR esponse>

I tem response = w s.request( “getProductB yN am e”, “S occer cleat”);I tem response = w s.request( “getProductB yN am e”, “S occer cleat”);

I tem item = response.getChild( “return”) ;I tem .getN am e( ) ; => “return”I tem .gettagA ttr ibute( “xsi:type”) ; => “ax26:I tem ”

I tem response = w s.request( “getProductB yN am e”, “S occer cleat”);

I tem item = response.getChild( “return”) ;I tem .getN am e( ) ; => “return”I tem .gettagA ttr ibute( “xsi:type”) ; => “ax26:I tem ”

item .getChild( “barcode”) .getContent( ) ; => “153”I tem .getChild( “brand”) .getContent( ) ; => “adidas”I tem .getChild( “descr iption”) .getContent( ) ; => “A cleat”…

Page 30: CHOReOS Web Services FISL Conference Brazil 2012

Comparison

Page 31: CHOReOS Web Services FISL Conference Brazil 2012

Conclusion

WSClient code is bigger!● Is it really??● No, Jax-WS code uses stubs that were

previously generated =P

Page 32: CHOReOS Web Services FISL Conference Brazil 2012

Demo

Page 33: CHOReOS Web Services FISL Conference Brazil 2012

Next steps● Implement new features

● REST services support● Integration test

– Validate messages exchanged between services

● Experimentation

Page 34: CHOReOS Web Services FISL Conference Brazil 2012

Questions?

This research has received finding from:

More Information: http://ccsl.ime.usp.br/baile/VandVRepository: https://github.com/choreos/choreos_v-v/