Upload
choreos
View
1.123
Download
0
Embed Size (px)
DESCRIPTION
Citation preview
ChoreUnit: Testing framework for Web Services
Felipe Besson, Guilherme Nogueira, Leonardo Leite{besson, gmaio, leofl}@ime.usp.br
Porto Alegre, July 2nd, 2011
Services
?
Product Vs Service
Product Vs Service
Web Services
Message exchange standards (xml) among systems through Internet (http)
Web Services - Applications● Machine-machine communication
0011110010111010
1011110111110000
Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems
Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation
Comprar
Zz
z
zz
zz
Z
Z
Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation
Buy
Zz
z
zz
zz
Z
Z
Service provider
Client
Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation● Data access
WS
Web Services - Applications● Machine-machine communication● Integrate heterogeneous systems● Business automation● Data access and creation (colaborative)
WS
Now: billions of web pages
Future: billions of web services
SOAP
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>
Web Services Clients in Java
● Apache Axis2● Jax-WS (Java EE API)
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>...
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);
}
WS Client with Jax-WS
$wsimport -s src http://choreos.ime.usp.br/store?wsdl
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
WS Client with Jax-WS
StoreWSService service = new StoreWSService();StoreWS store = service.getStoreWSPort();
List<CD> cds = store.searchByGenre("Rock");
TDD
Test-driven development
TDD
Write test
Make test pass
Refactoring
Our Framework
Stub creation can be a problem
Process:
1. create stubs
2. add classes to project
3. understand classes
Service interfacechanged!
%$#@
Developer
Problems when testing
● Tests must be almost completely rewritten
● Problem to integrate different services● How to do TDD without stubs?
%$#@
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
Overview
Usage (1)
WSClient – dinamic client
// criationWSClient service = new WSClient (String wsdl);
// Invoking an operationItem resposta = service.request (String operation,
Item parameters);
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”…
Comparison
Conclusion
WSClient code is bigger!● Is it really??● No, Jax-WS code uses stubs that were
previously generated =P
Demo
Next steps● Implement new features
● REST services support● Integration test
– Validate messages exchanged between services
● Experimentation
Questions?
This research has received finding from:
More Information: http://ccsl.ime.usp.br/baile/VandVRepository: https://github.com/choreos/choreos_v-v/